@elementor/wp-lite-env 0.0.17 → 0.0.19

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.
@@ -17,100 +17,108 @@ var getConfig = (configFilePath) => {
17
17
  mappings: {},
18
18
  config: {}
19
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
- };
20
+ return Object.assign({}, defaultConfig, configFile);
28
21
  };
29
22
 
30
23
  // src/run.ts
31
- import fs2 from "fs";
24
+ import fs2 from "fs/promises";
32
25
 
33
26
  // src/templates.ts
34
27
  import path from "path";
35
- var generateDockerComposeYmlTemplate = (config, basePath, port, configPath) => {
28
+ import { dump } from "js-yaml";
29
+ var generateVolumeMapping = (basePath, configPath, config) => {
36
30
  const mappingsStringArray = Object.keys(config.mappings).map((key) => {
37
31
  const value = config.mappings[key];
38
- return ` - >-
39
- ${path.resolve(basePath, value)}:/var/www/html/${key}
40
- `;
32
+ return `${path.resolve(basePath, value)}:/var/www/html/${key}`;
41
33
  });
42
34
  const pluginsStringArray = Object.keys(config.plugins).map((key) => {
43
35
  const value = config.plugins[key];
44
- return ` - >-
45
- ${path.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}
46
- `;
36
+ return `${path.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}`;
47
37
  });
48
38
  const themesStringArray = Object.keys(config.themes).map((key) => {
49
39
  const value = config.themes[key];
50
- return ` - >-
51
- ${path.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}
52
- `;
40
+ return `${path.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}`;
53
41
  });
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
- `;
42
+ const wpContent = `wpcontent:/var/www/html`;
43
+ const wpConfig = `${configPath}:/var/www/html/wp-config`;
44
+ return mappingsStringArray.concat(pluginsStringArray).concat(themesStringArray).concat([wpContent, wpConfig]);
45
+ };
46
+ var generateDockerComposeYmlTemplate = (config, basePath, port, configPath) => {
47
+ const hostUid = "502";
48
+ const hostGid = "20";
49
+ const wordpressDbUser = "root";
50
+ const wordpressDbPassword = "password";
51
+ const wordpressDbName = "wordpress";
52
+ const args = {
53
+ HOST_USERNAME: "someuser",
54
+ HOST_UID: hostUid,
55
+ HOST_GID: hostGid
56
+ };
57
+ const volumes = generateVolumeMapping(basePath, configPath, config);
58
+ const compose = {
59
+ services: {
60
+ mysql: {
61
+ image: "mariadb:lts",
62
+ ports: [
63
+ "${WP_ENV_MYSQL_PORT:-}:3306"
64
+ ],
65
+ environment: {
66
+ MYSQL_ROOT_HOST: "%",
67
+ MYSQL_ROOT_PASSWORD: "password",
68
+ MYSQL_DATABASE: "wordpress"
69
+ },
70
+ volumes: [
71
+ "mysql:/var/lib/mysql"
72
+ ]
73
+ },
74
+ wordpress: {
75
+ depends_on: ["mysql"],
76
+ build: {
77
+ context: ".",
78
+ dockerfile: "WordPress.Dockerfile",
79
+ no_cache: true,
80
+ args
81
+ },
82
+ ports: [
83
+ `\${WP_ENV_PORT:-${port}}:80`
84
+ ],
85
+ environment: {
86
+ APACHE_RUN_USER: `#${hostUid}`,
87
+ APACHE_RUN_GROUP: `#${hostGid}`,
88
+ WORDPRESS_DB_USER: wordpressDbUser,
89
+ WORDPRESS_DB_PASSWORD: wordpressDbPassword,
90
+ WORDPRESS_DB_NAME: wordpressDbName
91
+ },
92
+ volumes,
93
+ extra_hosts: [
94
+ "host.docker.internal:host-gateway"
95
+ ]
96
+ },
97
+ cli: {
98
+ depends_on: ["wordpress"],
99
+ build: {
100
+ context: ".",
101
+ dockerfile: "CLI.Dockerfile",
102
+ args
103
+ },
104
+ volumes,
105
+ user: `${hostUid}:${hostGid}`,
106
+ environment: {
107
+ WORDPRESS_DB_USER: wordpressDbUser,
108
+ WORDPRESS_DB_PASSWORD: wordpressDbPassword,
109
+ WORDPRESS_DB_NAME: wordpressDbName
110
+ },
111
+ extra_hosts: [
112
+ "host.docker.internal:host-gateway"
113
+ ]
114
+ }
115
+ },
116
+ volumes: {
117
+ mysql: {},
118
+ wpcontent: {}
119
+ }
120
+ };
121
+ return dump(compose);
114
122
  };
115
123
  var generateWordPressDockerfileTemplate = (config) => {
116
124
  return `FROM wordpress:${config.core}-php${config.phpVersion}
@@ -152,25 +160,29 @@ set -eox pipefail
152
160
  import { createHash } from "crypto";
153
161
  import os from "node:os";
154
162
  var waitForServer = async (url, timeoutMs) => {
155
- const startTime = Date.now();
156
163
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
157
- while (startTime + timeoutMs > Date.now()) {
164
+ const pollEveryMs = 100;
165
+ let retries = timeoutMs / pollEveryMs;
166
+ while (retries > 0) {
158
167
  try {
159
168
  const response = await fetch(url);
160
- if (response.ok && (200 === response.status || 302 === response.status)) {
169
+ if (200 === response.status || 302 === response.status) {
161
170
  return true;
162
171
  }
163
172
  } catch (e) {
164
- console.warn(`Encountered an error while waiting for server to start: ${e.message}
173
+ if ("ECONNREFUSED" !== e.cause?.code) {
174
+ console.warn(`Encountered an error while waiting for server to start: ${e.message}
165
175
  Trying to reach server again.`);
176
+ }
166
177
  } finally {
167
- await sleep(100);
178
+ retries--;
168
179
  }
180
+ await sleep(pollEveryMs);
169
181
  }
170
182
  console.error(`Server did not start within ${timeoutMs}ms`);
171
183
  return false;
172
184
  };
173
- var getRunPath = (port) => path2.resolve(os.tmpdir(), port);
185
+ var getRunPath = (port) => path2.resolve(os.tmpdir(), `${port}`);
174
186
  var start = async (port) => {
175
187
  const runPath = getRunPath(port);
176
188
  await upAll({
@@ -190,7 +202,7 @@ var stop = async (port) => {
190
202
  composeOptions: ["-p", `port${port}`],
191
203
  log: true
192
204
  });
193
- cleanup(port);
205
+ await cleanup(port);
194
206
  };
195
207
  var cli = async (port, command) => {
196
208
  const runPath = getRunPath(port);
@@ -206,52 +218,30 @@ var commandMap = {
206
218
  stop,
207
219
  cli
208
220
  };
209
- var getWpConfigPath = (port) => path2.resolve(process.cwd(), port);
210
- var generateFiles = (port, configFilePath) => {
221
+ var getWpConfigPath = (port) => path2.resolve(process.cwd(), `${port}`);
222
+ var generateFiles = async (port, configFilePath) => {
211
223
  const config = getConfig(configFilePath);
212
224
  const wpConfigPath = getWpConfigPath(port);
213
- if (!fs2.existsSync(wpConfigPath)) {
214
- fs2.mkdirSync(wpConfigPath, { recursive: true });
215
- }
225
+ await fs2.mkdir(wpConfigPath, { recursive: true });
216
226
  const wpConfig = generateConfiguration(config, port);
217
- fs2.writeFileSync(path2.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
227
+ await fs2.writeFile(path2.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
218
228
  const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port, wpConfigPath);
219
229
  const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
220
230
  const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
221
231
  const hash = createHash("sha256");
222
232
  hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port);
223
233
  const runPath = getRunPath(port);
224
- if (!fs2.existsSync(runPath)) {
225
- fs2.mkdirSync(runPath);
226
- }
234
+ await fs2.mkdir(runPath, { recursive: true });
227
235
  console.log(`writing files to run path: ${runPath}`);
228
- fs2.writeFileSync(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
229
- fs2.writeFileSync(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
230
- fs2.writeFileSync(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
236
+ await fs2.writeFile(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
237
+ await fs2.writeFile(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
238
+ await fs2.writeFile(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
231
239
  return runPath;
232
240
  };
233
- var getArgument = (argumentKey, processArgs) => {
234
- for (let i = 3; i < processArgs.length; i++) {
235
- const argument = processArgs[i];
236
- if (argument.startsWith(`${argumentKey}=`)) {
237
- return argument.substring(argumentKey.length + 1);
238
- }
239
- }
240
- return void 0;
241
- };
242
- var getConfigFilePath = (processArgs) => {
243
- return path2.resolve(getArgument("config", processArgs));
244
- };
245
- var getCliCommand = (processArgs) => {
246
- return getArgument("command", processArgs);
247
- };
248
- var getPort = (processArgs) => {
249
- return getArgument("port", processArgs) || "8888";
250
- };
251
- var cleanup = (port) => {
241
+ var cleanup = async (port) => {
252
242
  const runPath = getRunPath(port);
253
- fs2.rmSync(getWpConfigPath(port), { recursive: true, force: true });
254
- fs2.rmSync(runPath, { recursive: true, force: true });
243
+ await fs2.rm(getWpConfigPath(port), { recursive: true, force: true });
244
+ await fs2.rm(runPath, { recursive: true, force: true });
255
245
  };
256
246
 
257
247
  export {
@@ -259,9 +249,6 @@ export {
259
249
  stop,
260
250
  cli,
261
251
  commandMap,
262
- generateFiles,
263
- getConfigFilePath,
264
- getCliCommand,
265
- getPort
252
+ generateFiles
266
253
  };
267
- //# sourceMappingURL=chunk-MP53H5K3.js.map
254
+ //# sourceMappingURL=chunk-WLKYS3XU.js.map
package/dist/index.cjs CHANGED
@@ -38,28 +38,37 @@ module.exports = __toCommonJS(src_exports);
38
38
  // src/run.ts
39
39
  var import_docker_compose = require("docker-compose");
40
40
  var import_path = __toESM(require("path"), 1);
41
- var import_fs = __toESM(require("fs"), 1);
41
+ var import_promises = __toESM(require("fs/promises"), 1);
42
+
43
+ // src/templates.ts
44
+ var import_js_yaml = require("js-yaml");
45
+
46
+ // src/run.ts
42
47
  var import_node_os = __toESM(require("os"), 1);
43
48
  var waitForServer = async (url, timeoutMs) => {
44
- const startTime = Date.now();
45
49
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
46
- while (startTime + timeoutMs > Date.now()) {
50
+ const pollEveryMs = 100;
51
+ let retries = timeoutMs / pollEveryMs;
52
+ while (retries > 0) {
47
53
  try {
48
54
  const response = await fetch(url);
49
- if (response.ok && (200 === response.status || 302 === response.status)) {
55
+ if (200 === response.status || 302 === response.status) {
50
56
  return true;
51
57
  }
52
58
  } catch (e) {
53
- console.warn(`Encountered an error while waiting for server to start: ${e.message}
59
+ if ("ECONNREFUSED" !== e.cause?.code) {
60
+ console.warn(`Encountered an error while waiting for server to start: ${e.message}
54
61
  Trying to reach server again.`);
62
+ }
55
63
  } finally {
56
- await sleep(100);
64
+ retries--;
57
65
  }
66
+ await sleep(pollEveryMs);
58
67
  }
59
68
  console.error(`Server did not start within ${timeoutMs}ms`);
60
69
  return false;
61
70
  };
62
- var getRunPath = (port) => import_path.default.resolve(import_node_os.default.tmpdir(), port);
71
+ var getRunPath = (port) => import_path.default.resolve(import_node_os.default.tmpdir(), `${port}`);
63
72
  var start = async (port) => {
64
73
  const runPath = getRunPath(port);
65
74
  await (0, import_docker_compose.upAll)({
@@ -79,7 +88,7 @@ var stop = async (port) => {
79
88
  composeOptions: ["-p", `port${port}`],
80
89
  log: true
81
90
  });
82
- cleanup(port);
91
+ await cleanup(port);
83
92
  };
84
93
  var cli = async (port, command) => {
85
94
  const runPath = getRunPath(port);
@@ -90,11 +99,11 @@ var cli = async (port, command) => {
90
99
  log: true
91
100
  });
92
101
  };
93
- var getWpConfigPath = (port) => import_path.default.resolve(process.cwd(), port);
94
- var cleanup = (port) => {
102
+ var getWpConfigPath = (port) => import_path.default.resolve(process.cwd(), `${port}`);
103
+ var cleanup = async (port) => {
95
104
  const runPath = getRunPath(port);
96
- import_fs.default.rmSync(getWpConfigPath(port), { recursive: true, force: true });
97
- import_fs.default.rmSync(runPath, { recursive: true, force: true });
105
+ await import_promises.default.rm(getWpConfigPath(port), { recursive: true, force: true });
106
+ await import_promises.default.rm(runPath, { recursive: true, force: true });
98
107
  };
99
108
  // Annotate the CommonJS export names for ESM import in node:
100
109
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- declare const start: (port: string) => Promise<void>;
2
- declare const stop: (port: string) => Promise<void>;
3
- declare const cli: (port: string, command: string) => Promise<void>;
1
+ declare const start: (port: number) => Promise<void>;
2
+ declare const stop: (port: number) => Promise<void>;
3
+ declare const cli: (port: number, command: string) => Promise<void>;
4
4
 
5
5
  export { cli, start, stop };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- declare const start: (port: string) => Promise<void>;
2
- declare const stop: (port: string) => Promise<void>;
3
- declare const cli: (port: string, command: string) => Promise<void>;
1
+ declare const start: (port: number) => Promise<void>;
2
+ declare const stop: (port: number) => Promise<void>;
3
+ declare const cli: (port: number, command: string) => Promise<void>;
4
4
 
5
5
  export { cli, start, stop };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  cli,
3
3
  start,
4
4
  stop
5
- } from "./chunk-MP53H5K3.js";
5
+ } from "./chunk-WLKYS3XU.js";
6
6
  export {
7
7
  cli,
8
8
  start,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/wp-lite-env",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "private": false,
5
5
  "description": "A simple, lightweight, docker-based WordPress environment",
6
6
  "main": "dist/index.cjs",
@@ -31,13 +31,17 @@
31
31
  },
32
32
  "homepage": "https://github.com/elementor/wp-lite-env#readme",
33
33
  "dependencies": {
34
- "docker-compose": "^1.1.0"
34
+ "command-line-args": "^6.0.1",
35
+ "docker-compose": "^1.1.0",
36
+ "js-yaml": "^4.1.0"
35
37
  },
36
38
  "devDependencies": {
37
39
  "@changesets/cli": "^2.27.9",
38
40
  "@eslint/js": "^9.15.0",
39
41
  "@jest/globals": "^29.7.0",
42
+ "@types/command-line-args": "^5.2.3",
40
43
  "@types/eslint__js": "^8.42.3",
44
+ "@types/js-yaml": "^4.0.9",
41
45
  "@types/node": "^22.10.0",
42
46
  "eslint": "~9.14.0",
43
47
  "jest": "^29.7.0",
package/src/bin.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import {commandMap, generateFiles, getCliCommand, getConfigFilePath, getPort} from './run';
3
+ import commandLineArgs from 'command-line-args';
4
+ import {commandMap, generateFiles} from './run';
4
5
 
5
- const command = process.argv[ 2 ];
6
- if ( ! commandMap[ command ] ) {
7
- console.log( `Valid commands: ${ Object.keys( commandMap ).join( ', ' ) }. You used ${ command }` );
8
- }
6
+ const cliOptionDefinitions = [
7
+ { name: 'cmd', type: String, defaultOption: true, description: 'The command to run. Can be one of "start", "stop" or "cli"' },
8
+ { name: 'config', type: String, description: "Path to the configuration file defining the WordPress environment." },
9
+ { name: 'port', type: Number, description: "Port to run the WordPress environment on" },
10
+ { name: 'command', type: String, defaultValue: '', description: "The command to run by the WP CLI" },
11
+ ];
12
+ const cliOptions = commandLineArgs(cliOptionDefinitions);
9
13
 
10
- const port = getPort( process.argv );
11
- const configFilePath = getConfigFilePath( process.argv )
12
- const cliCommand = getCliCommand( process.argv );
13
- generateFiles( port, configFilePath );
14
-
15
- commandMap[command](port, cliCommand);
14
+ const command = cliOptions.cmd;
15
+ const port = cliOptions.port;
16
+ const configFilePath = cliOptions.config;
17
+ const cliCommand = cliOptions.command;
18
+ generateFiles( port, configFilePath ).then( () => commandMap[command](port, cliCommand) );
package/src/config.ts CHANGED
@@ -24,12 +24,5 @@ export const getConfig = ( configFilePath?: string ): Config => {
24
24
  config: {},
25
25
  };
26
26
 
27
- return {
28
- core: configFile.core || defaultConfig.core,
29
- phpVersion: configFile.phpVersion || defaultConfig.phpVersion,
30
- plugins: configFile.plugins || defaultConfig.plugins,
31
- themes: configFile.themes || defaultConfig.themes,
32
- mappings: configFile.mappings || defaultConfig.mappings,
33
- config: configFile.config || defaultConfig.config,
34
- };
27
+ return Object.assign({}, defaultConfig, configFile);
35
28
  };
package/src/run.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {downAll, run, upAll} from "docker-compose";
2
2
  import path from "path";
3
3
  import {getConfig} from "./config";
4
- import fs from "fs";
4
+ import fs from "fs/promises";
5
5
  import {
6
6
  generateCliDockerfileTemplate,
7
7
  generateConfiguration,
@@ -12,28 +12,33 @@ import {createHash} from "crypto";
12
12
  import os from "node:os";
13
13
 
14
14
  const waitForServer = async ( url: string, timeoutMs: number ) => {
15
- const startTime = Date.now();
16
15
  const sleep = ( ms: number ) => new Promise( ( r ) => setTimeout( r, ms ) );
17
16
 
18
- while ( startTime + timeoutMs > Date.now() ) {
17
+ const pollEveryMs = 100;
18
+ let retries = timeoutMs / pollEveryMs;
19
+
20
+ while (retries > 0) {
19
21
  try {
20
22
  const response = await fetch( url );
21
- if ( response.ok && ( 200 === response.status || 302 === response.status ) ) {
23
+ if ( 200 === response.status || 302 === response.status ) {
22
24
  return true;
23
25
  }
24
26
  } catch ( e ) {
25
- console.warn( `Encountered an error while waiting for server to start: ${ e.message }\nTrying to reach server again.` );
27
+ if ( 'ECONNREFUSED' !== e.cause?.code ) {
28
+ console.warn( `Encountered an error while waiting for server to start: ${ e.message }\nTrying to reach server again.` );
29
+ }
26
30
  } finally {
27
- await sleep( 100 );
31
+ retries--;
28
32
  }
33
+ await sleep (pollEveryMs);
29
34
  }
30
35
  console.error( `Server did not start within ${ timeoutMs }ms` );
31
36
  return false;
32
37
  };
33
38
 
34
- const getRunPath = ( port: string ) => path.resolve( os.tmpdir(), port );
39
+ const getRunPath = ( port: number ) => path.resolve( os.tmpdir(), `${port}` );
35
40
 
36
- export const start = async ( port: string ) => {
41
+ export const start = async ( port: number ) => {
37
42
  const runPath = getRunPath( port );
38
43
  await upAll( {
39
44
  commandOptions: [ '--build' ],
@@ -45,7 +50,7 @@ export const start = async ( port: string ) => {
45
50
  await cli( port, 'bash wp-config/configure-wp.sh' );
46
51
  };
47
52
 
48
- export const stop = async ( port: string ) => {
53
+ export const stop = async ( port: number ) => {
49
54
  const runPath = getRunPath( port );
50
55
  await downAll( {
51
56
  cwd: runPath,
@@ -53,10 +58,10 @@ export const stop = async ( port: string ) => {
53
58
  composeOptions: [ '-p', `port${ port }` ],
54
59
  log: true,
55
60
  } );
56
- cleanup( port );
61
+ await cleanup( port );
57
62
  };
58
63
 
59
- export const cli = async ( port: string, command: string ) => {
64
+ export const cli = async ( port: number, command: string ) => {
60
65
  const runPath = getRunPath( port );
61
66
  await run( 'cli', command, {
62
67
  cwd: runPath,
@@ -66,25 +71,23 @@ export const cli = async ( port: string, command: string ) => {
66
71
  } );
67
72
  };
68
73
 
69
- export const commandMap: { [key: string]: ( ( port: string ) => Promise<void> ) | ( ( port: string, command: string ) => Promise<void> ) } = {
74
+ export const commandMap: { [key: string]: ( ( port: number ) => Promise<void> ) | ( ( port: number, command: string ) => Promise<void> ) } = {
70
75
  start,
71
76
  stop,
72
77
  cli,
73
78
  };
74
79
 
75
- const getWpConfigPath = ( port: string ) => path.resolve( process.cwd(), port );
80
+ const getWpConfigPath = ( port: number ) => path.resolve( process.cwd(), `${port}` );
76
81
 
77
- export const generateFiles = ( port: string, configFilePath: string ) => {
82
+ export const generateFiles = async ( port: number, configFilePath: string ) => {
78
83
  const config = getConfig( configFilePath );
79
84
 
80
85
  // Using a local path since Docker Compose cannot access /tmp
81
86
  // See: https://github.com/docker/compose/issues/1153
82
87
  const wpConfigPath = getWpConfigPath( port );
83
- if ( ! fs.existsSync( wpConfigPath ) ) {
84
- fs.mkdirSync( wpConfigPath, { recursive: true } );
85
- }
88
+ await fs.mkdir( wpConfigPath, { recursive: true } );
86
89
  const wpConfig = generateConfiguration( config, port );
87
- fs.writeFileSync( path.resolve( wpConfigPath, 'configure-wp.sh' ), wpConfig );
90
+ await fs.writeFile( path.resolve( wpConfigPath, 'configure-wp.sh' ), wpConfig );
88
91
 
89
92
  const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate( config, process.cwd(), port, wpConfigPath );
90
93
  const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate( config );
@@ -92,14 +95,12 @@ export const generateFiles = ( port: string, configFilePath: string ) => {
92
95
  const hash = createHash( 'sha256' );
93
96
  hash.update( dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port );
94
97
  const runPath = getRunPath( port );
95
- if ( ! fs.existsSync( runPath ) ) {
96
- fs.mkdirSync( runPath );
97
- }
98
+ await fs.mkdir( runPath, { recursive: true } );
98
99
 
99
100
  console.log( `writing files to run path: ${ runPath }` );
100
- fs.writeFileSync( path.resolve( runPath, 'docker-compose.yml' ), dockerComposeYmlTemplate );
101
- fs.writeFileSync( path.resolve( runPath, 'WordPress.Dockerfile' ), wordPressDockerfileTemplate );
102
- fs.writeFileSync( path.resolve( runPath, 'CLI.Dockerfile' ), cliDockerfileTemplate );
101
+ await fs.writeFile( path.resolve( runPath, 'docker-compose.yml' ), dockerComposeYmlTemplate );
102
+ await fs.writeFile( path.resolve( runPath, 'WordPress.Dockerfile' ), wordPressDockerfileTemplate );
103
+ await fs.writeFile( path.resolve( runPath, 'CLI.Dockerfile' ), cliDockerfileTemplate );
103
104
 
104
105
  return runPath;
105
106
  };
@@ -118,16 +119,8 @@ export const getConfigFilePath = ( processArgs: string[] ) => {
118
119
  return path.resolve(getArgument( 'config', processArgs ));
119
120
  };
120
121
 
121
- export const getCliCommand = ( processArgs: string[] ) => {
122
- return getArgument( 'command', processArgs );
123
- };
124
-
125
- export const getPort = ( processArgs: string[] ) => {
126
- return getArgument( 'port', processArgs ) || '8888';
127
- };
128
-
129
- const cleanup = ( port: string ) => {
122
+ const cleanup = async ( port: number ) => {
130
123
  const runPath = getRunPath( port );
131
- fs.rmSync( getWpConfigPath( port ), { recursive: true, force: true } );
132
- fs.rmSync( runPath, { recursive: true, force: true } );
124
+ await fs.rm( getWpConfigPath( port ), { recursive: true, force: true } );
125
+ await fs.rm( runPath, { recursive: true, force: true } );
133
126
  }