@elementor/wp-lite-env 0.0.12 → 0.0.14
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/CHANGELOG.md +12 -0
- package/__tests__/e2e.ts +7 -8
- package/dist/index.cjs +309 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +26 -23
- package/index.ts +4 -6
- package/package.json +7 -6
- package/src/run.ts +13 -7
- package/tsup.build.ts +1 -1
package/CHANGELOG.md
CHANGED
package/__tests__/e2e.ts
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
import {afterEach, describe, expect, test} from "@jest/globals";
|
1
|
+
import {afterEach, beforeAll, describe, expect, test} from "@jest/globals";
|
2
2
|
import {cleanup, generateFiles, getConfigFilePath, start, stop} from "../src/run";
|
3
3
|
|
4
4
|
const port = '1234';
|
5
|
-
const runPath = (port: string) => {
|
6
|
-
return generateFiles(port, getConfigFilePath(['', '', '', 'config=./tests/.wp-lite-env.json']));
|
7
|
-
};
|
8
5
|
|
9
6
|
describe('end to end tests', () => {
|
7
|
+
beforeAll(async () => {
|
8
|
+
generateFiles(port, getConfigFilePath(['', '', '', 'config=./tests/.wp-lite-env.json']));
|
9
|
+
})
|
10
10
|
afterEach(async () => {
|
11
|
-
|
12
|
-
|
13
|
-
cleanup(port, theRunPath);
|
11
|
+
await stop(port);
|
12
|
+
cleanup(port);
|
14
13
|
}, 30000);
|
15
14
|
test('WordPress is up and running', async () => {
|
16
|
-
await start( port
|
15
|
+
await start( port );
|
17
16
|
const response = await fetch(`http://localhost:${port}`);
|
18
17
|
expect(response.ok).toBe(true);
|
19
18
|
expect(await response.text()).toContain('Welcome to WordPress');
|
package/dist/index.cjs
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// index.ts
|
31
|
+
var wp_lite_env_exports = {};
|
32
|
+
__export(wp_lite_env_exports, {
|
33
|
+
cli: () => cli,
|
34
|
+
start: () => start,
|
35
|
+
stop: () => stop
|
36
|
+
});
|
37
|
+
module.exports = __toCommonJS(wp_lite_env_exports);
|
38
|
+
|
39
|
+
// src/run.ts
|
40
|
+
var import_docker_compose = require("docker-compose");
|
41
|
+
var import_path2 = __toESM(require("path"), 1);
|
42
|
+
|
43
|
+
// src/config.ts
|
44
|
+
var import_fs = __toESM(require("fs"), 1);
|
45
|
+
var getConfig = (configFilePath2) => {
|
46
|
+
let configFile = {};
|
47
|
+
if (configFilePath2) {
|
48
|
+
configFile = JSON.parse(import_fs.default.readFileSync(configFilePath2, "utf8"));
|
49
|
+
}
|
50
|
+
const defaultConfig = {
|
51
|
+
core: "6.7",
|
52
|
+
phpVersion: "8.1",
|
53
|
+
plugins: {},
|
54
|
+
themes: {},
|
55
|
+
mappings: {},
|
56
|
+
config: {}
|
57
|
+
};
|
58
|
+
return {
|
59
|
+
core: configFile.core || defaultConfig.core,
|
60
|
+
phpVersion: configFile.phpVersion || defaultConfig.phpVersion,
|
61
|
+
plugins: configFile.plugins || defaultConfig.plugins,
|
62
|
+
themes: configFile.themes || defaultConfig.themes,
|
63
|
+
mappings: configFile.mappings || defaultConfig.mappings,
|
64
|
+
config: configFile.config || defaultConfig.config
|
65
|
+
};
|
66
|
+
};
|
67
|
+
|
68
|
+
// src/run.ts
|
69
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
70
|
+
|
71
|
+
// src/templates.ts
|
72
|
+
var import_path = __toESM(require("path"), 1);
|
73
|
+
var generateDockerComposeYmlTemplate = (config, basePath, port2, configPath) => {
|
74
|
+
const mappingsStringArray = Object.keys(config.mappings).map((key) => {
|
75
|
+
const value = config.mappings[key];
|
76
|
+
return ` - >-
|
77
|
+
${import_path.default.resolve(basePath, value)}:/var/www/html/${key}
|
78
|
+
`;
|
79
|
+
});
|
80
|
+
const pluginsStringArray = Object.keys(config.plugins).map((key) => {
|
81
|
+
const value = config.plugins[key];
|
82
|
+
return ` - >-
|
83
|
+
${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}
|
84
|
+
`;
|
85
|
+
});
|
86
|
+
const themesStringArray = Object.keys(config.themes).map((key) => {
|
87
|
+
const value = config.themes[key];
|
88
|
+
return ` - >-
|
89
|
+
${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}
|
90
|
+
`;
|
91
|
+
});
|
92
|
+
const wpContent = ` - >-
|
93
|
+
wpcontent:/var/www/html
|
94
|
+
`;
|
95
|
+
const wpConfig = ` - >-
|
96
|
+
${configPath}:/var/www/html/wp-config
|
97
|
+
`;
|
98
|
+
const volumes = mappingsStringArray.concat(pluginsStringArray).concat(themesStringArray).concat([wpContent, wpConfig]).join("");
|
99
|
+
return `services:
|
100
|
+
mysql:
|
101
|
+
image: 'mariadb:lts'
|
102
|
+
ports:
|
103
|
+
- '\${WP_ENV_MYSQL_PORT:-}:3306'
|
104
|
+
environment:
|
105
|
+
MYSQL_ROOT_HOST: '%'
|
106
|
+
MYSQL_ROOT_PASSWORD: password
|
107
|
+
MYSQL_DATABASE: wordpress
|
108
|
+
volumes:
|
109
|
+
- 'mysql:/var/lib/mysql'
|
110
|
+
wordpress:
|
111
|
+
depends_on:
|
112
|
+
- mysql
|
113
|
+
build:
|
114
|
+
context: .
|
115
|
+
dockerfile: WordPress.Dockerfile
|
116
|
+
no_cache: true
|
117
|
+
args: &ref_0
|
118
|
+
HOST_USERNAME: yotams
|
119
|
+
HOST_UID: '502'
|
120
|
+
HOST_GID: '20'
|
121
|
+
ports:
|
122
|
+
- '\${WP_ENV_PORT:-${port2}}:80'
|
123
|
+
environment:
|
124
|
+
APACHE_RUN_USER: '#502'
|
125
|
+
APACHE_RUN_GROUP: '#20'
|
126
|
+
WORDPRESS_DB_USER: root
|
127
|
+
WORDPRESS_DB_PASSWORD: password
|
128
|
+
WORDPRESS_DB_NAME: wordpress
|
129
|
+
volumes: &ref_1
|
130
|
+
${volumes}
|
131
|
+
extra_hosts:
|
132
|
+
- 'host.docker.internal:host-gateway'
|
133
|
+
cli:
|
134
|
+
depends_on:
|
135
|
+
- wordpress
|
136
|
+
build:
|
137
|
+
context: .
|
138
|
+
dockerfile: CLI.Dockerfile
|
139
|
+
args: *ref_0
|
140
|
+
volumes: *ref_1
|
141
|
+
user: '502:20'
|
142
|
+
environment:
|
143
|
+
WORDPRESS_DB_USER: root
|
144
|
+
WORDPRESS_DB_PASSWORD: password
|
145
|
+
WORDPRESS_DB_NAME: wordpress
|
146
|
+
extra_hosts:
|
147
|
+
- 'host.docker.internal:host-gateway'
|
148
|
+
volumes:
|
149
|
+
mysql: {}
|
150
|
+
wpcontent: {}
|
151
|
+
`;
|
152
|
+
};
|
153
|
+
var generateWordPressDockerfileTemplate = (config) => {
|
154
|
+
return `FROM wordpress:${config.core}-php${config.phpVersion}
|
155
|
+
ARG HOST_USERNAME
|
156
|
+
ARG HOST_UID
|
157
|
+
ARG HOST_GID
|
158
|
+
# When the IDs are already in use we can still safely move on.
|
159
|
+
RUN groupadd -o -g $HOST_GID $HOST_USERNAME || true
|
160
|
+
RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
|
161
|
+
`;
|
162
|
+
};
|
163
|
+
var generateCliDockerfileTemplate = (config) => {
|
164
|
+
return `FROM wordpress:cli-php${config.phpVersion}
|
165
|
+
ARG HOST_USERNAME
|
166
|
+
ARG HOST_UID
|
167
|
+
ARG HOST_GID
|
168
|
+
# When the IDs are already in use we can still safely move on.
|
169
|
+
RUN addgroup -g $HOST_GID $HOST_USERNAME || true
|
170
|
+
RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
|
171
|
+
# RUN adduser -h /home/$HOST_USERNAME -G $( getent group $HOST_GID | cut -d: -f1 ) -u $HOST_UID $HOST_USERNAME || true
|
172
|
+
|
173
|
+
# Have the container sleep infinitely to keep it alive for us to run commands on it.
|
174
|
+
CMD [ "/bin/sh", "-c", "while true; do sleep 2073600; done" ]
|
175
|
+
`;
|
176
|
+
};
|
177
|
+
var generateConfiguration = (config, port2) => {
|
178
|
+
const header = `#!/bin/bash
|
179
|
+
set -eox pipefail
|
180
|
+
`;
|
181
|
+
const configStringArray = Object.keys(config.config).map((key) => {
|
182
|
+
const value = config.config[key];
|
183
|
+
return `wp config set ${key} ${value} --raw`;
|
184
|
+
});
|
185
|
+
const wpCoreInstall = `wp core install --url="http://localhost:${port2}" --title="test" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`;
|
186
|
+
return [header, wpCoreInstall].concat(configStringArray).join("\n");
|
187
|
+
};
|
188
|
+
|
189
|
+
// src/run.ts
|
190
|
+
var import_crypto = require("crypto");
|
191
|
+
var import_node_os = __toESM(require("os"), 1);
|
192
|
+
var waitForServer = async (url, timeoutMs) => {
|
193
|
+
const startTime = Date.now();
|
194
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
195
|
+
while (startTime + timeoutMs > Date.now()) {
|
196
|
+
try {
|
197
|
+
const response = await fetch(url);
|
198
|
+
if (response.ok && (200 === response.status || 302 === response.status)) {
|
199
|
+
return true;
|
200
|
+
}
|
201
|
+
} catch (e) {
|
202
|
+
} finally {
|
203
|
+
await sleep(100);
|
204
|
+
}
|
205
|
+
}
|
206
|
+
return false;
|
207
|
+
};
|
208
|
+
var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), port2);
|
209
|
+
var start = async (port2) => {
|
210
|
+
const runPath = getRunPath(port2);
|
211
|
+
await (0, import_docker_compose.upAll)({
|
212
|
+
commandOptions: ["--build"],
|
213
|
+
composeOptions: ["-p", `port${port2}`],
|
214
|
+
cwd: runPath,
|
215
|
+
log: true
|
216
|
+
});
|
217
|
+
await waitForServer(`http://localhost:${port2}`, 1e4);
|
218
|
+
await cli(port2, "bash wp-config/configure-wp.sh");
|
219
|
+
};
|
220
|
+
var stop = async (port2) => {
|
221
|
+
const runPath = getRunPath(port2);
|
222
|
+
await (0, import_docker_compose.downAll)({
|
223
|
+
cwd: runPath,
|
224
|
+
commandOptions: ["--volumes", "--remove-orphans"],
|
225
|
+
composeOptions: ["-p", `port${port2}`],
|
226
|
+
log: true
|
227
|
+
});
|
228
|
+
};
|
229
|
+
var cli = async (port2, command2) => {
|
230
|
+
const runPath = getRunPath(port2);
|
231
|
+
await (0, import_docker_compose.run)("cli", command2, {
|
232
|
+
cwd: runPath,
|
233
|
+
commandOptions: ["--rm"],
|
234
|
+
composeOptions: ["-p", `port${port2}`],
|
235
|
+
log: true
|
236
|
+
});
|
237
|
+
};
|
238
|
+
var commandMap = {
|
239
|
+
start,
|
240
|
+
stop,
|
241
|
+
cli
|
242
|
+
};
|
243
|
+
var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), port2);
|
244
|
+
var generateFiles = (port2, configFilePath2) => {
|
245
|
+
const config = getConfig(configFilePath2);
|
246
|
+
const wpConfigPath = getWpConfigPath(port2);
|
247
|
+
if (!import_fs2.default.existsSync(wpConfigPath)) {
|
248
|
+
import_fs2.default.mkdirSync(wpConfigPath, { recursive: true });
|
249
|
+
}
|
250
|
+
const wpConfig = generateConfiguration(config, port2);
|
251
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
|
252
|
+
const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port2, wpConfigPath);
|
253
|
+
const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
|
254
|
+
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
255
|
+
const hash = (0, import_crypto.createHash)("sha256");
|
256
|
+
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
|
257
|
+
const runPath = getRunPath(port2);
|
258
|
+
if (!import_fs2.default.existsSync(runPath)) {
|
259
|
+
import_fs2.default.mkdirSync(runPath);
|
260
|
+
}
|
261
|
+
console.log(`writing files to run path: ${runPath}`);
|
262
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
263
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
264
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
265
|
+
return runPath;
|
266
|
+
};
|
267
|
+
var getArgument = (argumentKey, processArgs) => {
|
268
|
+
for (let i = 3; i < processArgs.length; i++) {
|
269
|
+
const argument = processArgs[i];
|
270
|
+
if (argument.startsWith(`${argumentKey}=`)) {
|
271
|
+
return argument.substring(argumentKey.length + 1);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
return void 0;
|
275
|
+
};
|
276
|
+
var getConfigFilePath = (processArgs) => {
|
277
|
+
return import_path2.default.resolve(getArgument("config", processArgs));
|
278
|
+
};
|
279
|
+
var getCliCommand = (processArgs) => {
|
280
|
+
return getArgument("command", processArgs);
|
281
|
+
};
|
282
|
+
var getPort = (processArgs) => {
|
283
|
+
return getArgument("port", processArgs) || "8888";
|
284
|
+
};
|
285
|
+
var cleanup = (port2) => {
|
286
|
+
const runPath = getRunPath(port2);
|
287
|
+
import_fs2.default.rmSync(getWpConfigPath(port2), { recursive: true, force: true });
|
288
|
+
import_fs2.default.rmSync(runPath, { recursive: true, force: true });
|
289
|
+
};
|
290
|
+
|
291
|
+
// index.ts
|
292
|
+
var command = process.argv[2];
|
293
|
+
if (!commandMap[command]) {
|
294
|
+
console.log(`Valid commands: ${Object.keys(commandMap).join(", ")}. You used ${command}`);
|
295
|
+
}
|
296
|
+
var port = getPort(process.argv);
|
297
|
+
var configFilePath = getConfigFilePath(process.argv);
|
298
|
+
var cliCommand = getCliCommand(process.argv);
|
299
|
+
generateFiles(port, configFilePath);
|
300
|
+
commandMap[command](port, cliCommand).finally(() => {
|
301
|
+
cleanup(port);
|
302
|
+
});
|
303
|
+
// Annotate the CommonJS export names for ESM import in node:
|
304
|
+
0 && (module.exports = {
|
305
|
+
cli,
|
306
|
+
start,
|
307
|
+
stop
|
308
|
+
});
|
309
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
declare const start: (port: string
|
3
|
-
declare const stop: (port: string
|
4
|
-
declare const cli: (port: string,
|
2
|
+
declare const start: (port: string) => Promise<void>;
|
3
|
+
declare const stop: (port: string) => Promise<void>;
|
4
|
+
declare const cli: (port: string, command: string) => Promise<void>;
|
5
5
|
|
6
6
|
export { cli, start, stop };
|
package/dist/index.js
CHANGED
@@ -169,27 +169,31 @@ var waitForServer = async (url, timeoutMs) => {
|
|
169
169
|
}
|
170
170
|
return false;
|
171
171
|
};
|
172
|
-
var
|
172
|
+
var getRunPath = (port2) => path2.resolve(os.tmpdir(), port2);
|
173
|
+
var start = async (port2) => {
|
174
|
+
const runPath = getRunPath(port2);
|
173
175
|
await upAll({
|
174
176
|
commandOptions: ["--build"],
|
175
177
|
composeOptions: ["-p", `port${port2}`],
|
176
|
-
cwd:
|
178
|
+
cwd: runPath,
|
177
179
|
log: true
|
178
180
|
});
|
179
181
|
await waitForServer(`http://localhost:${port2}`, 1e4);
|
180
|
-
await cli(port2,
|
182
|
+
await cli(port2, "bash wp-config/configure-wp.sh");
|
181
183
|
};
|
182
|
-
var stop = async (port2
|
184
|
+
var stop = async (port2) => {
|
185
|
+
const runPath = getRunPath(port2);
|
183
186
|
await downAll({
|
184
|
-
cwd:
|
187
|
+
cwd: runPath,
|
185
188
|
commandOptions: ["--volumes", "--remove-orphans"],
|
186
189
|
composeOptions: ["-p", `port${port2}`],
|
187
190
|
log: true
|
188
191
|
});
|
189
192
|
};
|
190
|
-
var cli = async (port2,
|
193
|
+
var cli = async (port2, command2) => {
|
194
|
+
const runPath = getRunPath(port2);
|
191
195
|
await run("cli", command2, {
|
192
|
-
cwd:
|
196
|
+
cwd: runPath,
|
193
197
|
commandOptions: ["--rm"],
|
194
198
|
composeOptions: ["-p", `port${port2}`],
|
195
199
|
log: true
|
@@ -214,15 +218,15 @@ var generateFiles = (port2, configFilePath2) => {
|
|
214
218
|
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
215
219
|
const hash = createHash("sha256");
|
216
220
|
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
|
217
|
-
const
|
218
|
-
if (!fs2.existsSync(
|
219
|
-
fs2.mkdirSync(
|
221
|
+
const runPath = getRunPath(port2);
|
222
|
+
if (!fs2.existsSync(runPath)) {
|
223
|
+
fs2.mkdirSync(runPath);
|
220
224
|
}
|
221
|
-
console.log(`writing files to run path: ${
|
222
|
-
fs2.writeFileSync(path2.resolve(
|
223
|
-
fs2.writeFileSync(path2.resolve(
|
224
|
-
fs2.writeFileSync(path2.resolve(
|
225
|
-
return
|
225
|
+
console.log(`writing files to run path: ${runPath}`);
|
226
|
+
fs2.writeFileSync(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
227
|
+
fs2.writeFileSync(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
228
|
+
fs2.writeFileSync(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
229
|
+
return runPath;
|
226
230
|
};
|
227
231
|
var getArgument = (argumentKey, processArgs) => {
|
228
232
|
for (let i = 3; i < processArgs.length; i++) {
|
@@ -242,9 +246,10 @@ var getCliCommand = (processArgs) => {
|
|
242
246
|
var getPort = (processArgs) => {
|
243
247
|
return getArgument("port", processArgs) || "8888";
|
244
248
|
};
|
245
|
-
var cleanup = (port2
|
249
|
+
var cleanup = (port2) => {
|
250
|
+
const runPath = getRunPath(port2);
|
246
251
|
fs2.rmSync(getWpConfigPath(port2), { recursive: true, force: true });
|
247
|
-
fs2.rmSync(
|
252
|
+
fs2.rmSync(runPath, { recursive: true, force: true });
|
248
253
|
};
|
249
254
|
|
250
255
|
// index.ts
|
@@ -254,13 +259,11 @@ if (!commandMap[command]) {
|
|
254
259
|
}
|
255
260
|
var port = getPort(process.argv);
|
256
261
|
var configFilePath = getConfigFilePath(process.argv);
|
257
|
-
var runPath = generateFiles(port, configFilePath);
|
258
262
|
var cliCommand = getCliCommand(process.argv);
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
}
|
263
|
+
generateFiles(port, configFilePath);
|
264
|
+
commandMap[command](port, cliCommand).finally(() => {
|
265
|
+
cleanup(port);
|
266
|
+
});
|
264
267
|
export {
|
265
268
|
cli,
|
266
269
|
start,
|
package/index.ts
CHANGED
@@ -10,11 +10,9 @@ if ( ! commandMap[ command ] ) {
|
|
10
10
|
|
11
11
|
const port = getPort( process.argv );
|
12
12
|
const configFilePath = getConfigFilePath( process.argv )
|
13
|
-
const runPath = generateFiles( port, configFilePath );
|
14
13
|
const cliCommand = getCliCommand( process.argv );
|
14
|
+
generateFiles( port, configFilePath );
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
cleanup( port, runPath );
|
20
|
-
}
|
16
|
+
commandMap[command](port, cliCommand).finally( () => {
|
17
|
+
cleanup( port );
|
18
|
+
} );
|
package/package.json
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "@elementor/wp-lite-env",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.14",
|
4
4
|
"private": false,
|
5
5
|
"description": "A simple, lightweight, docker-based WordPress environment",
|
6
|
-
"main": "dist/index.
|
6
|
+
"main": "dist/index.cjs",
|
7
|
+
"module": "dist/index.js",
|
7
8
|
"type": "module",
|
8
|
-
"types": "dist/index.d.
|
9
|
+
"types": "dist/index.d.cts",
|
9
10
|
"bin": {
|
10
|
-
"wp-lite-env": "dist/index.
|
11
|
+
"wp-lite-env": "dist/index.cjs"
|
11
12
|
},
|
12
13
|
"scripts": {
|
13
14
|
"build": "tsup --config=./tsup.build.ts",
|
@@ -37,12 +38,12 @@
|
|
37
38
|
"@eslint/js": "^9.15.0",
|
38
39
|
"@jest/globals": "^29.7.0",
|
39
40
|
"@types/eslint__js": "^8.42.3",
|
40
|
-
"@types/node": "^22.
|
41
|
+
"@types/node": "^22.10.0",
|
41
42
|
"eslint": "~9.14.0",
|
42
43
|
"jest": "^29.7.0",
|
43
44
|
"ts-jest": "^29.2.5",
|
44
45
|
"tsup": "^8.3.5",
|
45
46
|
"typescript": "^5.6.3",
|
46
|
-
"typescript-eslint": "^8.
|
47
|
+
"typescript-eslint": "^8.16.0"
|
47
48
|
}
|
48
49
|
}
|
package/src/run.ts
CHANGED
@@ -30,7 +30,10 @@ const waitForServer = async ( url: string, timeoutMs: number ) => {
|
|
30
30
|
return false;
|
31
31
|
};
|
32
32
|
|
33
|
-
|
33
|
+
const getRunPath = ( port: string ) => path.resolve( os.tmpdir(), port );
|
34
|
+
|
35
|
+
export const start = async ( port: string ) => {
|
36
|
+
const runPath = getRunPath( port );
|
34
37
|
await upAll( {
|
35
38
|
commandOptions: [ '--build' ],
|
36
39
|
composeOptions: [ '-p', `port${ port }` ],
|
@@ -38,10 +41,11 @@ export const start = async ( port: string, runPath: string ) => {
|
|
38
41
|
log: true,
|
39
42
|
} );
|
40
43
|
await waitForServer( `http://localhost:${ port }`, 10000 );
|
41
|
-
await cli( port,
|
44
|
+
await cli( port, 'bash wp-config/configure-wp.sh' );
|
42
45
|
};
|
43
46
|
|
44
|
-
export const stop = async ( port: string
|
47
|
+
export const stop = async ( port: string ) => {
|
48
|
+
const runPath = getRunPath( port );
|
45
49
|
await downAll( {
|
46
50
|
cwd: runPath,
|
47
51
|
commandOptions: [ '--volumes', '--remove-orphans' ],
|
@@ -50,7 +54,8 @@ export const stop = async ( port: string, runPath: string ) => {
|
|
50
54
|
} );
|
51
55
|
};
|
52
56
|
|
53
|
-
export const cli = async ( port: string,
|
57
|
+
export const cli = async ( port: string, command: string ) => {
|
58
|
+
const runPath = getRunPath( port );
|
54
59
|
await run( 'cli', command, {
|
55
60
|
cwd: runPath,
|
56
61
|
commandOptions: [ '--rm' ],
|
@@ -59,7 +64,7 @@ export const cli = async ( port: string, runPath: string, command: string ) => {
|
|
59
64
|
} );
|
60
65
|
};
|
61
66
|
|
62
|
-
export const commandMap: { [key: string]: ( ( port: string ) => Promise<void> ) | ( ( port: string,
|
67
|
+
export const commandMap: { [key: string]: ( ( port: string ) => Promise<void> ) | ( ( port: string, command: string ) => Promise<void> ) } = {
|
63
68
|
start,
|
64
69
|
stop,
|
65
70
|
cli,
|
@@ -84,7 +89,7 @@ export const generateFiles = ( port: string, configFilePath: string ) => {
|
|
84
89
|
const cliDockerfileTemplate = generateCliDockerfileTemplate( config );
|
85
90
|
const hash = createHash( 'sha256' );
|
86
91
|
hash.update( dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port );
|
87
|
-
const runPath =
|
92
|
+
const runPath = getRunPath( port );
|
88
93
|
if ( ! fs.existsSync( runPath ) ) {
|
89
94
|
fs.mkdirSync( runPath );
|
90
95
|
}
|
@@ -119,7 +124,8 @@ export const getPort = ( processArgs: string[] ) => {
|
|
119
124
|
return getArgument( 'port', processArgs ) || '8888';
|
120
125
|
};
|
121
126
|
|
122
|
-
export const cleanup = ( port: string
|
127
|
+
export const cleanup = ( port: string ) => {
|
128
|
+
const runPath = getRunPath( port );
|
123
129
|
fs.rmSync( getWpConfigPath( port ), { recursive: true, force: true } );
|
124
130
|
fs.rmSync( runPath, { recursive: true, force: true } );
|
125
131
|
}
|