@elementor/wp-lite-env 0.0.14 → 0.0.15

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