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

V0.0.4 #25

Merged
merged 70 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3791575
Rename class and file 'install' to 'Installer'
erikyo Dec 8, 2023
45ec2e0
Add Database.js file with upload and dump methods
erikyo Dec 8, 2023
daa727a
Refactor package installation classes into separate files
erikyo Dec 8, 2023
ac8af1d
Add Updater.js with update methods for plugins, themes and WordPress
erikyo Dec 8, 2023
ec94d27
Refactor utils.js, moving functions into newly created utils/index.js
erikyo Dec 8, 2023
0aeb047
Refactor code and enhance database functionality
erikyo Dec 8, 2023
41fd51d
Update package version and add new dependencies
erikyo Dec 8, 2023
0426834
Add typings for WPMMconfig object properties
erikyo Dec 8, 2023
9b2d987
Refactor getConfig function for better typing
erikyo Dec 8, 2023
29655bf
Improve code documentation and implement proper naming
erikyo Dec 8, 2023
ccca816
Add comprehensive JSDoc comments and refactor variable names
erikyo Dec 8, 2023
33fba9c
Refactor codebase for clarity and add JSDoc comments
erikyo Dec 8, 2023
e68283e
Add user locale function and improve code readability
erikyo Dec 9, 2023
fa8c1ec
Create WordPress configuration utility functions
erikyo Dec 9, 2023
d3b28f6
Refactor Dump class for WordPress configuration
erikyo Dec 9, 2023
d75d1e9
Correct typo in Initialize.js comments
erikyo Dec 9, 2023
96386a7
Refactor WordPress installer in Installer.js
erikyo Dec 9, 2023
c34e7e2
Refactor Package class and remove Plugin/Theme specific classes
erikyo Dec 9, 2023
15e6a95
Refactor WpPackage setup and configuration
erikyo Dec 9, 2023
bc80770
Refactor WordPress paths utility and action functions
erikyo Dec 9, 2023
0282cdc
Update package version and dependencies in package-lock.json
erikyo Dec 9, 2023
25421ce
: Simplify wp-package.json and reorganize tests
erikyo Dec 9, 2023
ebfb655
Refactor and simplify utility test file imports
erikyo Dec 9, 2023
6e54259
Provides an example for the new database related functions
erikyo Dec 9, 2023
b19665a
Add post-install command runner function
erikyo Dec 9, 2023
263a661
chore
erikyo Dec 9, 2023
6ee55c1
: Implement remote config loading
erikyo Dec 9, 2023
d1484b4
Update baseFolder for WordPress installation
erikyo Dec 9, 2023
86c4c55
Add lib/constants.js file for WordPress install
erikyo Dec 9, 2023
1036322
Refactor WordPress config generation in Initialize.js
erikyo Dec 9, 2023
99afe09
Implement WordPress package update functionality
erikyo Dec 9, 2023
9b2bf81
Refactor Dump.js and improve WordPress version handling
erikyo Dec 9, 2023
44cd7f6
Add husky for git hooks and update scripts
erikyo Dec 9, 2023
b08953c
Implement Updater class and adjust update functionality
erikyo Dec 9, 2023
b854a04
Refactor update method with Updater class and 'updateObject'
erikyo Dec 9, 2023
7b46e00
Refactor updater logic by moving it to Updater class
erikyo Dec 9, 2023
adee258
Update and organize Initialize class methods
erikyo Dec 9, 2023
b02291d
Refactor dependency paths and constructor in Installer class
erikyo Dec 9, 2023
3d64e4e
Refactor lib/utils module and update Installer class
erikyo Dec 9, 2023
255e610
Refactor utility functions and update Installer constructor
erikyo Dec 9, 2023
caa1dee
Remove `wp-package.json` and refactor utility imports
erikyo Dec 9, 2023
f82e789
Refactor code to consolidate utility imports
erikyo Dec 9, 2023
a6ae21a
Update base folder definition and refactor file imports
erikyo Dec 9, 2023
2a795b4
Refactor function name and add new tests to utils.test.js
erikyo Dec 9, 2023
c78c061
Add WordPress configuration parsing functionality and related tests
erikyo Dec 9, 2023
33fa39f
Add initConfig function to data.js
erikyo Dec 10, 2023
06758fe
Refactor getConfig function and connection settings in data.js
erikyo Dec 10, 2023
f71f110
Add axiosFetch function to wordpress.js
erikyo Dec 10, 2023
0841b18
Replace axios.get with axiosFetch in getLastWp function
erikyo Dec 10, 2023
5af2e3c
Add getWpConfigContent function in wordpress.js
erikyo Dec 10, 2023
575bc94
Fix constant names and improve function parsers in wordpress.js
erikyo Dec 10, 2023
9d79a14
Refactor database dump method and improve error handling
erikyo Dec 10, 2023
1b4993f
Update Dump class in lib/Dump.js
erikyo Dec 10, 2023
130c25c
Update casing of constant declarations in lib/constants.js
erikyo Dec 10, 2023
120d1ad
Adapt lib/index.js to handle asynchronous configuration loading
erikyo Dec 10, 2023
c3bfc09
Refactor code to use async functions and rename constants
erikyo Dec 10, 2023
719d2c0
Update parseWpConfig tests and move test assets to fixtures
erikyo Dec 10, 2023
c63a8d1
Add directory existence validation to scanDirectory method
erikyo Dec 10, 2023
3b633b7
Refactor WordPress configuration definitions and simplify action invo…
erikyo Dec 10, 2023
57cbbb7
Add actions.js file with WordPress management functionalities
erikyo Dec 10, 2023
98f741d
Refactor actions in actions.js and index.js
erikyo Dec 10, 2023
c982e82
Refactor code for clarity and error handling in data.js
erikyo Dec 10, 2023
aabc72d
Refactor code and update documentation
erikyo Dec 10, 2023
6a29c76
Update project dependencies and introduce TypeScript
erikyo Dec 10, 2023
9973f23
Refactor and optimize WordPress installation configuration
erikyo Dec 11, 2023
bb8be61
Add utility functions for WordPress configuration parsing and modific…
erikyo Dec 11, 2023
3f8eb28
Add utility prompts for WordPress configuration and dump options
erikyo Dec 11, 2023
c635334
Refactor utility imports and update test configurations
erikyo Dec 11, 2023
da2a62d
Modify typescript target, update eslint script and add dependencies
erikyo Dec 11, 2023
0999c8a
Update configuration handling and refactor prompts
erikyo Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add comprehensive JSDoc comments and refactor variable names
The update significantly improves code clarity and readability by adding comprehensive JSDoc comments to classes, functions, and variables across multiple files. In addition, it includes refactoring of parameters and variables for consistent naming conventions and precise type clarity with the introduction of explicit typing. The file initialize.js was also renamed to Initialize.js to maintain codebase consistency and adhere to naming standards.
  • Loading branch information
erikyo committed Dec 8, 2023
commit ccca81669f82cd69e5e85d47c7e259329ab64201
6 changes: 6 additions & 0 deletions lib/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const { getConnectionSettings } = require('./utils');
const mysqldump = require('mysqldump');
const fs = require('fs').promises;

/**
* Constructor for the Database class.
*
* @class Database
* @param {WPMMconfig} config - The configuration object.
*/
class Database {
/**
* A description of the entire function.
Expand Down
39 changes: 38 additions & 1 deletion lib/Dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@ const fs = require('fs');
const path = require('path');
const { geVarFromPHPFile } = require('./utils');

/**
* Represents a Dump class for WordPress configuration.
*
* @class Dump
*/
class Dump {
constructor () {W
/**
* Constructor for the class.
*
* Initializes the class with the necessary folders for WordPress.
*/
constructor () {
this.wpFolder = process.cwd();
this.themeFolder = path.join(this.wpFolder, 'wp-content', 'themes');
this.pluginsFolder = path.join(this.wpFolder, 'wp-content', 'plugins');
}

/**
* Initializes the function by logging the `wpFolder` and `themeFolder` properties,
* scanning the theme and plugins directories, retrieving the website name from the
* `wpFolder` path, getting the WordPress version from `wp-includes/version.php`,
* determining the language using `Intl.DateTimeFormat().resolvedOptions().locale`,
* and saving the result to a JSON file.
*
* @return {void}
*/
init () {
console.log(this.wpFolder);
console.log(this.themeFolder);
Expand Down Expand Up @@ -41,6 +60,12 @@ class Dump {
console.log(`🆗 Wordpress configuration Dump completed. Configuration saved to ${outputPath}`);
}

/**
* Scans a directory and returns an array of objects containing the name and version of each item found.
*
* @param {string} directory - The path of the directory to scan.
* @return {Array} - An array of objects with the name and version of each item found.
*/
scanDirectory (directory) {
const items = fs.readdirSync(directory);
const result = [];
Expand Down Expand Up @@ -76,12 +101,24 @@ class Dump {
return result;
}

/**
* Extracts the version number from a style file.
*
* @param {string} filePath - The path to the style file.
* @return {string|null} The version number extracted from the style file, or null if no match was found.
*/
extractVersionFromStyleFile (filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const match = /Version:\s*([\d.]+)/i.exec(content);
return match ? match[1] : null;
}

/**
* Extracts the version number from a PHP file.
*
* @param {string} filePath - The path to the PHP file.
* @return {string|null} The version number extracted from the file, or null if no version is found.
*/
extractVersionFromPHPFile (filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const match = /Version:\s*([\d.]+)/i.exec(content);
Expand Down
14 changes: 12 additions & 2 deletions lib/Initialize.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
const fs = require('fs');
const path = require('path');

/**
* Initialize class for generating WordPress configuration file.
*
* @class Initialize
*/
class Initialize {
constructor (options) {
this.options = options || {};
/**
* Constructor for a new instance of the class.
*
* @param {WPMMconfig} config - Optional configuration options.
*/
constructor (config) {
this.options = config || {};
this.wpFolder = process.cwd();
this.outputPath = path.join(this.wpFolder, 'wp-package.json');
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const { cleanup, makeDir } = require('./utils/fs.js');
const { WordPressPackage, PluginPackage, ThemePackage } = require('./package');

/**
* The wpmm class represents the WordPress installer and provides methods for installing WordPress and its dependencies.
* The Installer class represents the WordPress installer and provides methods for installing WordPress and its dependencies.
*
* @class Installer
*/
class Installer {
/**
Expand Down
15 changes: 10 additions & 5 deletions lib/Package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ const {
} = require('./utils/fs');

/**
* @typedef {Object} WPMMpaths - the object containing the paths
* @property {string} rootFolder - the root folder of the application
* @property {string} tempDir - the temporary directory
* @property {string} baseFolder - the script base directory
* @typedef {Object} WPMMpaths - The object containing the paths
* @property {string} rootFolder - The root folder of the application
* @property {string} tempDir - The temporary directory
* @property {string} baseFolder - The path to the WordPress folder. Defaults to the current working directory.
* @property {string} destFolder - The destination folder for package installation.
*/

/**
* Represents a package and provides methods to download and install it.
*
* @class Package
*/
class Package {
/**
* Constructs a new instance of the class.
Expand Down Expand Up @@ -121,7 +126,7 @@ class Package {
/**
* Installs a package with the given name, version, and type.
*
* @param config - The configuration object.
* @param {WPMMconfig} config - The configuration object.
* @param {string} packageType - The type of the package ('theme' or 'plugin').
* @return {Promise<void>} - A promise that resolves once the package is downloaded and installed.
*/
Expand Down
6 changes: 6 additions & 0 deletions lib/PluginPackage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const Package = require('./package');

/**
* Represents a theme package.
*
* @class PluginPackage
* @extends Package
*/
export class PluginPackage extends Package {
/**
* Asynchronously installs a plugin.
Expand Down
6 changes: 6 additions & 0 deletions lib/ThemePackage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const Package = require('./package');

/**
* Represents a theme package.
*
* @class ThemePackage
* @extends Package
*/
export class ThemePackage extends Package {
/**
* Installs a package with the specified name and version as a theme.
Expand Down
27 changes: 27 additions & 0 deletions lib/Updater.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
const { exec } = require('child_process');

/**
* Represents the Updater class.
*
* @class Updater
*/
class Updater {
/**
* Constructs a new instance of the class.
*
* @param {WPMMconfig} config - the configuration object
*/
constructor (config) {
// Load configuration from wp-package.json
this.config = config;
}

/**
* Update plugins.
*
* @async
* @function updatePlugins - Updates plugins using the `wp plugin install` command.
* @throws {Error} If there is an error updating the plugins.
*/
async updatePlugins () {
try {
const plugins = this.config.plugins;
Expand All @@ -31,6 +48,11 @@ class Updater {
}
}

/**
* Updates the themes in the configuration by installing and activating them.
*
* @return {void}
*/
async updateThemes () {
try {
const themes = this.config.themes;
Expand All @@ -56,6 +78,11 @@ class Updater {
}
}

/**
* Updates the WordPress installation.
*
* @return {Promise} A promise that resolves when the update is complete.
*/
async updateWordPress () {
try {
const command = 'wp core update';
Expand Down
8 changes: 7 additions & 1 deletion lib/WpPackage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const { getWordPressDownloadUrl, replaceDbConstant, replaceDbConstantBool, replaceEmptySalts } = require('./utils/index.js');
const path = require('path');
const fs = require('lib/utils/fs');
const fs = require('fs');
const { renameFolder } = require('./utils/fs');
const Package = require('./package');

/**
* Represents a WordPress package that can be installed and configured.
*
* @class WpPackage
* @extends Package
*/
export class WpPackage extends Package {
/**
* Installs WordPress with the specified version and language.
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const Initialize = require('./initialize.js');
const yargs = require('yargs');
const { hideBin } = require('yargs/helpers');

// Get the arguments from the command line
/** @var {yargs} argv - The command line arguments. */
const argv = yargs(hideBin(process.argv)).argv;

// Get the config
/** @var {WPMMconfig} config - The configuration object for the script. */
const config = getConfig(argv);

// Start the timer
/** @var {number} startTime - the time at which the script started. */
const startTime = Date.now();

const actions = {
Expand Down
13 changes: 13 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ async function installNpmPackages (packageDirectory) {
});
}

/**
* Installs composer dependencies and generates autoloader based on composer.json file.
*
* @param {string} repoPath - The path to the repository where composer.json is located.
*
* @returns {Promise} - A promise resolving when the installation process is completed.
*/
async function installComposer (repoPath) {
console.log('🎻 Found composer.json');
await exec('composer install --no-dev', { cwd: repoPath });
Expand Down Expand Up @@ -287,6 +294,12 @@ function getInfo (config, actions) {
console.log('🚀 Command line available actions: ' + JSON.stringify(actionsKeys, null, 2));
}

/**
* Logs the time passed in milliseconds since the given start time.
*
* @param {number} startTime - The start time in milliseconds.
* @return {undefined}
*/
function printTimePassed (startTime) {
// End the timer
const endTime = Date.now();
Expand Down