Skip to content

Commit

Permalink
Refactor codebase, reorganize scripts and optimise config handling
Browse files Browse the repository at this point in the history
The diff represents several updates across the codebase. Reorganized 'scripts' in 'package.json' for better readability and further separation of concerns by adding the 'docs' command. Introduced a 'postInstall' property in 'wp-package.json'.

Refactored 'lib/index.js' by wrapping actions within an object, which allows selection of the appropriate action based on the provided argv key. It improves code readability and maintainability whilst keeping the intent of the original code.

In 'lib/package.js', reorganization of the 'require' statements was made. Reordered them to better reflect their execution sequence.

'Rename' command used to better align with the language used in rest of the code. The renaming of 'lib/init.js' to 'lib/initialize.js' helps in achieving consistency across the codebase.
  • Loading branch information
erikyo committed Dec 2, 2023
1 parent 1e15f2a commit c6f33b8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
42 changes: 25 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@ const config = getConfig(argv);
// Start the timer
const startTime = Date.now();

if (argv.dump === true) {
const dump = new WordPressConfigDump(this);
dump.init();
printTimePassed(startTime);
} else if (argv.initialize === true) {
const initializer = new Initialize(config);
initializer.generateConfig();
printTimePassed(startTime);
} else {
// Install WordPress
const installer = new WordPressInstaller(config);

installer.run().then(() => {
console.log('🚀 WordPress installed successfully.');
const actions = {
dump: () => {
const dump = new WordPressConfigDump(this);
dump.init();
printTimePassed(startTime);
process.exit(0);
},
init: () => {
const initializer = new Initialize(config);
initializer.generateConfig();
printTimePassed(startTime);
});
}
process.exit(0);
},
default: () => {
// Install WordPress
const installer = new WordPressInstaller(config);

installer.run().then(() => {
console.log('🚀 WordPress installed successfully.');
printTimePassed(startTime);
process.exit(0);
});
}
};

process.exit(0);
const action = Object.keys(argv).find(key => argv[key] === true);
(actions[action] || actions.default)();
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const {
downloadFile,
extractZip,
getDownloadUrl,
getWordPressDownloadUrl,
installNpmPackages,
Expand All @@ -12,6 +10,8 @@ const {
} = require('./utils');

const {
downloadFile,
extractZip,
renameFolder
} = require('./fs');

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"type": "git",
"url": "https://github.com/erikyo/wpmm.git"
},
"scripts": {
"test": "jest",
"docs": "npx jsdoc lib/index.js -d docs -c jsdoc.json"
},
"bin": {
"wpmm": "lib/index.js"
},
"scripts": {
"test": "jest"
},
"main": "lib/index.js",
"keywords": [
"wordpress",
Expand Down
3 changes: 2 additions & 1 deletion wp-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
}
},
"themes": [],
"plugins": []
"plugins": [],
"postInstall": []
}

0 comments on commit c6f33b8

Please sign in to comment.