@elementor/wp-lite-env 0.0.13 → 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 +12 -0
- package/dist/bin.cjs +289 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +23 -0
- package/dist/chunk-BYFZ2VGL.js +264 -0
- package/dist/index.cjs +94 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -267
- package/package.json +5 -4
- package/{index.ts → src/bin.ts} +3 -6
- package/src/index.ts +1 -0
- package/tsup.build.ts +2 -2
- package/tsup.dev.ts +1 -1
package/CHANGELOG.md
CHANGED
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
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
|
29
|
+
// src/index.ts
|
30
|
+
var src_exports = {};
|
31
|
+
__export(src_exports, {
|
32
|
+
cli: () => cli,
|
33
|
+
start: () => start,
|
34
|
+
stop: () => stop
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
37
|
+
|
38
|
+
// src/run.ts
|
39
|
+
var import_docker_compose = require("docker-compose");
|
40
|
+
var import_path = __toESM(require("path"), 1);
|
41
|
+
var import_node_os = __toESM(require("os"), 1);
|
42
|
+
var waitForServer = async (url, timeoutMs) => {
|
43
|
+
const startTime = Date.now();
|
44
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
45
|
+
while (startTime + timeoutMs > Date.now()) {
|
46
|
+
try {
|
47
|
+
const response = await fetch(url);
|
48
|
+
if (response.ok && (200 === response.status || 302 === response.status)) {
|
49
|
+
return true;
|
50
|
+
}
|
51
|
+
} catch (e) {
|
52
|
+
} finally {
|
53
|
+
await sleep(100);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return false;
|
57
|
+
};
|
58
|
+
var getRunPath = (port) => import_path.default.resolve(import_node_os.default.tmpdir(), port);
|
59
|
+
var start = async (port) => {
|
60
|
+
const runPath = getRunPath(port);
|
61
|
+
await (0, import_docker_compose.upAll)({
|
62
|
+
commandOptions: ["--build"],
|
63
|
+
composeOptions: ["-p", `port${port}`],
|
64
|
+
cwd: runPath,
|
65
|
+
log: true
|
66
|
+
});
|
67
|
+
await waitForServer(`http://localhost:${port}`, 1e4);
|
68
|
+
await cli(port, "bash wp-config/configure-wp.sh");
|
69
|
+
};
|
70
|
+
var stop = async (port) => {
|
71
|
+
const runPath = getRunPath(port);
|
72
|
+
await (0, import_docker_compose.downAll)({
|
73
|
+
cwd: runPath,
|
74
|
+
commandOptions: ["--volumes", "--remove-orphans"],
|
75
|
+
composeOptions: ["-p", `port${port}`],
|
76
|
+
log: true
|
77
|
+
});
|
78
|
+
};
|
79
|
+
var cli = async (port, command) => {
|
80
|
+
const runPath = getRunPath(port);
|
81
|
+
await (0, import_docker_compose.run)("cli", command, {
|
82
|
+
cwd: runPath,
|
83
|
+
commandOptions: ["--rm"],
|
84
|
+
composeOptions: ["-p", `port${port}`],
|
85
|
+
log: true
|
86
|
+
});
|
87
|
+
};
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
89
|
+
0 && (module.exports = {
|
90
|
+
cli,
|
91
|
+
start,
|
92
|
+
stop
|
93
|
+
});
|
94
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,271 +1,8 @@
|
|
1
|
-
|
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
|
-
|
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
|
-
try {
|
265
|
-
await commandMap[command](port, cliCommand);
|
266
|
-
} finally {
|
267
|
-
cleanup(port);
|
268
|
-
}
|
4
|
+
stop
|
5
|
+
} from "./chunk-BYFZ2VGL.js";
|
269
6
|
export {
|
270
7
|
cli,
|
271
8
|
start,
|
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.15",
|
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/
|
11
|
+
"wp-lite-env": "dist/bin.cjs"
|
11
12
|
},
|
12
13
|
"scripts": {
|
13
14
|
"build": "tsup --config=./tsup.build.ts",
|
package/{index.ts → src/bin.ts}
RENAMED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
import {cleanup, commandMap, generateFiles, getCliCommand, getConfigFilePath, getPort} from './
|
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 ] ) {
|
@@ -13,8 +12,6 @@ const configFilePath = getConfigFilePath( process.argv )
|
|
13
12
|
const cliCommand = getCliCommand( process.argv );
|
14
13
|
generateFiles( port, configFilePath );
|
15
14
|
|
16
|
-
|
17
|
-
await commandMap[command](port, cliCommand);
|
18
|
-
} finally {
|
15
|
+
commandMap[command](port, cliCommand).finally( () => {
|
19
16
|
cleanup( port );
|
20
|
-
}
|
17
|
+
} );
|
package/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {start, stop, cli} from './run';
|
package/tsup.build.ts
CHANGED