@elementor/wp-lite-env 0.0.14 → 0.0.16
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 +1 -2
- package/dist/bin.cjs +288 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +20 -0
- package/dist/chunk-UBXF6D42.js +264 -0
- package/dist/index.cjs +24 -231
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +4 -265
- package/package.json +2 -2
- package/{index.ts → src/bin.ts} +2 -5
- package/src/index.ts +1 -0
- package/src/run.ts +2 -1
- package/tsup.build.ts +1 -1
- package/tsup.dev.ts +1 -1
package/CHANGELOG.md
CHANGED
package/__tests__/e2e.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import {afterEach, beforeAll, describe, expect, test} from "@jest/globals";
|
2
|
-
import {
|
2
|
+
import {generateFiles, getConfigFilePath, start, stop} from "../src/run";
|
3
3
|
|
4
4
|
const port = '1234';
|
5
5
|
|
@@ -9,7 +9,6 @@ describe('end to end tests', () => {
|
|
9
9
|
})
|
10
10
|
afterEach(async () => {
|
11
11
|
await stop(port);
|
12
|
-
cleanup(port);
|
13
12
|
}, 30000);
|
14
13
|
test('WordPress is up and running', async () => {
|
15
14
|
await start( port );
|
package/dist/bin.cjs
ADDED
@@ -0,0 +1,288 @@
|
|
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
|
+
cleanup(port2);
|
215
|
+
};
|
216
|
+
var cli = async (port2, command2) => {
|
217
|
+
const runPath = getRunPath(port2);
|
218
|
+
await (0, import_docker_compose.run)("cli", command2, {
|
219
|
+
cwd: runPath,
|
220
|
+
commandOptions: ["--rm"],
|
221
|
+
composeOptions: ["-p", `port${port2}`],
|
222
|
+
log: true
|
223
|
+
});
|
224
|
+
};
|
225
|
+
var commandMap = {
|
226
|
+
start,
|
227
|
+
stop,
|
228
|
+
cli
|
229
|
+
};
|
230
|
+
var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), port2);
|
231
|
+
var generateFiles = (port2, configFilePath2) => {
|
232
|
+
const config = getConfig(configFilePath2);
|
233
|
+
const wpConfigPath = getWpConfigPath(port2);
|
234
|
+
if (!import_fs2.default.existsSync(wpConfigPath)) {
|
235
|
+
import_fs2.default.mkdirSync(wpConfigPath, { recursive: true });
|
236
|
+
}
|
237
|
+
const wpConfig = generateConfiguration(config, port2);
|
238
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
|
239
|
+
const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port2, wpConfigPath);
|
240
|
+
const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
|
241
|
+
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
242
|
+
const hash = (0, import_crypto.createHash)("sha256");
|
243
|
+
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
|
244
|
+
const runPath = getRunPath(port2);
|
245
|
+
if (!import_fs2.default.existsSync(runPath)) {
|
246
|
+
import_fs2.default.mkdirSync(runPath);
|
247
|
+
}
|
248
|
+
console.log(`writing files to run path: ${runPath}`);
|
249
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
250
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
251
|
+
import_fs2.default.writeFileSync(import_path2.default.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
252
|
+
return runPath;
|
253
|
+
};
|
254
|
+
var getArgument = (argumentKey, processArgs) => {
|
255
|
+
for (let i = 3; i < processArgs.length; i++) {
|
256
|
+
const argument = processArgs[i];
|
257
|
+
if (argument.startsWith(`${argumentKey}=`)) {
|
258
|
+
return argument.substring(argumentKey.length + 1);
|
259
|
+
}
|
260
|
+
}
|
261
|
+
return void 0;
|
262
|
+
};
|
263
|
+
var getConfigFilePath = (processArgs) => {
|
264
|
+
return import_path2.default.resolve(getArgument("config", processArgs));
|
265
|
+
};
|
266
|
+
var getCliCommand = (processArgs) => {
|
267
|
+
return getArgument("command", processArgs);
|
268
|
+
};
|
269
|
+
var getPort = (processArgs) => {
|
270
|
+
return getArgument("port", processArgs) || "8888";
|
271
|
+
};
|
272
|
+
var cleanup = (port2) => {
|
273
|
+
const runPath = getRunPath(port2);
|
274
|
+
import_fs2.default.rmSync(getWpConfigPath(port2), { recursive: true, force: true });
|
275
|
+
import_fs2.default.rmSync(runPath, { recursive: true, force: true });
|
276
|
+
};
|
277
|
+
|
278
|
+
// src/bin.ts
|
279
|
+
var command = process.argv[2];
|
280
|
+
if (!commandMap[command]) {
|
281
|
+
console.log(`Valid commands: ${Object.keys(commandMap).join(", ")}. You used ${command}`);
|
282
|
+
}
|
283
|
+
var port = getPort(process.argv);
|
284
|
+
var configFilePath = getConfigFilePath(process.argv);
|
285
|
+
var cliCommand = getCliCommand(process.argv);
|
286
|
+
generateFiles(port, configFilePath);
|
287
|
+
commandMap[command](port, cliCommand);
|
288
|
+
//# 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,20 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import {
|
3
|
+
commandMap,
|
4
|
+
generateFiles,
|
5
|
+
getCliCommand,
|
6
|
+
getConfigFilePath,
|
7
|
+
getPort
|
8
|
+
} from "./chunk-UBXF6D42.js";
|
9
|
+
|
10
|
+
// src/bin.ts
|
11
|
+
var command = process.argv[2];
|
12
|
+
if (!commandMap[command]) {
|
13
|
+
console.log(`Valid commands: ${Object.keys(commandMap).join(", ")}. You used ${command}`);
|
14
|
+
}
|
15
|
+
var port = getPort(process.argv);
|
16
|
+
var configFilePath = getConfigFilePath(process.argv);
|
17
|
+
var cliCommand = getCliCommand(process.argv);
|
18
|
+
generateFiles(port, configFilePath);
|
19
|
+
commandMap[command](port, cliCommand);
|
20
|
+
//# 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
|
+
cleanup(port);
|
191
|
+
};
|
192
|
+
var cli = async (port, command) => {
|
193
|
+
const runPath = getRunPath(port);
|
194
|
+
await run("cli", command, {
|
195
|
+
cwd: runPath,
|
196
|
+
commandOptions: ["--rm"],
|
197
|
+
composeOptions: ["-p", `port${port}`],
|
198
|
+
log: true
|
199
|
+
});
|
200
|
+
};
|
201
|
+
var commandMap = {
|
202
|
+
start,
|
203
|
+
stop,
|
204
|
+
cli
|
205
|
+
};
|
206
|
+
var getWpConfigPath = (port) => path2.resolve(process.cwd(), port);
|
207
|
+
var generateFiles = (port, configFilePath) => {
|
208
|
+
const config = getConfig(configFilePath);
|
209
|
+
const wpConfigPath = getWpConfigPath(port);
|
210
|
+
if (!fs2.existsSync(wpConfigPath)) {
|
211
|
+
fs2.mkdirSync(wpConfigPath, { recursive: true });
|
212
|
+
}
|
213
|
+
const wpConfig = generateConfiguration(config, port);
|
214
|
+
fs2.writeFileSync(path2.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
|
215
|
+
const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port, wpConfigPath);
|
216
|
+
const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
|
217
|
+
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
218
|
+
const hash = createHash("sha256");
|
219
|
+
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port);
|
220
|
+
const runPath = getRunPath(port);
|
221
|
+
if (!fs2.existsSync(runPath)) {
|
222
|
+
fs2.mkdirSync(runPath);
|
223
|
+
}
|
224
|
+
console.log(`writing files to run path: ${runPath}`);
|
225
|
+
fs2.writeFileSync(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
226
|
+
fs2.writeFileSync(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
227
|
+
fs2.writeFileSync(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
228
|
+
return runPath;
|
229
|
+
};
|
230
|
+
var getArgument = (argumentKey, processArgs) => {
|
231
|
+
for (let i = 3; i < processArgs.length; i++) {
|
232
|
+
const argument = processArgs[i];
|
233
|
+
if (argument.startsWith(`${argumentKey}=`)) {
|
234
|
+
return argument.substring(argumentKey.length + 1);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return void 0;
|
238
|
+
};
|
239
|
+
var getConfigFilePath = (processArgs) => {
|
240
|
+
return path2.resolve(getArgument("config", processArgs));
|
241
|
+
};
|
242
|
+
var getCliCommand = (processArgs) => {
|
243
|
+
return getArgument("command", processArgs);
|
244
|
+
};
|
245
|
+
var getPort = (processArgs) => {
|
246
|
+
return getArgument("port", processArgs) || "8888";
|
247
|
+
};
|
248
|
+
var cleanup = (port) => {
|
249
|
+
const runPath = getRunPath(port);
|
250
|
+
fs2.rmSync(getWpConfigPath(port), { recursive: true, force: true });
|
251
|
+
fs2.rmSync(runPath, { recursive: true, force: true });
|
252
|
+
};
|
253
|
+
|
254
|
+
export {
|
255
|
+
start,
|
256
|
+
stop,
|
257
|
+
cli,
|
258
|
+
commandMap,
|
259
|
+
generateFiles,
|
260
|
+
getConfigFilePath,
|
261
|
+
getCliCommand,
|
262
|
+
getPort
|
263
|
+
};
|
264
|
+
//# sourceMappingURL=chunk-UBXF6D42.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,19 @@ 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
|
32
|
-
__export(
|
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(
|
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
|
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");
|
41
|
+
var import_fs = __toESM(require("fs"), 1);
|
191
42
|
var import_node_os = __toESM(require("os"), 1);
|
192
43
|
var waitForServer = async (url, timeoutMs) => {
|
193
44
|
const startTime = Date.now();
|
@@ -205,101 +56,43 @@ var waitForServer = async (url, timeoutMs) => {
|
|
205
56
|
}
|
206
57
|
return false;
|
207
58
|
};
|
208
|
-
var getRunPath = (
|
209
|
-
var start = async (
|
210
|
-
const runPath = getRunPath(
|
59
|
+
var getRunPath = (port) => import_path.default.resolve(import_node_os.default.tmpdir(), port);
|
60
|
+
var start = async (port) => {
|
61
|
+
const runPath = getRunPath(port);
|
211
62
|
await (0, import_docker_compose.upAll)({
|
212
63
|
commandOptions: ["--build"],
|
213
|
-
composeOptions: ["-p", `port${
|
64
|
+
composeOptions: ["-p", `port${port}`],
|
214
65
|
cwd: runPath,
|
215
66
|
log: true
|
216
67
|
});
|
217
|
-
await waitForServer(`http://localhost:${
|
218
|
-
await cli(
|
68
|
+
await waitForServer(`http://localhost:${port}`, 1e4);
|
69
|
+
await cli(port, "bash wp-config/configure-wp.sh");
|
219
70
|
};
|
220
|
-
var stop = async (
|
221
|
-
const runPath = getRunPath(
|
71
|
+
var stop = async (port) => {
|
72
|
+
const runPath = getRunPath(port);
|
222
73
|
await (0, import_docker_compose.downAll)({
|
223
74
|
cwd: runPath,
|
224
75
|
commandOptions: ["--volumes", "--remove-orphans"],
|
225
|
-
composeOptions: ["-p", `port${
|
76
|
+
composeOptions: ["-p", `port${port}`],
|
226
77
|
log: true
|
227
78
|
});
|
79
|
+
cleanup(port);
|
228
80
|
};
|
229
|
-
var cli = async (
|
230
|
-
const runPath = getRunPath(
|
231
|
-
await (0, import_docker_compose.run)("cli",
|
81
|
+
var cli = async (port, command) => {
|
82
|
+
const runPath = getRunPath(port);
|
83
|
+
await (0, import_docker_compose.run)("cli", command, {
|
232
84
|
cwd: runPath,
|
233
85
|
commandOptions: ["--rm"],
|
234
|
-
composeOptions: ["-p", `port${
|
86
|
+
composeOptions: ["-p", `port${port}`],
|
235
87
|
log: true
|
236
88
|
});
|
237
89
|
};
|
238
|
-
var
|
239
|
-
|
240
|
-
|
241
|
-
|
90
|
+
var getWpConfigPath = (port) => import_path.default.resolve(process.cwd(), port);
|
91
|
+
var cleanup = (port) => {
|
92
|
+
const runPath = getRunPath(port);
|
93
|
+
import_fs.default.rmSync(getWpConfigPath(port), { recursive: true, force: true });
|
94
|
+
import_fs.default.rmSync(runPath, { recursive: true, force: true });
|
242
95
|
};
|
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
96
|
// Annotate the CommonJS export names for ESM import in node:
|
304
97
|
0 && (module.exports = {
|
305
98
|
cli,
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,269 +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
|
-
commandMap[command](port, cliCommand).finally(() => {
|
265
|
-
cleanup(port);
|
266
|
-
});
|
4
|
+
stop
|
5
|
+
} from "./chunk-UBXF6D42.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.
|
3
|
+
"version": "0.0.16",
|
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/
|
11
|
+
"wp-lite-env": "dist/bin.cjs"
|
12
12
|
},
|
13
13
|
"scripts": {
|
14
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 {
|
4
|
-
export {start, stop, cli} from './src/run';
|
3
|
+
import {commandMap, generateFiles, getCliCommand, getConfigFilePath, getPort} from './run';
|
5
4
|
|
6
5
|
const command = process.argv[ 2 ];
|
7
6
|
if ( ! commandMap[ command ] ) {
|
@@ -13,6 +12,4 @@ const configFilePath = getConfigFilePath( process.argv )
|
|
13
12
|
const cliCommand = getCliCommand( process.argv );
|
14
13
|
generateFiles( port, configFilePath );
|
15
14
|
|
16
|
-
commandMap[command](port, cliCommand)
|
17
|
-
cleanup( port );
|
18
|
-
} );
|
15
|
+
commandMap[command](port, cliCommand);
|
package/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {start, stop, cli} from './run';
|
package/src/run.ts
CHANGED
@@ -52,6 +52,7 @@ export const stop = async ( port: string ) => {
|
|
52
52
|
composeOptions: [ '-p', `port${ port }` ],
|
53
53
|
log: true,
|
54
54
|
} );
|
55
|
+
cleanup( port );
|
55
56
|
};
|
56
57
|
|
57
58
|
export const cli = async ( port: string, command: string ) => {
|
@@ -124,7 +125,7 @@ export const getPort = ( processArgs: string[] ) => {
|
|
124
125
|
return getArgument( 'port', processArgs ) || '8888';
|
125
126
|
};
|
126
127
|
|
127
|
-
|
128
|
+
const cleanup = ( port: string ) => {
|
128
129
|
const runPath = getRunPath( port );
|
129
130
|
fs.rmSync( getWpConfigPath( port ), { recursive: true, force: true } );
|
130
131
|
fs.rmSync( runPath, { recursive: true, force: true } );
|
package/tsup.build.ts
CHANGED