@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.
- package/.github/workflows/release.yml +1 -1
- package/.github/workflows/require-changesets.yml +1 -1
- package/CHANGELOG.md +19 -0
- package/__tests__/__snapshots__/template.test.ts.snap +73 -11
- package/__tests__/config.test.ts +2 -2
- package/__tests__/e2e.ts +16 -9
- package/__tests__/template.test.ts +25 -7
- package/dist/bin.cjs +124 -128
- package/dist/bin.js +15 -14
- package/dist/{chunk-MP53H5K3.js → chunk-WLKYS3XU.js} +111 -124
- package/dist/index.cjs +21 -12
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/package.json +6 -2
- package/src/bin.ts +14 -11
- package/src/config.ts +1 -8
- package/src/run.ts +28 -35
- package/src/templates.ts +87 -66
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# wp-lite-env
|
2
2
|
|
3
|
+
## 0.0.19
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 6f6b9ac: put retries-- in finally block, or theres a condition where it runs forever
|
8
|
+
- 6f6b9ac: add test for template generation
|
9
|
+
- 6f6b9ac: add a bin test
|
10
|
+
|
11
|
+
## 0.0.18
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- 7735ac3: use fs/promises
|
16
|
+
- 3ae029a: use Object.assign to set default configuration values
|
17
|
+
- 82d3000: use js-yaml to generate docker-compose.yml
|
18
|
+
- b733e44: use command-line-args
|
19
|
+
- cb25ce7: force dir creation
|
20
|
+
- efe3327: refactor waitForServer
|
21
|
+
|
3
22
|
## 0.0.17
|
4
23
|
|
5
24
|
### Patch Changes
|
@@ -1,17 +1,17 @@
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
2
|
|
3
|
-
exports[`templates compose file generation
|
3
|
+
exports[`templates compose file generation compose generated with correct empty values 1`] = `
|
4
4
|
"services:
|
5
5
|
mysql:
|
6
|
-
image:
|
6
|
+
image: mariadb:lts
|
7
7
|
ports:
|
8
|
-
-
|
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
|
-
-
|
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:
|
23
|
+
HOST_USERNAME: someuser
|
24
24
|
HOST_UID: '502'
|
25
25
|
HOST_GID: '20'
|
26
26
|
ports:
|
27
|
-
-
|
27
|
+
- \${WP_ENV_PORT:-1234}:80
|
28
28
|
environment:
|
29
29
|
APACHE_RUN_USER: '#502'
|
30
30
|
APACHE_RUN_GROUP: '#20'
|
@@ -32,13 +32,75 @@ 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
|
+
- wpcontent:/var/www/html
|
36
|
+
- /some/wp-config/path:/var/www/html/wp-config
|
37
|
+
extra_hosts:
|
38
|
+
- host.docker.internal:host-gateway
|
39
|
+
cli:
|
40
|
+
depends_on:
|
41
|
+
- wordpress
|
42
|
+
build:
|
43
|
+
context: .
|
44
|
+
dockerfile: CLI.Dockerfile
|
45
|
+
args: *ref_0
|
46
|
+
volumes: *ref_1
|
47
|
+
user: '502:20'
|
48
|
+
environment:
|
49
|
+
WORDPRESS_DB_USER: root
|
50
|
+
WORDPRESS_DB_PASSWORD: password
|
51
|
+
WORDPRESS_DB_NAME: wordpress
|
52
|
+
extra_hosts:
|
53
|
+
- host.docker.internal:host-gateway
|
54
|
+
volumes:
|
55
|
+
mysql: {}
|
56
|
+
wpcontent: {}
|
57
|
+
"
|
58
|
+
`;
|
59
|
+
|
60
|
+
exports[`templates compose file generation compose generated with correct values 1`] = `
|
61
|
+
"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: someuser
|
81
|
+
HOST_UID: '502'
|
82
|
+
HOST_GID: '20'
|
83
|
+
ports:
|
84
|
+
- \${WP_ENV_PORT:-1234}: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
|
+
- /some/base/path/some/container/path:/var/www/html/some/host/path
|
35
93
|
- >-
|
36
|
-
|
94
|
+
/some/base/path/some/other/container/path:/var/www/html/some/other/host/path
|
95
|
+
- /some/base/some/plugin/path:/var/www/html/wp-content/plugins/plugin1
|
37
96
|
- >-
|
38
|
-
/some/
|
39
|
-
|
97
|
+
/some/base/some/other/plugin/path:/var/www/html/wp-content/plugins/plugin2
|
98
|
+
- /some/base/some/theme/path:/var/www/html/wp-content/themes/theme1
|
99
|
+
- /some/base/some/other/theme/path:/var/www/html/wp-content/themes/theme2
|
100
|
+
- wpcontent:/var/www/html
|
101
|
+
- /some/wp-config/path:/var/www/html/wp-config
|
40
102
|
extra_hosts:
|
41
|
-
-
|
103
|
+
- host.docker.internal:host-gateway
|
42
104
|
cli:
|
43
105
|
depends_on:
|
44
106
|
- wordpress
|
@@ -53,7 +115,7 @@ exports[`templates compose file generation snapshot test 1`] = `
|
|
53
115
|
WORDPRESS_DB_PASSWORD: password
|
54
116
|
WORDPRESS_DB_NAME: wordpress
|
55
117
|
extra_hosts:
|
56
|
-
-
|
118
|
+
- host.docker.internal:host-gateway
|
57
119
|
volumes:
|
58
120
|
mysql: {}
|
59
121
|
wpcontent: {}
|
package/__tests__/config.test.ts
CHANGED
@@ -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,19 +1,26 @@
|
|
1
|
-
import {
|
1
|
+
import {describe, expect, test} from "@jest/globals";
|
2
2
|
import {generateFiles, getConfigFilePath, start, stop} from "../src/run";
|
3
|
+
import {execSync} from "node:child_process";
|
3
4
|
|
4
|
-
const port =
|
5
|
+
const port = 1234;
|
5
6
|
|
6
7
|
describe('end to end tests', () => {
|
7
|
-
beforeAll(async () => {
|
8
|
-
generateFiles(port, getConfigFilePath(['', '', '', 'config=./__tests__/.wp-lite-env.json']));
|
9
|
-
})
|
10
|
-
afterEach(async () => {
|
11
|
-
await stop(port);
|
12
|
-
}, 30000);
|
13
8
|
test('WordPress is up and running', async () => {
|
14
|
-
await
|
9
|
+
await generateFiles(port, getConfigFilePath(['', '', '', 'config=./__tests__/.wp-lite-env.json']));
|
10
|
+
try {
|
11
|
+
await start(port);
|
12
|
+
const response = await fetch(`http://localhost:${port}`);
|
13
|
+
expect(response.ok).toBe(true);
|
14
|
+
expect(await response.text()).toContain('Welcome to WordPress');
|
15
|
+
} finally {
|
16
|
+
await stop(port);
|
17
|
+
}
|
18
|
+
}, 60000);
|
19
|
+
test('WordPress is up and running using binary (requires building the library!)', async () => {
|
20
|
+
execSync('npx wp-lite-env start --config=./__tests__/.wp-lite-env.json --port=1234');
|
15
21
|
const response = await fetch(`http://localhost:${port}`);
|
16
22
|
expect(response.ok).toBe(true);
|
17
23
|
expect(await response.text()).toContain('Welcome to WordPress');
|
24
|
+
execSync('npx wp-lite-env stop --config=./__tests__/.wp-lite-env.json --port=1234');
|
18
25
|
}, 60000);
|
19
26
|
});
|
@@ -30,19 +30,37 @@ describe('templates', () => {
|
|
30
30
|
"WP_DEBUG": false
|
31
31
|
}
|
32
32
|
};
|
33
|
-
const configTemplate = generateConfiguration( config,
|
33
|
+
const configTemplate = generateConfiguration( config, 1234 );
|
34
34
|
expect(configTemplate).toMatchSnapshot();
|
35
35
|
});
|
36
36
|
});
|
37
37
|
|
38
38
|
describe('compose file generation', () => {
|
39
|
-
test('
|
39
|
+
test('compose generated with correct empty values', () => {
|
40
40
|
const config = {
|
41
41
|
mappings: {},
|
42
42
|
plugins: {},
|
43
43
|
themes: {},
|
44
44
|
}
|
45
|
-
const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path',
|
45
|
+
const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', 1234, '/some/wp-config/path' );
|
46
|
+
expect(composeYml).toMatchSnapshot();
|
47
|
+
});
|
48
|
+
test('compose generated with correct values', () => {
|
49
|
+
const config = {
|
50
|
+
mappings: {
|
51
|
+
'some/host/path': 'some/container/path',
|
52
|
+
'some/other/host/path': 'some/other/container/path',
|
53
|
+
},
|
54
|
+
plugins: {
|
55
|
+
'plugin1': '../some/plugin/path',
|
56
|
+
'plugin2': '../some/other/plugin/path',
|
57
|
+
},
|
58
|
+
themes: {
|
59
|
+
'theme1': '../some/theme/path',
|
60
|
+
'theme2': '../some/other/theme/path',
|
61
|
+
},
|
62
|
+
}
|
63
|
+
const composeYml = generateDockerComposeYmlTemplate( config, '/some/base/path', 1234, '/some/wp-config/path' );
|
46
64
|
expect(composeYml).toMatchSnapshot();
|
47
65
|
});
|
48
66
|
test('mappings are mounted correctly', () => {
|
@@ -55,7 +73,7 @@ describe('templates', () => {
|
|
55
73
|
themes: {},
|
56
74
|
}
|
57
75
|
const basePath = '/some/base/path';
|
58
|
-
const composeYml = generateDockerComposeYmlTemplate( config, basePath,
|
76
|
+
const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
|
59
77
|
expect(composeYml).toMatch(new RegExp(`${basePath}/some/container/path:/var/www/html/some/host/path`));
|
60
78
|
expect(composeYml).toMatch(new RegExp(`${basePath}/some/other/container/path:/var/www/html/some/other/host/path`));
|
61
79
|
});
|
@@ -70,7 +88,7 @@ describe('templates', () => {
|
|
70
88
|
themes: {},
|
71
89
|
}
|
72
90
|
const basePath = '/some/base/path';
|
73
|
-
const composeYml = generateDockerComposeYmlTemplate( config, basePath,
|
91
|
+
const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
|
74
92
|
expect(composeYml).toMatch(new RegExp(`/some/base/some/plugin/path:/var/www/html/wp-content/plugins/plugin1`));
|
75
93
|
expect(composeYml).toMatch(new RegExp(`/some/base/some/other/plugin/path:/var/www/html/wp-content/plugins/plugin2`));
|
76
94
|
});
|
@@ -84,7 +102,7 @@ describe('templates', () => {
|
|
84
102
|
},
|
85
103
|
}
|
86
104
|
const basePath = '/some/base/path';
|
87
|
-
const composeYml = generateDockerComposeYmlTemplate( config, basePath,
|
105
|
+
const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
|
88
106
|
expect(composeYml).toMatch(new RegExp(`/some/base/some/theme/path:/var/www/html/wp-content/themes/theme1`));
|
89
107
|
expect(composeYml).toMatch(new RegExp(`/some/base/some/other/theme/path:/var/www/html/wp-content/themes/theme2`));
|
90
108
|
});
|
@@ -96,7 +114,7 @@ describe('templates', () => {
|
|
96
114
|
themes: {},
|
97
115
|
}
|
98
116
|
const basePath = '/some/base/path';
|
99
|
-
const composeYml = generateDockerComposeYmlTemplate( config, basePath,
|
117
|
+
const composeYml = generateDockerComposeYmlTemplate( config, basePath, 1234, '/some/wp-config/path' );
|
100
118
|
expect(composeYml).toMatch(new RegExp(`/some/wp-config/path:/var/www/html/wp-config`));
|
101
119
|
});
|
102
120
|
});
|
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
|
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
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
const
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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,25 +187,29 @@ 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
|
-
|
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 (
|
196
|
+
if (200 === response.status || 302 === response.status) {
|
185
197
|
return true;
|
186
198
|
}
|
187
199
|
} catch (e) {
|
188
|
-
|
200
|
+
if ("ECONNREFUSED" !== e.cause?.code) {
|
201
|
+
console.warn(`Encountered an error while waiting for server to start: ${e.message}
|
189
202
|
Trying to reach server again.`);
|
203
|
+
}
|
190
204
|
} finally {
|
191
|
-
|
205
|
+
retries--;
|
192
206
|
}
|
207
|
+
await sleep(pollEveryMs);
|
193
208
|
}
|
194
209
|
console.error(`Server did not start within ${timeoutMs}ms`);
|
195
210
|
return false;
|
196
211
|
};
|
197
|
-
var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), port2);
|
212
|
+
var getRunPath = (port2) => import_path2.default.resolve(import_node_os.default.tmpdir(), `${port2}`);
|
198
213
|
var start = async (port2) => {
|
199
214
|
const runPath = getRunPath(port2);
|
200
215
|
await (0, import_docker_compose.upAll)({
|
@@ -214,7 +229,7 @@ var stop = async (port2) => {
|
|
214
229
|
composeOptions: ["-p", `port${port2}`],
|
215
230
|
log: true
|
216
231
|
});
|
217
|
-
cleanup(port2);
|
232
|
+
await cleanup(port2);
|
218
233
|
};
|
219
234
|
var cli = async (port2, command2) => {
|
220
235
|
const runPath = getRunPath(port2);
|
@@ -230,62 +245,43 @@ var commandMap = {
|
|
230
245
|
stop,
|
231
246
|
cli
|
232
247
|
};
|
233
|
-
var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), port2);
|
234
|
-
var generateFiles = (port2, configFilePath2) => {
|
248
|
+
var getWpConfigPath = (port2) => import_path2.default.resolve(process.cwd(), `${port2}`);
|
249
|
+
var generateFiles = async (port2, configFilePath2) => {
|
235
250
|
const config = getConfig(configFilePath2);
|
236
251
|
const wpConfigPath = getWpConfigPath(port2);
|
237
|
-
|
238
|
-
import_fs2.default.mkdirSync(wpConfigPath, { recursive: true });
|
239
|
-
}
|
252
|
+
await import_promises.default.mkdir(wpConfigPath, { recursive: true });
|
240
253
|
const wpConfig = generateConfiguration(config, port2);
|
241
|
-
|
254
|
+
await import_promises.default.writeFile(import_path2.default.resolve(wpConfigPath, "configure-wp.sh"), wpConfig);
|
242
255
|
const dockerComposeYmlTemplate = generateDockerComposeYmlTemplate(config, process.cwd(), port2, wpConfigPath);
|
243
256
|
const wordPressDockerfileTemplate = generateWordPressDockerfileTemplate(config);
|
244
257
|
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
245
258
|
const hash = (0, import_crypto.createHash)("sha256");
|
246
259
|
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
|
247
260
|
const runPath = getRunPath(port2);
|
248
|
-
|
249
|
-
import_fs2.default.mkdirSync(runPath);
|
250
|
-
}
|
261
|
+
await import_promises.default.mkdir(runPath, { recursive: true });
|
251
262
|
console.log(`writing files to run path: ${runPath}`);
|
252
|
-
|
253
|
-
|
254
|
-
|
263
|
+
await import_promises.default.writeFile(import_path2.default.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
264
|
+
await import_promises.default.writeFile(import_path2.default.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
265
|
+
await import_promises.default.writeFile(import_path2.default.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
255
266
|
return runPath;
|
256
267
|
};
|
257
|
-
var
|
258
|
-
for (let i = 3; i < processArgs.length; i++) {
|
259
|
-
const argument = processArgs[i];
|
260
|
-
if (argument.startsWith(`${argumentKey}=`)) {
|
261
|
-
return argument.substring(argumentKey.length + 1);
|
262
|
-
}
|
263
|
-
}
|
264
|
-
return void 0;
|
265
|
-
};
|
266
|
-
var getConfigFilePath = (processArgs) => {
|
267
|
-
return import_path2.default.resolve(getArgument("config", processArgs));
|
268
|
-
};
|
269
|
-
var getCliCommand = (processArgs) => {
|
270
|
-
return getArgument("command", processArgs);
|
271
|
-
};
|
272
|
-
var getPort = (processArgs) => {
|
273
|
-
return getArgument("port", processArgs) || "8888";
|
274
|
-
};
|
275
|
-
var cleanup = (port2) => {
|
268
|
+
var cleanup = async (port2) => {
|
276
269
|
const runPath = getRunPath(port2);
|
277
|
-
|
278
|
-
|
270
|
+
await import_promises.default.rm(getWpConfigPath(port2), { recursive: true, force: true });
|
271
|
+
await import_promises.default.rm(runPath, { recursive: true, force: true });
|
279
272
|
};
|
280
273
|
|
281
274
|
// src/bin.ts
|
282
|
-
var
|
283
|
-
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
|
288
|
-
var
|
289
|
-
|
290
|
-
|
275
|
+
var cliOptionDefinitions = [
|
276
|
+
{ name: "cmd", type: String, defaultOption: true, description: 'The command to run. Can be one of "start", "stop" or "cli"' },
|
277
|
+
{ name: "config", type: String, description: "Path to the configuration file defining the WordPress environment." },
|
278
|
+
{ name: "port", type: Number, description: "Port to run the WordPress environment on" },
|
279
|
+
{ name: "command", type: String, defaultValue: "", description: "The command to run by the WP CLI" }
|
280
|
+
];
|
281
|
+
var cliOptions = (0, import_command_line_args.default)(cliOptionDefinitions);
|
282
|
+
var command = cliOptions.cmd;
|
283
|
+
var port = cliOptions.port;
|
284
|
+
var configFilePath = cliOptions.config;
|
285
|
+
var cliCommand = cliOptions.command;
|
286
|
+
generateFiles(port, configFilePath).then(() => commandMap[command](port, cliCommand));
|
291
287
|
//# 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
|
-
|
6
|
-
getConfigFilePath,
|
7
|
-
getPort
|
8
|
-
} from "./chunk-MP53H5K3.js";
|
4
|
+
generateFiles
|
5
|
+
} from "./chunk-WLKYS3XU.js";
|
9
6
|
|
10
7
|
// src/bin.ts
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|