@atomicsmash/cli 12.0.2 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomicsmash/cli",
3
- "version": "12.0.2",
3
+ "version": "13.0.0",
4
4
  "description": "A collection of CLI tools by Atomic Smash.",
5
5
  "keywords": [],
6
6
  "homepage": "https://www.atomicsmash.co.uk/",
@@ -40,11 +40,11 @@
40
40
  "lint:types": "tsc -b"
41
41
  },
42
42
  "dependencies": {
43
- "@atomicsmash/smash-config": "^2.0.2",
43
+ "@atomicsmash/smash-config": "^2.0.3",
44
44
  "dotenv": "^17.4.2",
45
- "yargs": "^18.1.0"
45
+ "yargs": "^18.2.0"
46
46
  },
47
47
  "devDependencies": {
48
- "type-fest": "^5.9.0"
48
+ "type-fest": "^5.10.0"
49
49
  }
50
50
  }
@@ -1,6 +0,0 @@
1
- import "dotenv/config";
2
- export declare const command = "setup-database";
3
- export declare const describe = "Create a new database and initialise the site with no content.";
4
- export declare const deprecated = "You probably no longer need this with changes to the pull database script. If you do, migrate a copy of these commands into a local project script.";
5
- export declare function handler(): Promise<void>;
6
- //# sourceMappingURL=setup-database.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAKA,OAAO,eAAe,CAAC;AA+EvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,eAAO,MAAM,UAAU,wJAC+H,CAAC;AACvJ,wBAAsB,OAAO,kBAuH5B"}
@@ -1,138 +0,0 @@
1
- import { exec } from "node:child_process";
2
- import { performance } from "node:perf_hooks";
3
- import { promisify } from "node:util";
4
- import { getSmashConfig } from "@atomicsmash/smash-config";
5
- import { convertMeasureToPrettyString, startRunningMessage } from "../utils.js";
6
- import "dotenv/config";
7
- function extractDependenciesFromError(errorMessage) {
8
- // Extract plugin names from error messages like:
9
- // "Warning: Failed to activate plugin. Discount Rules for WooCommerce requires 1 plugin to be installed and activated: WooCommerce."
10
- const regex = /requires \d+ plugin[s]? to be installed and activated: (.+)\./;
11
- const match = regex.exec(errorMessage);
12
- if (match?.[1]) {
13
- return match[1].split(",").map((dep) => dep.trim());
14
- }
15
- return [];
16
- }
17
- async function activatePluginsWithRetry(execute, pluginsToActivate, excludedPlugins) {
18
- const maxRetries = 10; // Prevent infinite loops
19
- let retryCount = 0;
20
- const remainingPlugins = [...pluginsToActivate];
21
- while (remainingPlugins.length > 0 && retryCount < maxRetries) {
22
- const pluginsToTry = [...remainingPlugins];
23
- remainingPlugins.length = 0; // Clear the array
24
- for (const pluginName of pluginsToTry) {
25
- if (excludedPlugins.includes(pluginName)) {
26
- continue;
27
- }
28
- try {
29
- await execute(`wp plugin activate ${pluginName}`);
30
- console.log(`✓ Activated ${pluginName}`);
31
- }
32
- catch (error) {
33
- const errorMessage = error instanceof Error ? error.message : String(error);
34
- // Check if this is a dependency error
35
- const dependencies = extractDependenciesFromError(errorMessage);
36
- if (dependencies.length > 0) {
37
- console.log(`⚠ ${pluginName} requires dependencies: ${dependencies.join(", ")}`);
38
- // Add dependencies to the remaining plugins list if they're not already there
39
- for (const dep of dependencies) {
40
- if (!pluginsToActivate.includes(dep) &&
41
- !excludedPlugins.includes(dep)) {
42
- pluginsToActivate.push(dep);
43
- }
44
- if (!remainingPlugins.includes(dep)) {
45
- remainingPlugins.push(dep);
46
- }
47
- }
48
- // Add the current plugin back to try again later
49
- remainingPlugins.push(pluginName);
50
- }
51
- else {
52
- console.warn(`⚠ Warning: Could not activate ${pluginName}: ${errorMessage}`);
53
- }
54
- }
55
- }
56
- retryCount++;
57
- }
58
- if (remainingPlugins.length > 0) {
59
- console.warn(`⚠ Warning: Could not activate all plugins after ${maxRetries.toString()} attempts. Remaining: ${remainingPlugins.join(", ")}`);
60
- }
61
- }
62
- export const command = "setup-database";
63
- export const describe = "Create a new database and initialise the site with no content.";
64
- export const deprecated = "You probably no longer need this with changes to the pull database script. If you do, migrate a copy of these commands into a local project script.";
65
- export async function handler() {
66
- const execute = promisify(exec);
67
- const smashConfig = await getSmashConfig();
68
- // These must remain env vars because they differ for each dev.
69
- const newUserToAdd = process.env.WORDPRESS_USER &&
70
- process.env.WORDPRESS_USER_EMAIL &&
71
- process.env.WORDPRESS_PASSWORD
72
- ? {
73
- user: process.env.WORDPRESS_USER,
74
- email: process.env.WORDPRESS_USER_EMAIL,
75
- password: process.env.WORDPRESS_PASSWORD,
76
- }
77
- : null;
78
- const { projectName, themeFolderName } = smashConfig;
79
- const stopRunningMessage = startRunningMessage("Initialising database");
80
- performance.mark("Start");
81
- await execute("wp db create")
82
- .then(() => {
83
- return execute(`wp core install --url=http://${process.env.CI ? "127.0.0.1" : `${projectName}.test`}/ --title=Temp --admin_user=Bot --admin_email=fake@fake.com --admin_password=password`);
84
- })
85
- .then(() => {
86
- performance.mark("wordpress-tables");
87
- console.log(`Wordpress database tables installed. (${convertMeasureToPrettyString(performance.measure("wordpress-tables", "Start"))})`);
88
- if (newUserToAdd) {
89
- return execute(`wp user create ${newUserToAdd.user} ${newUserToAdd.email} --user_pass=${newUserToAdd.password} --role=administrator`);
90
- }
91
- })
92
- .then(async () => {
93
- if (newUserToAdd) {
94
- performance.mark("add-custom-user");
95
- console.log(`Custom user ${newUserToAdd.user} added. (${convertMeasureToPrettyString(performance.measure("add-custom-user", "wordpress-tables"))})`);
96
- }
97
- const excludedPlugins = [
98
- "stream",
99
- "shortpixel-image-optimiser",
100
- "wordfence",
101
- "wp-mail-smtp",
102
- "modular-connector",
103
- ];
104
- const { stdout: pluginList } = await execute("wp plugin list --format=json");
105
- const allPlugins = JSON.parse(pluginList);
106
- // Filter out excluded plugins and already active plugins
107
- const pluginsToActivate = allPlugins
108
- .filter((plugin) => !excludedPlugins.includes(plugin.name) &&
109
- plugin.status !== "active")
110
- .map((plugin) => plugin.name);
111
- await activatePluginsWithRetry(execute, pluginsToActivate, excludedPlugins);
112
- })
113
- .then(() => {
114
- performance.mark("plugins");
115
- console.log(`Plugins activated. (${convertMeasureToPrettyString(performance.measure("plugins", newUserToAdd ? "add-custom-user" : "wordpress-tables"))})`);
116
- return execute(`wp theme activate ${themeFolderName}`);
117
- })
118
- .then(async () => {
119
- performance.mark("theme");
120
- console.log(`Theme activated. (${convertMeasureToPrettyString(performance.measure("theme", "plugins"))})`);
121
- await stopRunningMessage();
122
- console.log(`Database set up${newUserToAdd ? ` and ${newUserToAdd.user} user added` : !process.env.CI ? ". To set up a user, run the `wp user create` command." : ""}. (${convertMeasureToPrettyString(performance.measure("everything", "Start"))})`);
123
- })
124
- .catch(async (error) => {
125
- await stopRunningMessage();
126
- if (typeof error === "object" &&
127
- error &&
128
- "stderr" in error &&
129
- typeof error.stderr === "string" &&
130
- error.stderr.startsWith("ERROR 1007")) {
131
- console.error("Database already exists with the name in the wp-config. Please delete that database first with `wp db drop --yes`");
132
- }
133
- else {
134
- console.error(error);
135
- process.exitCode = 1;
136
- }
137
- });
138
- }