@atomicsmash/cli 9.0.0 → 9.0.1-beta.1
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/dist/commands/pull-database.d.ts.map +1 -1
- package/dist/commands/pull-database.js +1 -0
- package/dist/commands/pull-media.d.ts.map +1 -1
- package/dist/commands/pull-media.js +1 -0
- package/dist/commands/setup-database.d.ts.map +1 -1
- package/dist/commands/setup-database.js +132 -2
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +3 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-database.d.ts","sourceRoot":"","sources":["../../src/commands/pull-database.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AACvC,eAAO,MAAM,QAAQ,oEAC6C,CAAC;AACnE,wBAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"pull-database.d.ts","sourceRoot":"","sources":["../../src/commands/pull-database.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,OAAO,kBAAkB,CAAC;AACvC,eAAO,MAAM,QAAQ,oEAC6C,CAAC;AACnE,wBAAsB,OAAO,kBA+J5B"}
|
|
@@ -140,6 +140,7 @@ export async function handler() {
|
|
|
140
140
|
if (failedCleanups.length > 0) {
|
|
141
141
|
console.warn(`Warning: Failed to delete ${failedCleanups.length} temporary file(s). You may need to clean them up manually.`);
|
|
142
142
|
}
|
|
143
|
+
process.exitCode = 1;
|
|
143
144
|
});
|
|
144
145
|
})();
|
|
145
146
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-media.d.ts","sourceRoot":"","sources":["../../src/commands/pull-media.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,QAAQ,gDAAgD,CAAC;AACtE,wBAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"pull-media.d.ts","sourceRoot":"","sources":["../../src/commands/pull-media.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,QAAQ,gDAAgD,CAAC;AACtE,wBAAsB,OAAO,kBA6E5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup-database.d.ts","sourceRoot":"","sources":["../../src/commands/setup-database.ts"],"names":[],"mappings":"AAUA,OAAO,eAAe,CAAC;AA4HvB,eAAO,MAAM,OAAO,mBAAmB,CAAC;AACxC,eAAO,MAAM,QAAQ,mEAC4C,CAAC;AAClE,wBAAsB,OAAO,kBAsH5B"}
|
|
@@ -1,8 +1,113 @@
|
|
|
1
1
|
import { exec } from "node:child_process";
|
|
2
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
2
4
|
import { performance } from "node:perf_hooks";
|
|
3
5
|
import { promisify } from "node:util";
|
|
4
6
|
import { convertMeasureToPrettyString, getSmashConfig, startRunningMessage, } from "../utils.js";
|
|
5
7
|
import "dotenv/config";
|
|
8
|
+
function parsePluginHeaders(pluginPath) {
|
|
9
|
+
try {
|
|
10
|
+
// Find the main plugin file by looking for the standard WordPress plugin header
|
|
11
|
+
const files = readdirSync(pluginPath).filter(file => file.endsWith('.php'));
|
|
12
|
+
let mainFile = null;
|
|
13
|
+
// Look for the file containing the standard plugin header
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
const content = readFileSync(join(pluginPath, file), 'utf8');
|
|
16
|
+
// Check for the standard plugin header (Plugin Name: field)
|
|
17
|
+
if (/^\s*\/\*\*[\s\S]*?Plugin Name:/m.test(content)) {
|
|
18
|
+
mainFile = file;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!mainFile)
|
|
23
|
+
return null;
|
|
24
|
+
const content = readFileSync(join(pluginPath, mainFile), 'utf8');
|
|
25
|
+
// Match the plugin header block
|
|
26
|
+
const headerPattern = /\/\*\*\s*([\s\S]*?)\s*\*\//;
|
|
27
|
+
const match = headerPattern.exec(content);
|
|
28
|
+
if (!match)
|
|
29
|
+
return null;
|
|
30
|
+
const headers = {};
|
|
31
|
+
const headerContent = match[1];
|
|
32
|
+
// Parse each header line
|
|
33
|
+
headerContent?.split('\n').forEach(line => {
|
|
34
|
+
const colonIndex = line.indexOf(':');
|
|
35
|
+
if (colonIndex > 0) {
|
|
36
|
+
const key = line.substring(0, colonIndex).trim().replace(/\*/g, '');
|
|
37
|
+
const value = line.substring(colonIndex + 1).trim();
|
|
38
|
+
if (key && value) {
|
|
39
|
+
headers[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return headers;
|
|
44
|
+
}
|
|
45
|
+
catch (_error) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function buildDependencyGraph(execute) {
|
|
50
|
+
const graph = new Map();
|
|
51
|
+
const pluginPaths = new Map();
|
|
52
|
+
// Get the plugins directory path
|
|
53
|
+
const { stdout: pluginsDir } = await execute('wp plugin path');
|
|
54
|
+
const pluginsDirectory = pluginsDir.trim();
|
|
55
|
+
// Get all plugins
|
|
56
|
+
const { stdout: pluginList } = await execute('wp plugin list --format=json');
|
|
57
|
+
const plugins = JSON.parse(pluginList);
|
|
58
|
+
// Map plugin names to their paths
|
|
59
|
+
for (const plugin of plugins) {
|
|
60
|
+
const pluginPath = `${pluginsDirectory}/${plugin.name}`;
|
|
61
|
+
pluginPaths.set(plugin.name, pluginPath);
|
|
62
|
+
}
|
|
63
|
+
// Parse headers and build dependency graph
|
|
64
|
+
for (const [pluginName, pluginPath] of pluginPaths) {
|
|
65
|
+
const headers = parsePluginHeaders(pluginPath);
|
|
66
|
+
if (headers?.['Requires Plugins']) {
|
|
67
|
+
// Parse the Requires Plugins field (comma-separated list)
|
|
68
|
+
const dependencies = headers['Requires Plugins']
|
|
69
|
+
.split(',')
|
|
70
|
+
.map(dep => dep.trim())
|
|
71
|
+
.filter(dep => dep.length > 0);
|
|
72
|
+
graph.set(pluginName, dependencies);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
graph.set(pluginName, []);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return graph;
|
|
79
|
+
}
|
|
80
|
+
function topologicalSort(graph) {
|
|
81
|
+
const visited = new Set();
|
|
82
|
+
const temp = new Set();
|
|
83
|
+
const result = [];
|
|
84
|
+
function visit(node) {
|
|
85
|
+
if (temp.has(node)) {
|
|
86
|
+
throw new Error(`Circular dependency detected involving ${node}`);
|
|
87
|
+
}
|
|
88
|
+
if (visited.has(node)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
temp.add(node);
|
|
92
|
+
// Visit all dependencies first
|
|
93
|
+
const dependencies = graph.get(node) ?? [];
|
|
94
|
+
for (const dep of dependencies) {
|
|
95
|
+
if (graph.has(dep)) {
|
|
96
|
+
visit(dep);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
temp.delete(node);
|
|
100
|
+
visited.add(node);
|
|
101
|
+
result.push(node);
|
|
102
|
+
}
|
|
103
|
+
// Visit all nodes
|
|
104
|
+
for (const node of graph.keys()) {
|
|
105
|
+
if (!visited.has(node)) {
|
|
106
|
+
visit(node);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
6
111
|
export const command = "setup-database";
|
|
7
112
|
export const describe = "Create a new database and initialise the site with no content.";
|
|
8
113
|
export async function handler() {
|
|
@@ -30,12 +135,36 @@ export async function handler() {
|
|
|
30
135
|
return execute(`wp user create ${process.env.WORDPRESS_USER} ${process.env.WORDPRESS_USER_EMAIL} --user_pass=${process.env.WORDPRESS_PASSWORD} --role=administrator`);
|
|
31
136
|
}
|
|
32
137
|
})
|
|
33
|
-
.then(() => {
|
|
138
|
+
.then(async () => {
|
|
34
139
|
if (addCustomUser) {
|
|
35
140
|
performance.mark("add-custom-user");
|
|
36
141
|
console.log(`Custom user ${process.env.WORDPRESS_USER} added. (${convertMeasureToPrettyString(performance.measure("add-custom-user", "wordpress-tables"))})`);
|
|
37
142
|
}
|
|
38
|
-
|
|
143
|
+
const dependencyGraph = await buildDependencyGraph(execute);
|
|
144
|
+
const excludedPlugins = ['stream', 'shortpixel-image-optimiser', 'wordfence'];
|
|
145
|
+
const { stdout: pluginList } = await execute('wp plugin list --format=json');
|
|
146
|
+
const allPlugins = JSON.parse(pluginList);
|
|
147
|
+
// Filter out excluded plugins and already active plugins
|
|
148
|
+
const pluginsToActivate = allPlugins.filter(plugin => !excludedPlugins.includes(plugin.name) &&
|
|
149
|
+
plugin.status !== 'active');
|
|
150
|
+
const filteredGraph = new Map();
|
|
151
|
+
for (const plugin of pluginsToActivate) {
|
|
152
|
+
const dependencies = dependencyGraph.get(plugin.name) ?? [];
|
|
153
|
+
// Only include dependencies that are also in our activation list
|
|
154
|
+
const filteredDependencies = dependencies.filter(dep => pluginsToActivate.some(p => p.name === dep));
|
|
155
|
+
filteredGraph.set(plugin.name, filteredDependencies);
|
|
156
|
+
}
|
|
157
|
+
const activationOrder = topologicalSort(filteredGraph);
|
|
158
|
+
for (const pluginName of activationOrder) {
|
|
159
|
+
try {
|
|
160
|
+
await execute(`wp plugin activate ${pluginName}`);
|
|
161
|
+
console.log(`✓ Activated ${pluginName}`);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
165
|
+
console.warn(`⚠ Warning: Could not activate ${pluginName}: ${errorMessage}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
39
168
|
})
|
|
40
169
|
.then(() => {
|
|
41
170
|
performance.mark("plugins");
|
|
@@ -55,6 +184,7 @@ export async function handler() {
|
|
|
55
184
|
}
|
|
56
185
|
else {
|
|
57
186
|
console.error(error);
|
|
187
|
+
process.exitCode = 1;
|
|
58
188
|
}
|
|
59
189
|
});
|
|
60
190
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,QAAQ,kDAAkD,CAAC;AACxE,wBAAsB,OAAO,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,QAAQ,kDAAkD,CAAC;AACxE,wBAAsB,OAAO,kBA+P5B"}
|
package/dist/commands/setup.js
CHANGED
|
@@ -174,6 +174,9 @@ export async function handler() {
|
|
|
174
174
|
else {
|
|
175
175
|
console.log(`Setup is complete. ${convertMeasureToPrettyString(performance.measure("everything", "Start"))}`);
|
|
176
176
|
}
|
|
177
|
+
}).catch((error) => {
|
|
178
|
+
console.error(error);
|
|
179
|
+
process.exitCode = 1;
|
|
177
180
|
});
|
|
178
181
|
}
|
|
179
182
|
}
|