@elementor/wp-lite-env 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # wp-lite-env
2
2
 
3
+ ## 0.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 81fa706: export commands
8
+
9
+ ## 0.0.11
10
+
11
+ ### Patch Changes
12
+
13
+ - 1d26547: use tsup for building the package
14
+
3
15
  ## 0.0.10
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=index.d.ts.map
2
+ declare const start: (port: string, runPath: string) => Promise<void>;
3
+ declare const stop: (port: string, runPath: string) => Promise<void>;
4
+ declare const cli: (port: string, runPath: string, command: string) => Promise<void>;
5
+
6
+ export { cli, start, stop };
package/dist/index.js CHANGED
@@ -1,16 +1,269 @@
1
1
  #!/usr/bin/env node
2
- import { cleanup, commandMap, generateFiles, getCliCommand, getConfigFilePath, getPort } from './src/run';
3
- const command = process.argv[2];
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 start = async (port2, runPath2) => {
173
+ await upAll({
174
+ commandOptions: ["--build"],
175
+ composeOptions: ["-p", `port${port2}`],
176
+ cwd: runPath2,
177
+ log: true
178
+ });
179
+ await waitForServer(`http://localhost:${port2}`, 1e4);
180
+ await cli(port2, runPath2, "bash wp-config/configure-wp.sh");
181
+ };
182
+ var stop = async (port2, runPath2) => {
183
+ await downAll({
184
+ cwd: runPath2,
185
+ commandOptions: ["--volumes", "--remove-orphans"],
186
+ composeOptions: ["-p", `port${port2}`],
187
+ log: true
188
+ });
189
+ };
190
+ var cli = async (port2, runPath2, command2) => {
191
+ await run("cli", command2, {
192
+ cwd: runPath2,
193
+ commandOptions: ["--rm"],
194
+ composeOptions: ["-p", `port${port2}`],
195
+ log: true
196
+ });
197
+ };
198
+ var commandMap = {
199
+ start,
200
+ stop,
201
+ cli
202
+ };
203
+ var getWpConfigPath = (port2) => path2.resolve(process.cwd(), port2);
204
+ var generateFiles = (port2, configFilePath2) => {
205
+ const config = getConfig(configFilePath2);
206
+ const wpConfigPath = getWpConfigPath(port2);
207
+ if (!fs2.existsSync(wpConfigPath)) {
208
+ fs2.mkdirSync(wpConfigPath, { recursive: true });
209
+ }
210
+ const wpConfig = generateConfiguration(config, port2);
211
+ fs2.writeFileSync(path2.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
212
+ const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port2, wpConfigPath);
213
+ const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
214
+ const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
215
+ const hash = createHash("sha256");
216
+ hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
217
+ const runPath2 = path2.resolve(os.tmpdir(), `${hash.digest("hex")}`);
218
+ if (!fs2.existsSync(runPath2)) {
219
+ fs2.mkdirSync(runPath2);
220
+ }
221
+ console.log(`writing files to run path: ${runPath2}`);
222
+ fs2.writeFileSync(path2.resolve(runPath2, "docker-compose.yml"), dockerComposeYmlTemplate);
223
+ fs2.writeFileSync(path2.resolve(runPath2, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
224
+ fs2.writeFileSync(path2.resolve(runPath2, "CLI.Dockerfile"), cliDockerfileTemplate);
225
+ return runPath2;
226
+ };
227
+ var getArgument = (argumentKey, processArgs) => {
228
+ for (let i = 3; i < processArgs.length; i++) {
229
+ const argument = processArgs[i];
230
+ if (argument.startsWith(`${argumentKey}=`)) {
231
+ return argument.substring(argumentKey.length + 1);
232
+ }
233
+ }
234
+ return void 0;
235
+ };
236
+ var getConfigFilePath = (processArgs) => {
237
+ return path2.resolve(getArgument("config", processArgs));
238
+ };
239
+ var getCliCommand = (processArgs) => {
240
+ return getArgument("command", processArgs);
241
+ };
242
+ var getPort = (processArgs) => {
243
+ return getArgument("port", processArgs) || "8888";
244
+ };
245
+ var cleanup = (port2, runPath2) => {
246
+ fs2.rmSync(getWpConfigPath(port2), { recursive: true, force: true });
247
+ fs2.rmSync(runPath2, { recursive: true, force: true });
248
+ };
249
+
250
+ // index.ts
251
+ var command = process.argv[2];
4
252
  if (!commandMap[command]) {
5
- console.log(`Valid commands: ${Object.keys(commandMap).join(', ')}. You used ${command}`);
253
+ console.log(`Valid commands: ${Object.keys(commandMap).join(", ")}. You used ${command}`);
6
254
  }
7
- const port = getPort(process.argv);
8
- const configFilePath = getConfigFilePath(process.argv);
9
- const runPath = generateFiles(port, configFilePath);
10
- const cliCommand = getCliCommand(process.argv);
255
+ var port = getPort(process.argv);
256
+ var configFilePath = getConfigFilePath(process.argv);
257
+ var runPath = generateFiles(port, configFilePath);
258
+ var cliCommand = getCliCommand(process.argv);
11
259
  try {
12
- await commandMap[command](port, runPath, cliCommand);
13
- }
14
- finally {
15
- cleanup(port, runPath);
260
+ await commandMap[command](port, runPath, cliCommand);
261
+ } finally {
262
+ cleanup(port, runPath);
16
263
  }
264
+ export {
265
+ cli,
266
+ start,
267
+ stop
268
+ };
269
+ //# sourceMappingURL=index.js.map
package/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import {cleanup, commandMap, generateFiles, getCliCommand, getConfigFilePath, getPort} from './src/run';
4
+ export {start, stop, cli} from './src/run';
4
5
 
5
6
  const command = process.argv[ 2 ];
6
7
  if ( ! commandMap[ command ] ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/wp-lite-env",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "private": false,
5
5
  "description": "A simple, lightweight, docker-based WordPress environment",
6
6
  "main": "dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "wp-lite-env": "dist/index.js"
11
11
  },
12
12
  "scripts": {
13
- "build": "tsc",
13
+ "build": "tsup --config=./tsup.build.ts",
14
+ "dev": "tsup --config=./tsup.dev.ts",
14
15
  "lint": "eslint",
15
16
  "release": "npm run build && changeset publish",
16
17
  "test": "jest --coverage=true"
@@ -40,6 +41,7 @@
40
41
  "eslint": "~9.14.0",
41
42
  "jest": "^29.7.0",
42
43
  "ts-jest": "^29.2.5",
44
+ "tsup": "^8.3.5",
43
45
  "typescript": "^5.6.3",
44
46
  "typescript-eslint": "^8.14.0"
45
47
  }
package/src/run.ts CHANGED
@@ -50,7 +50,7 @@ export const stop = async ( port: string, runPath: string ) => {
50
50
  } );
51
51
  };
52
52
 
53
- const cli = async ( port: string, runPath: string, command: string ) => {
53
+ export const cli = async ( port: string, runPath: string, command: string ) => {
54
54
  await run( 'cli', command, {
55
55
  cwd: runPath,
56
56
  commandOptions: [ '--rm' ],
package/tsup.build.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig( {
4
+ entry: [ './index.ts' ],
5
+ clean: true,
6
+ format: [ 'esm' ],
7
+ sourcemap: true,
8
+ dts: true,
9
+ } );
package/tsup.dev.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig( {
4
+ entry: [ './index.ts' ],
5
+ clean: true,
6
+ format: [ 'esm' ],
7
+ sourcemap: true,
8
+ watch: true,
9
+ } );
package/dist/package.json DELETED
@@ -1,46 +0,0 @@
1
- {
2
- "name": "@elementor/wp-lite-env",
3
- "version": "0.0.10",
4
- "private": false,
5
- "description": "A simple, lightweight, docker-based WordPress environment",
6
- "main": "dist/index.js",
7
- "type": "module",
8
- "types": "dist/index.d.ts",
9
- "bin": {
10
- "wp-lite-env": "dist/index.js"
11
- },
12
- "scripts": {
13
- "build": "tsc",
14
- "lint": "eslint",
15
- "release": "npm run build && changeset publish",
16
- "test": "jest --coverage=true"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/elementor/wp-lite-env.git"
21
- },
22
- "publishConfig": {
23
- "access": "public"
24
- },
25
- "author": "Elementor Team",
26
- "license": "ISC",
27
- "bugs": {
28
- "url": "https://github.com/elementor/wp-lite-env/issues"
29
- },
30
- "homepage": "https://github.com/elementor/wp-lite-env#readme",
31
- "dependencies": {
32
- "docker-compose": "^1.1.0"
33
- },
34
- "devDependencies": {
35
- "@changesets/cli": "^2.27.9",
36
- "@eslint/js": "^9.15.0",
37
- "@jest/globals": "^29.7.0",
38
- "@types/eslint__js": "^8.42.3",
39
- "@types/node": "^22.9.0",
40
- "eslint": "~9.14.0",
41
- "jest": "^29.7.0",
42
- "ts-jest": "^29.2.5",
43
- "typescript": "^5.6.3",
44
- "typescript-eslint": "^8.14.0"
45
- }
46
- }
@@ -1,16 +0,0 @@
1
- export type Config = {
2
- core?: string;
3
- phpVersion?: string;
4
- plugins?: {
5
- [key: string]: string;
6
- };
7
- themes?: {
8
- [key: string]: string;
9
- };
10
- mappings?: {
11
- [key: string]: string;
12
- };
13
- config?: Record<string, string | boolean>;
14
- };
15
- export declare const getConfig: (configFilePath?: string) => Config;
16
- //# sourceMappingURL=config.d.ts.map
@@ -1,23 +0,0 @@
1
- import fs from 'fs';
2
- export const getConfig = (configFilePath) => {
3
- let configFile = {};
4
- if (configFilePath) {
5
- configFile = JSON.parse(fs.readFileSync(configFilePath, 'utf8'));
6
- }
7
- const defaultConfig = {
8
- core: '6.7',
9
- phpVersion: '8.1',
10
- plugins: {},
11
- themes: {},
12
- mappings: {},
13
- config: {},
14
- };
15
- return {
16
- core: configFile.core || defaultConfig.core,
17
- phpVersion: configFile.phpVersion || defaultConfig.phpVersion,
18
- plugins: configFile.plugins || defaultConfig.plugins,
19
- themes: configFile.themes || defaultConfig.themes,
20
- mappings: configFile.mappings || defaultConfig.mappings,
21
- config: configFile.config || defaultConfig.config,
22
- };
23
- };
package/dist/src/run.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare const start: (port: string, runPath: string) => Promise<void>;
2
- export declare const stop: (port: string, runPath: string) => Promise<void>;
3
- export declare const commandMap: {
4
- [key: string]: ((port: string) => Promise<void>) | ((port: string, runPath: string, command: string) => Promise<void>);
5
- };
6
- export declare const generateFiles: (port: string, configFilePath: string) => string;
7
- export declare const getConfigFilePath: (processArgs: string[]) => string;
8
- export declare const getCliCommand: (processArgs: string[]) => string;
9
- export declare const getPort: (processArgs: string[]) => string;
10
- export declare const cleanup: (port: string, runPath: string) => void;
11
- //# sourceMappingURL=run.d.ts.map
package/dist/src/run.js DELETED
@@ -1,105 +0,0 @@
1
- import { downAll, run, upAll } from "docker-compose";
2
- import path from "path";
3
- import { getConfig } from "./config";
4
- import fs from "fs";
5
- import { generateCliDockerfileTemplate, generateConfiguration, generateDockerComposeYmlTemplate, generateWordPressDockerfileTemplate } from "./templates";
6
- import { createHash } from "crypto";
7
- import os from "node:os";
8
- const waitForServer = async (url, timeoutMs) => {
9
- const startTime = Date.now();
10
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
11
- while (startTime + timeoutMs > Date.now()) {
12
- try {
13
- const response = await fetch(url);
14
- if (response.ok && (200 === response.status || 302 === response.status)) {
15
- return true;
16
- }
17
- }
18
- catch (e) { // eslint-disable-line @typescript-eslint/no-unused-vars
19
- // Ignore
20
- }
21
- finally {
22
- await sleep(100);
23
- }
24
- }
25
- return false;
26
- };
27
- export const start = async (port, runPath) => {
28
- await upAll({
29
- commandOptions: ['--build'],
30
- composeOptions: ['-p', `port${port}`],
31
- cwd: runPath,
32
- log: true,
33
- });
34
- await waitForServer(`http://localhost:${port}`, 10000);
35
- await cli(port, runPath, 'bash wp-config/configure-wp.sh');
36
- };
37
- export const stop = async (port, runPath) => {
38
- await downAll({
39
- cwd: runPath,
40
- commandOptions: ['--volumes', '--remove-orphans'],
41
- composeOptions: ['-p', `port${port}`],
42
- log: true,
43
- });
44
- };
45
- const cli = async (port, runPath, command) => {
46
- await run('cli', command, {
47
- cwd: runPath,
48
- commandOptions: ['--rm'],
49
- composeOptions: ['-p', `port${port}`],
50
- log: true,
51
- });
52
- };
53
- export const commandMap = {
54
- start,
55
- stop,
56
- cli,
57
- };
58
- const getWpConfigPath = (port) => path.resolve(process.cwd(), port);
59
- export const generateFiles = (port, configFilePath) => {
60
- const config = getConfig(configFilePath);
61
- // Using a local path since Docker Compose cannot access /tmp
62
- // See: https://github.com/docker/compose/issues/1153
63
- const wpConfigPath = getWpConfigPath(port);
64
- if (!fs.existsSync(wpConfigPath)) {
65
- fs.mkdirSync(wpConfigPath, { recursive: true });
66
- }
67
- const wpConfig = generateConfiguration(config, port);
68
- fs.writeFileSync(path.resolve(wpConfigPath, 'configure-wp.sh'), wpConfig);
69
- const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port, wpConfigPath);
70
- const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
71
- const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
72
- const hash = createHash('sha256');
73
- hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port);
74
- const runPath = path.resolve(os.tmpdir(), `${hash.digest('hex')}`);
75
- if (!fs.existsSync(runPath)) {
76
- fs.mkdirSync(runPath);
77
- }
78
- console.log(`writing files to run path: ${runPath}`);
79
- fs.writeFileSync(path.resolve(runPath, 'docker-compose.yml'), dockerComposeYmlTemplate);
80
- fs.writeFileSync(path.resolve(runPath, 'WordPress.Dockerfile'), wordPressDockerfileTemplate);
81
- fs.writeFileSync(path.resolve(runPath, 'CLI.Dockerfile'), cliDockerfileTemplate);
82
- return runPath;
83
- };
84
- const getArgument = (argumentKey, processArgs) => {
85
- for (let i = 3; i < processArgs.length; i++) {
86
- const argument = processArgs[i];
87
- if (argument.startsWith(`${argumentKey}=`)) {
88
- return argument.substring(argumentKey.length + 1);
89
- }
90
- }
91
- return undefined;
92
- };
93
- export const getConfigFilePath = (processArgs) => {
94
- return path.resolve(getArgument('config', processArgs));
95
- };
96
- export const getCliCommand = (processArgs) => {
97
- return getArgument('command', processArgs);
98
- };
99
- export const getPort = (processArgs) => {
100
- return getArgument('port', processArgs) || '8888';
101
- };
102
- export const cleanup = (port, runPath) => {
103
- fs.rmSync(getWpConfigPath(port), { recursive: true, force: true });
104
- fs.rmSync(runPath, { recursive: true, force: true });
105
- };
@@ -1,6 +0,0 @@
1
- import { Config } from './config';
2
- export declare const generateDockerComposeYmlTemplate: (config: Config, basePath: string, port: string, configPath: string) => string;
3
- export declare const generateWordPressDockerfileTemplate: (config: Config) => string;
4
- export declare const generateCliDockerfileTemplate: (config: Config) => string;
5
- export declare const generateConfiguration: (config: Config, port: string) => string;
6
- //# sourceMappingURL=templates.d.ts.map
@@ -1,111 +0,0 @@
1
- import path from 'path';
2
- export const generateDockerComposeYmlTemplate = (config, basePath, port, configPath) => {
3
- const mappingsStringArray = Object.keys(config.mappings).map((key) => {
4
- const value = config.mappings[key];
5
- return ` - >-
6
- ${path.resolve(basePath, value)}:/var/www/html/${key}\n`;
7
- });
8
- const pluginsStringArray = Object.keys(config.plugins).map((key) => {
9
- const value = config.plugins[key];
10
- return ` - >-
11
- ${path.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}\n`;
12
- });
13
- const themesStringArray = Object.keys(config.themes).map((key) => {
14
- const value = config.themes[key];
15
- return ` - >-
16
- ${path.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}\n`;
17
- });
18
- const wpContent = ` - >-
19
- wpcontent:/var/www/html\n`;
20
- const wpConfig = ` - >-
21
- ${configPath}:/var/www/html/wp-config\n`;
22
- const volumes = mappingsStringArray.concat(pluginsStringArray).concat(themesStringArray).concat([wpContent, wpConfig]).join('');
23
- return `services:
24
- mysql:
25
- image: 'mariadb:lts'
26
- ports:
27
- - '\${WP_ENV_MYSQL_PORT:-}:3306'
28
- environment:
29
- MYSQL_ROOT_HOST: '%'
30
- MYSQL_ROOT_PASSWORD: password
31
- MYSQL_DATABASE: wordpress
32
- volumes:
33
- - 'mysql:/var/lib/mysql'
34
- wordpress:
35
- depends_on:
36
- - mysql
37
- build:
38
- context: .
39
- dockerfile: WordPress.Dockerfile
40
- no_cache: true
41
- args: &ref_0
42
- HOST_USERNAME: yotams
43
- HOST_UID: '502'
44
- HOST_GID: '20'
45
- ports:
46
- - '\${WP_ENV_PORT:-${port}}:80'
47
- environment:
48
- APACHE_RUN_USER: '#502'
49
- APACHE_RUN_GROUP: '#20'
50
- WORDPRESS_DB_USER: root
51
- WORDPRESS_DB_PASSWORD: password
52
- WORDPRESS_DB_NAME: wordpress
53
- volumes: &ref_1
54
- ${volumes}
55
- extra_hosts:
56
- - 'host.docker.internal:host-gateway'
57
- cli:
58
- depends_on:
59
- - wordpress
60
- build:
61
- context: .
62
- dockerfile: CLI.Dockerfile
63
- args: *ref_0
64
- volumes: *ref_1
65
- user: '502:20'
66
- environment:
67
- WORDPRESS_DB_USER: root
68
- WORDPRESS_DB_PASSWORD: password
69
- WORDPRESS_DB_NAME: wordpress
70
- extra_hosts:
71
- - 'host.docker.internal:host-gateway'
72
- volumes:
73
- mysql: {}
74
- wpcontent: {}
75
- `;
76
- };
77
- export const generateWordPressDockerfileTemplate = (config) => {
78
- return `FROM wordpress:${config.core}-php${config.phpVersion}
79
- ARG HOST_USERNAME
80
- ARG HOST_UID
81
- ARG HOST_GID
82
- # When the IDs are already in use we can still safely move on.
83
- RUN groupadd -o -g $HOST_GID $HOST_USERNAME || true
84
- RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
85
- `;
86
- };
87
- export const generateCliDockerfileTemplate = (config) => {
88
- return `FROM wordpress:cli-php${config.phpVersion}
89
- ARG HOST_USERNAME
90
- ARG HOST_UID
91
- ARG HOST_GID
92
- # When the IDs are already in use we can still safely move on.
93
- RUN addgroup -g $HOST_GID $HOST_USERNAME || true
94
- RUN useradd -mlo -u $HOST_UID -g $HOST_GID $HOST_USERNAME || true
95
- # RUN adduser -h /home/$HOST_USERNAME -G $( getent group $HOST_GID | cut -d: -f1 ) -u $HOST_UID $HOST_USERNAME || true
96
-
97
- # Have the container sleep infinitely to keep it alive for us to run commands on it.
98
- CMD [ "/bin/sh", "-c", "while true; do sleep 2073600; done" ]
99
- `;
100
- };
101
- export const generateConfiguration = (config, port) => {
102
- const header = `#!/bin/bash
103
- set -eox pipefail
104
- `;
105
- const configStringArray = Object.keys(config.config).map((key) => {
106
- const value = config.config[key];
107
- return `wp config set ${key} ${value} --raw`;
108
- });
109
- const wpCoreInstall = `wp core install --url="http://localhost:${port}" --title="test" --admin_user=admin --admin_password=password --admin_email=wordpress@example.com --skip-email`;
110
- return [header, wpCoreInstall].concat(configStringArray).join('\n');
111
- };