@elementor/wp-lite-env 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # wp-lite-env
2
2
 
3
+ ## 0.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 7735ac3: use fs/promises
8
+ - 3ae029a: use Object.assign to set default configuration values
9
+ - 82d3000: use js-yaml to generate docker-compose.yml
10
+ - b733e44: use command-line-args
11
+ - cb25ce7: force dir creation
12
+ - efe3327: refactor waitForServer
13
+
14
+ ## 0.0.17
15
+
16
+ ### Patch Changes
17
+
18
+ - 34f7b7c: code review fixes
19
+ - a021f2d: code review fixes
20
+
3
21
  ## 0.0.16
4
22
 
5
23
  ### Patch Changes
@@ -3,15 +3,15 @@
3
3
  exports[`templates compose file generation snapshot test 1`] = `
4
4
  "services:
5
5
  mysql:
6
- image: 'mariadb:lts'
6
+ image: mariadb:lts
7
7
  ports:
8
- - '\${WP_ENV_MYSQL_PORT:-}:3306'
8
+ - \${WP_ENV_MYSQL_PORT:-}:3306
9
9
  environment:
10
10
  MYSQL_ROOT_HOST: '%'
11
11
  MYSQL_ROOT_PASSWORD: password
12
12
  MYSQL_DATABASE: wordpress
13
13
  volumes:
14
- - 'mysql:/var/lib/mysql'
14
+ - mysql:/var/lib/mysql
15
15
  wordpress:
16
16
  depends_on:
17
17
  - mysql
@@ -20,11 +20,11 @@ exports[`templates compose file generation snapshot test 1`] = `
20
20
  dockerfile: WordPress.Dockerfile
21
21
  no_cache: true
22
22
  args: &ref_0
23
- HOST_USERNAME: yotams
23
+ HOST_USERNAME: someuser
24
24
  HOST_UID: '502'
25
25
  HOST_GID: '20'
26
26
  ports:
27
- - '\${WP_ENV_PORT:-1234}:80'
27
+ - \${WP_ENV_PORT:-1234}:80
28
28
  environment:
29
29
  APACHE_RUN_USER: '#502'
30
30
  APACHE_RUN_GROUP: '#20'
@@ -32,13 +32,10 @@ exports[`templates compose file generation snapshot test 1`] = `
32
32
  WORDPRESS_DB_PASSWORD: password
33
33
  WORDPRESS_DB_NAME: wordpress
34
34
  volumes: &ref_1
35
- - >-
36
- wpcontent:/var/www/html
37
- - >-
38
- /some/wp-config/path:/var/www/html/wp-config
39
-
35
+ - wpcontent:/var/www/html
36
+ - /some/wp-config/path:/var/www/html/wp-config
40
37
  extra_hosts:
41
- - 'host.docker.internal:host-gateway'
38
+ - host.docker.internal:host-gateway
42
39
  cli:
43
40
  depends_on:
44
41
  - wordpress
@@ -53,7 +50,7 @@ exports[`templates compose file generation snapshot test 1`] = `
53
50
  WORDPRESS_DB_PASSWORD: password
54
51
  WORDPRESS_DB_NAME: wordpress
55
52
  extra_hosts:
56
- - 'host.docker.internal:host-gateway'
53
+ - host.docker.internal:host-gateway
57
54
  volumes:
58
55
  mysql: {}
59
56
  wpcontent: {}
@@ -8,13 +8,13 @@ describe('config', () => {
8
8
  test('defaults', () => {
9
9
  (fs.readFileSync as unknown as MockInstance).mockReturnValueOnce(JSON.stringify({"some" : "data"}));
10
10
  const config = getConfig('some/path');
11
- expect(config).toEqual({
11
+ expect(config).toEqual(expect.objectContaining({
12
12
  core: '6.7',
13
13
  phpVersion: '8.1',
14
14
  plugins: {},
15
15
  themes: {},
16
16
  mappings: {},
17
17
  config: {},
18
- });
18
+ }));
19
19
  });
20
20
  });
package/__tests__/e2e.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import {afterEach, beforeAll, describe, expect, test} from "@jest/globals";
2
2
  import {generateFiles, getConfigFilePath, start, stop} from "../src/run";
3
3
 
4
- const port = '1234';
4
+ const port = 1234;
5
5
 
6
6
  describe('end to end tests', () => {
7
7
  beforeAll(async () => {
8
- generateFiles(port, getConfigFilePath(['', '', '', 'config=./tests/.wp-lite-env.json']));
8
+ await generateFiles(port, getConfigFilePath(['', '', '', 'config=./__tests__/.wp-lite-env.json']));
9
9
  })
10
10
  afterEach(async () => {
11
11
  await stop(port);
@@ -30,7 +30,7 @@ describe('templates', () => {
30
30
  "WP_DEBUG": false
31
31
  }
32
32
  };
33
- const configTemplate = generateConfiguration( config, '1234' );
33
+ const configTemplate = generateConfiguration( config, 1234 );
34
34
  expect(configTemplate).toMatchSnapshot();
35
35
  });
36
36
  });
@@ -42,7 +42,7 @@ describe('templates', () => {
42
42
  plugins: {},
43
43
  themes: {},
44
44
  }
45
- const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', '1234', '/some/wp-config/path' );
45
+ const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', 1234, '/some/wp-config/path' );
46
46
  expect(composeYml).toMatchSnapshot();
47
47
  });
48
48
  test('mappings are mounted correctly', () => {
@@ -55,7 +55,7 @@ describe('templates', () => {
55
55
  themes: {},
56
56
  }
57
57
  const basePath = '/some/base/path';
58
- const composeYml = generateDockerComposeYmlTemplate( config, basePath, '1234', '/some/wp-config/path' );
58
+ const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
59
59
  expect(composeYml).toMatch(new RegExp(`${basePath}/some/container/path:/var/www/html/some/host/path`));
60
60
  expect(composeYml).toMatch(new RegExp(`${basePath}/some/other/container/path:/var/www/html/some/other/host/path`));
61
61
  });
@@ -70,7 +70,7 @@ describe('templates', () => {
70
70
  themes: {},
71
71
  }
72
72
  const basePath = '/some/base/path';
73
- const composeYml = generateDockerComposeYmlTemplate( config, basePath, '1234', '/some/wp-config/path' );
73
+ const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
74
74
  expect(composeYml).toMatch(new RegExp(`/some/base/some/plugin/path:/var/www/html/wp-content/plugins/plugin1`));
75
75
  expect(composeYml).toMatch(new RegExp(`/some/base/some/other/plugin/path:/var/www/html/wp-content/plugins/plugin2`));
76
76
  });
@@ -84,7 +84,7 @@ describe('templates', () => {
84
84
  },
85
85
  }
86
86
  const basePath = '/some/base/path';
87
- const composeYml = generateDockerComposeYmlTemplate( config, basePath, '1234', '/some/wp-config/path' );
87
+ const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
88
88
  expect(composeYml).toMatch(new RegExp(`/some/base/some/theme/path:/var/www/html/wp-content/themes/theme1`));
89
89
  expect(composeYml).toMatch(new RegExp(`/some/base/some/other/theme/path:/var/www/html/wp-content/themes/theme2`));
90
90
  });
@@ -96,7 +96,7 @@ describe('templates', () => {
96
96
  themes: {},
97
97
  }
98
98
  const basePath = '/some/base/path';
99
- const composeYml = generateDockerComposeYmlTemplate( config, basePath, '1234', '/some/wp-config/path' );
99
+ const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
100
100
  expect(composeYml).toMatch(new RegExp(`/some/wp-config/path:/var/www/html/wp-config`));
101
101
  });
102
102
  });
package/dist/bin.cjs CHANGED
@@ -22,6 +22,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
 
25
+ // src/bin.ts
26
+ var import_command_line_args = __toESM(require("command-line-args"), 1);
27
+
25
28
  // src/run.ts
26
29
  var import_docker_compose = require("docker-compose");
27
30
  var import_path2 = __toESM(require("path"), 1);
@@ -41,100 +44,108 @@ var getConfig = (configFilePath2) => {
41
44
  mappings: {},
42
45
  config: {}
43
46
  };
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
- };
47
+ return Object.assign({}, defaultConfig, configFile);
52
48
  };
53
49
 
54
50
  // src/run.ts
55
- var import_fs2 = __toESM(require("fs"), 1);
51
+ var import_promises = __toESM(require("fs/promises"), 1);
56
52
 
57
53
  // src/templates.ts
58
54
  var import_path = __toESM(require("path"), 1);
59
- var generateDockerComposeYmlTemplate = (config, basePath, port2, configPath) => {
55
+ var import_js_yaml = require("js-yaml");
56
+ var generateVolumeMapping = (basePath, configPath, config) => {
60
57
  const mappingsStringArray = Object.keys(config.mappings).map((key) => {
61
58
  const value = config.mappings[key];
62
- return ` - >-
63
- ${import_path.default.resolve(basePath, value)}:/var/www/html/${key}
64
- `;
59
+ return `${import_path.default.resolve(basePath, value)}:/var/www/html/${key}`;
65
60
  });
66
61
  const pluginsStringArray = Object.keys(config.plugins).map((key) => {
67
62
  const value = config.plugins[key];
68
- return ` - >-
69
- ${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}
70
- `;
63
+ return `${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/plugins/${key}`;
71
64
  });
72
65
  const themesStringArray = Object.keys(config.themes).map((key) => {
73
66
  const value = config.themes[key];
74
- return ` - >-
75
- ${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}
76
- `;
67
+ return `${import_path.default.resolve(basePath, value)}:/var/www/html/wp-content/themes/${key}`;
77
68
  });
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
- `;
69
+ const wpContent = `wpcontent:/var/www/html`;
70
+ const wpConfig = `${configPath}:/var/www/html/wp-config`;
71
+ return mappingsStringArray.concat(pluginsStringArray).concat(themesStringArray).concat([wpContent, wpConfig]);
72
+ };
73
+ var generateDockerComposeYmlTemplate = (config, basePath, port2, configPath) => {
74
+ const hostUid = "502";
75
+ const hostGid = "20";
76
+ const wordpressDbUser = "root";
77
+ const wordpressDbPassword = "password";
78
+ const wordpressDbName = "wordpress";
79
+ const args = {
80
+ HOST_USERNAME: "someuser",
81
+ HOST_UID: hostUid,
82
+ HOST_GID: hostGid
83
+ };
84
+ const volumes = generateVolumeMapping(basePath, configPath, config);
85
+ const compose = {
86
+ services: {
87
+ mysql: {
88
+ image: "mariadb:lts",
89
+ ports: [
90
+ "${WP_ENV_MYSQL_PORT:-}:3306"
91
+ ],
92
+ environment: {
93
+ MYSQL_ROOT_HOST: "%",
94
+ MYSQL_ROOT_PASSWORD: "password",
95
+ MYSQL_DATABASE: "wordpress"
96
+ },
97
+ volumes: [
98
+ "mysql:/var/lib/mysql"
99
+ ]
100
+ },
101
+ wordpress: {
102
+ depends_on: ["mysql"],
103
+ build: {
104
+ context: ".",
105
+ dockerfile: "WordPress.Dockerfile",
106
+ no_cache: true,
107
+ args
108
+ },
109
+ ports: [
110
+ `\${WP_ENV_PORT:-${port2}}:80`
111
+ ],
112
+ environment: {
113
+ APACHE_RUN_USER: `#${hostUid}`,
114
+ APACHE_RUN_GROUP: `#${hostGid}`,
115
+ WORDPRESS_DB_USER: wordpressDbUser,
116
+ WORDPRESS_DB_PASSWORD: wordpressDbPassword,
117
+ WORDPRESS_DB_NAME: wordpressDbName
118
+ },
119
+ volumes,
120
+ extra_hosts: [
121
+ "host.docker.internal:host-gateway"
122
+ ]
123
+ },
124
+ cli: {
125
+ depends_on: ["wordpress"],
126
+ build: {
127
+ context: ".",
128
+ dockerfile: "CLI.Dockerfile",
129
+ args
130
+ },
131
+ volumes,
132
+ user: `${hostUid}:${hostGid}`,
133
+ environment: {
134
+ WORDPRESS_DB_USER: wordpressDbUser,
135
+ WORDPRESS_DB_PASSWORD: wordpressDbPassword,
136
+ WORDPRESS_DB_NAME: wordpressDbName
137
+ },
138
+ extra_hosts: [
139
+ "host.docker.internal:host-gateway"
140
+ ]
141
+ }
142
+ },
143
+ volumes: {
144
+ mysql: {},
145
+ wpcontent: {}
146
+ }
147
+ };
148
+ return (0, import_js_yaml.dump)(compose);
138
149
  };
139
150
  var generateWordPressDockerfileTemplate = (config) => {
140
151
  return `FROM wordpress:${config.core}-php${config.phpVersion}
@@ -176,22 +187,28 @@ set -eox pipefail
176
187
  var import_crypto = require("crypto");
177
188
  var import_node_os = __toESM(require("os"), 1);
178
189
  var waitForServer = async (url, timeoutMs) => {
179
- const startTime = Date.now();
180
190
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
181
- while (startTime + timeoutMs > Date.now()) {
191
+ const pollEveryMs = 100;
192
+ let retries = timeoutMs / pollEveryMs;
193
+ while (retries > 0) {
182
194
  try {
183
195
  const response = await fetch(url);
184
- if (response.ok && (200 === response.status || 302 === response.status)) {
196
+ if (200 === response.status || 302 === response.status) {
185
197
  return true;
186
198
  }
187
199
  } catch (e) {
188
- } finally {
189
- await sleep(100);
200
+ if ("ECONNREFUSED" !== e.cause?.code) {
201
+ console.warn(`Encountered an error while waiting for server to start: ${e.message}
202
+ Trying to reach server again.`);
203
+ }
190
204
  }
205
+ await sleep(pollEveryMs);
206
+ retries--;
191
207
  }
208
+ console.error(`Server did not start within ${timeoutMs}ms`);
192
209
  return false;
193
210
  };
194
- var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), port2);
211
+ var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), `${port2}`);
195
212
  var start = async (port2) => {
196
213
  const runPath = getRunPath(port2);
197
214
  await (0, import_docker_compose.upAll)({
@@ -200,7 +217,7 @@ var start = async (port2) => {
200
217
  cwd: runPath,
201
218
  log: true
202
219
  });
203
- await waitForServer(`http://localhost:${port2}`, 1e4);
220
+ await waitForServer(`http://0.0.0.0:${port2}`, 1e4);
204
221
  await cli(port2, "bash wp-config/configure-wp.sh");
205
222
  };
206
223
  var stop = async (port2) => {
@@ -211,7 +228,7 @@ var stop = async (port2) => {
211
228
  composeOptions: ["-p", `port${port2}`],
212
229
  log: true
213
230
  });
214
- cleanup(port2);
231
+ await cleanup(port2);
215
232
  };
216
233
  var cli = async (port2, command2) => {
217
234
  const runPath = getRunPath(port2);
@@ -227,62 +244,43 @@ var commandMap = {
227
244
  stop,
228
245
  cli
229
246
  };
230
- var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), port2);
231
- var generateFiles = (port2, configFilePath2) => {
247
+ var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), `${port2}`);
248
+ var generateFiles = async (port2, configFilePath2) => {
232
249
  const config = getConfig(configFilePath2);
233
250
  const wpConfigPath = getWpConfigPath(port2);
234
- if (!import_fs2.default.existsSync(wpConfigPath)) {
235
- import_fs2.default.mkdirSync(wpConfigPath, { recursive: true });
236
- }
251
+ await import_promises.default.mkdir(wpConfigPath, { recursive: true });
237
252
  const wpConfig = generateConfiguration(config, port2);
238
- import_fs2.default.writeFileSync(import_path2.default.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
253
+ await import_promises.default.writeFile(import_path2.default.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
239
254
  const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port2, wpConfigPath);
240
255
  const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
241
256
  const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
242
257
  const hash = (0, import_crypto.createHash)("sha256");
243
258
  hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
244
259
  const runPath = getRunPath(port2);
245
- if (!import_fs2.default.existsSync(runPath)) {
246
- import_fs2.default.mkdirSync(runPath);
247
- }
260
+ await import_promises.default.mkdir(runPath, { recursive: true });
248
261
  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);
262
+ await import_promises.default.writeFile(import_path2.default.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
263
+ await import_promises.default.writeFile(import_path2.default.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
264
+ await import_promises.default.writeFile(import_path2.default.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
252
265
  return runPath;
253
266
  };
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) => {
267
+ var cleanup = async (port2) => {
273
268
  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 });
269
+ await import_promises.default.rm(getWpConfigPath(port2), { recursive: true, force: true });
270
+ await import_promises.default.rm(runPath, { recursive: true, force: true });
276
271
  };
277
272
 
278
273
  // 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);
274
+ var cliOptionDefinitions = [
275
+ { name: "cmd", type: String, defaultOption: true, description: 'The command to run. Can be one of "start", "stop" or "cli"' },
276
+ { name: "config", type: String, description: "Path to the configuration file defining the WordPress environment." },
277
+ { name: "port", type: Number, description: "Port to run the WordPress environment on" },
278
+ { name: "command", type: String, defaultValue: "", description: "The command to run by the WP CLI" }
279
+ ];
280
+ var cliOptions = (0, import_command_line_args.default)(cliOptionDefinitions);
281
+ var command = cliOptions.cmd;
282
+ var port = cliOptions.port;
283
+ var configFilePath = cliOptions.config;
284
+ var cliCommand = cliOptions.command;
285
+ generateFiles(port, configFilePath).then(() => commandMap[command](port, cliCommand));
288
286
  //# sourceMappingURL=bin.cjs.map
package/dist/bin.js CHANGED
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  commandMap,
4
- generateFiles,
5
- getCliCommand,
6
- getConfigFilePath,
7
- getPort
8
- } from "./chunk-UBXF6D42.js";
4
+ generateFiles
5
+ } from "./chunk-FNPCY3S6.js";
9
6
 
10
7
  // 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);
8
+ import commandLineArgs from "command-line-args";
9
+ var cliOptionDefinitions = [
10
+ { name: "cmd", type: String, defaultOption: true, description: 'The command to run. Can be one of "start", "stop" or "cli"' },
11
+ { name: "config", type: String, description: "Path to the configuration file defining the WordPress environment." },
12
+ { name: "port", type: Number, description: "Port to run the WordPress environment on" },
13
+ { name: "command", type: String, defaultValue: "", description: "The command to run by the WP CLI" }
14
+ ];
15
+ var cliOptions = commandLineArgs(cliOptionDefinitions);
16
+ var command = cliOptions.cmd;
17
+ var port = cliOptions.port;
18
+ var configFilePath = cliOptions.config;
19
+ var cliCommand = cliOptions.command;
20
+ generateFiles(port, configFilePath).then(() => commandMap[command](port, cliCommand));
20
21
  //# sourceMappingURL=bin.js.map