Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code for init, pkgFile, functions, and npm modules #240

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RoachxD
Copy link

@RoachxD RoachxD commented Jul 20, 2023

This pull request contains several refactoring changes to improve the code quality and readability of the init, pkgFile, functions, and npm modules. The main changes are:

  • Simplify the code by using absolute paths, optional chaining, destructuring assignment, and inquirer.prompt with an array of questions, in the init module.
  • Optimize the package file generation code by using default values, map calls, and nullish coalescing operator in the pkgFile module.
  • Optimize the isEmptyDir and createFiles functions by using every, Promise.all, and pathJoin in the functions module.
  • Use get method from https module instead of request to simplify the code in the npm module.

Please review the changes and let me know if you have any feedback or suggestions.

RoachxD added 4 commits July 19, 2023 15:34
- Refactor imports to use absolute paths.
- Use `join` as `pathJoin` for increased clarity.
- Simplify the code by using optional chaining and destructuring assignment.
- Update the list of `randomArrayValue` options.
- Use `inquirer.prompt` with an array of questions to simplify the code.
- `dependencies` and `devDependencies` objects are extracted from `siteManifest` and assigned default values of `{}` to avoid repeatedly accessing the same properties.
- `reduce` calls in the `dependencies` and `devDependencies` properties have been replaced with `map` calls and the spread operator has been replaced with `Object.assign`. This avoids creating new objects on each iteration of the `reduce` function.
- The optional chaining operator (`?.`) has been removed from the `options.deps` and `options.devDeps` properties and replaced with nullish coalescing operator (`??`) and an empty array. This ensures that the `map` function is always called on an array, even if the property is `undefined`.
- Replace `for` loop with `every` method in `isEmptyDir`.
- Replace `for` loop with `Promise.all` and `map` in `createFiles`.
- Rename `join` import from `path` to `pathJoin` for increased clarity.
- Add comment to `catch` block in `safeStat`.
- Improve readability with line breaks and optional chaining.
- Use `get` method from `https` module instead of `request` to simplify the code.
- Remove unnecessary `req.end()` call.
- Change `close` event to `end` event for resolving the promise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant