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

Reshape the script using OOP #4

Merged
merged 9 commits into from
Dec 1, 2023
Merged

Reshape the script using OOP #4

merged 9 commits into from
Dec 1, 2023

Conversation

erikyo
Copy link
Collaborator

@erikyo erikyo commented Nov 30, 2023

not a great fan of OOP, but I must admit that in this case it suits very well.

close #1, close #3

erikyo and others added 7 commits November 30, 2023 18:08
The commit includes the change of the earlier function-based approach to an Object-Oriented way for handling WordPress package in the index. This refactor was made to increase readability and modularity of the code.

The utility functions have been merged into a single `utils.js` file, which was moved to 'lib' directory and reexported as an object for simpler imports. Also, to increase readability, 'getOptionValue' was replaced with 'yargs' and 'hideBin' for more efficient and streamlined command-line parameters parsing.

The revision also includes addition of 'getConfig' function to handle reading and parsing of configuration file (wp-package.json).

index.js was also renamed and relocated to 'lib' folder for better project structure and increased code maintainability.

A new dependency to yargs library was added to parse command line parameters.

The handcrafted function to parse command line arguments was dropped in favour of popular 'yargs' library for increased reliability and easier maintenance.

The binary and main entry point in the package.json was updated to reflect the new file location. The version was also bumped.

The package-lock.json was automatically updated to adjust the new 'yargs' dependency and version bump.
Three utility functions are introduced in utils.js to enhance security and ease of use for WordPress installations. replaceDbConstant(configContent, constantName, userDefinedValue) replaces a constant in wp-config.php with a user-defined value. generateSalt() creates a random salt code, and replaceEmptySalts(configContent) replaces empty salt place holders in the wp-config.php with generated salt codes. These functions allow users to easily replace database constants and salts in WordPress configurations without having to manually edit wp-config.php.

The exported functions of utils.js were also updated to incorporate these new methods.

In the Package class, the way of updating WordPress configurations was changed to use these new utility functions, making the code cleaner and more readable.

wp-package.json was modified to change the name, DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST to more meaningful, user-defined values.

New scripts field was also added to package.json to standardize the entry point for the application.

The readme.md file has been updated to reflect these changes, with the version number incremented accordingly.

Overall, this commit improves the security and usability of the tool, by allowing automatic generation and configuration of constants and salts in the wp-config.php file.
…tyles for various editors and IDEs, following WordPress coding standards. And, the '.gitignore' file was updated to remove a now redundant 'wp-folder'.
@gardenboi gardenboi merged commit dd53951 into master Dec 1, 2023
@erikyo erikyo deleted the OOP branch December 1, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants