@atomicsmash/cli 9.0.1-beta.0 → 9.0.1-beta.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAQA,OAAO,eAAe,CAAC;AAEvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,wBAAsB,OAAO,kBAuF5B"}
1
+ {"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAQA,OAAO,eAAe,CAAC;AAiEvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,wBAAsB,OAAO,kBAkG5B"}
@@ -3,6 +3,60 @@ import { performance } from "node:perf_hooks";
3
3
  import { promisify } from "node:util";
4
4
  import { convertMeasureToPrettyString, getSmashConfig, startRunningMessage, } from "../utils.js";
5
5
  import "dotenv/config";
6
+ function extractDependenciesFromError(errorMessage) {
7
+ // Extract plugin names from error messages like:
8
+ // "Warning: Failed to activate plugin. Discount Rules for WooCommerce requires 1 plugin to be installed and activated: WooCommerce."
9
+ const regex = /requires \d+ plugin[s]? to be installed and activated: (.+)\./;
10
+ const match = regex.exec(errorMessage);
11
+ if (match?.[1]) {
12
+ return match[1].split(',').map(dep => dep.trim());
13
+ }
14
+ return [];
15
+ }
16
+ async function activatePluginsWithRetry(execute, pluginsToActivate, excludedPlugins) {
17
+ const maxRetries = 10; // Prevent infinite loops
18
+ let retryCount = 0;
19
+ const remainingPlugins = [...pluginsToActivate];
20
+ while (remainingPlugins.length > 0 && retryCount < maxRetries) {
21
+ const pluginsToTry = [...remainingPlugins];
22
+ remainingPlugins.length = 0; // Clear the array
23
+ for (const pluginName of pluginsToTry) {
24
+ if (excludedPlugins.includes(pluginName)) {
25
+ continue;
26
+ }
27
+ try {
28
+ await execute(`wp plugin activate ${pluginName}`);
29
+ console.log(`✓ Activated ${pluginName}`);
30
+ }
31
+ catch (error) {
32
+ const errorMessage = error instanceof Error ? error.message : String(error);
33
+ // Check if this is a dependency error
34
+ const dependencies = extractDependenciesFromError(errorMessage);
35
+ if (dependencies.length > 0) {
36
+ console.log(`⚠ ${pluginName} requires dependencies: ${dependencies.join(', ')}`);
37
+ // Add dependencies to the remaining plugins list if they're not already there
38
+ for (const dep of dependencies) {
39
+ if (!pluginsToActivate.includes(dep) && !excludedPlugins.includes(dep)) {
40
+ pluginsToActivate.push(dep);
41
+ }
42
+ if (!remainingPlugins.includes(dep)) {
43
+ remainingPlugins.push(dep);
44
+ }
45
+ }
46
+ // Add the current plugin back to try again later
47
+ remainingPlugins.push(pluginName);
48
+ }
49
+ else {
50
+ console.warn(`⚠ Warning: Could not activate ${pluginName}: ${errorMessage}`);
51
+ }
52
+ }
53
+ }
54
+ retryCount++;
55
+ }
56
+ if (remainingPlugins.length > 0) {
57
+ console.warn(`⚠ Warning: Could not activate all plugins after ${maxRetries} attempts. Remaining: ${remainingPlugins.join(', ')}`);
58
+ }
59
+ }
6
60
  export const command = "setup-database";
7
61
  export const describe = "Create a new database and initialise the site with no content.";
8
62
  export async function handler() {
@@ -30,12 +84,20 @@ export async function handler() {
30
84
  return execute(`wp user create ${process.env.WORDPRESS_USER} ${process.env.WORDPRESS_USER_EMAIL} --user_pass=${process.env.WORDPRESS_PASSWORD} --role=administrator`);
31
85
  }
32
86
  })
33
- .then(() => {
87
+ .then(async () => {
34
88
  if (addCustomUser) {
35
89
  performance.mark("add-custom-user");
36
90
  console.log(`Custom user ${process.env.WORDPRESS_USER} added. (${convertMeasureToPrettyString(performance.measure("add-custom-user", "wordpress-tables"))})`);
37
91
  }
38
- return execute(`wp plugin activate --all --exclude=wordfence,shortpixel-image-optimiser`);
92
+ const excludedPlugins = ['stream', 'shortpixel-image-optimiser', 'wordfence'];
93
+ const { stdout: pluginList } = await execute('wp plugin list --format=json');
94
+ const allPlugins = JSON.parse(pluginList);
95
+ // Filter out excluded plugins and already active plugins
96
+ const pluginsToActivate = allPlugins
97
+ .filter(plugin => !excludedPlugins.includes(plugin.name) &&
98
+ plugin.status !== 'active')
99
+ .map(plugin => plugin.name);
100
+ await activatePluginsWithRetry(execute, pluginsToActivate, excludedPlugins);
39
101
  })
40
102
  .then(() => {
41
103
  performance.mark("plugins");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomicsmash/cli",
3
- "version": "9.0.1-beta.0",
3
+ "version": "9.0.1-beta.2",
4
4
  "description": "A collection of CLI tools by Atomic Smash.",
5
5
  "keywords": [],
6
6
  "homepage": "https://www.atomicsmash.co.uk/",