@elementor/wp-lite-env 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/__tests__/e2e.ts +7 -8
- package/dist/index.d.ts +5 -0
- package/dist/index.js +30 -20
- package/index.ts +4 -3
- package/package.json +3 -3
- package/src/run.ts +13 -7
package/CHANGELOG.md
CHANGED
package/__tests__/e2e.ts
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
import {afterEach, describe, expect, test} from "@jest/globals";
|
1
|
+
import {afterEach, beforeAll, describe, expect, test} from "@jest/globals";
|
2
2
|
import {cleanup, generateFiles, getConfigFilePath, start, stop} from "../src/run";
|
3
3
|
|
4
4
|
const port = '1234';
|
5
|
-
const runPath = (port: string) => {
|
6
|
-
return generateFiles(port, getConfigFilePath(['', '', '', 'config=./tests/.wp-lite-env.json']));
|
7
|
-
};
|
8
5
|
|
9
6
|
describe('end to end tests', () => {
|
7
|
+
beforeAll(async () => {
|
8
|
+
generateFiles(port, getConfigFilePath(['', '', '', 'config=./tests/.wp-lite-env.json']));
|
9
|
+
})
|
10
10
|
afterEach(async () => {
|
11
|
-
|
12
|
-
|
13
|
-
cleanup(port, theRunPath);
|
11
|
+
await stop(port);
|
12
|
+
cleanup(port);
|
14
13
|
}, 30000);
|
15
14
|
test('WordPress is up and running', async () => {
|
16
|
-
await start( port
|
15
|
+
await start( port );
|
17
16
|
const response = await fetch(`http://localhost:${port}`);
|
18
17
|
expect(response.ok).toBe(true);
|
19
18
|
expect(await response.text()).toContain('Welcome to WordPress');
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -169,27 +169,31 @@ var waitForServer = async (url, timeoutMs) => {
|
|
169
169
|
}
|
170
170
|
return false;
|
171
171
|
};
|
172
|
-
var
|
172
|
+
var getRunPath = (port2) => path2.resolve(os.tmpdir(), port2);
|
173
|
+
var start = async (port2) => {
|
174
|
+
const runPath = getRunPath(port2);
|
173
175
|
await upAll({
|
174
176
|
commandOptions: ["--build"],
|
175
177
|
composeOptions: ["-p", `port${port2}`],
|
176
|
-
cwd:
|
178
|
+
cwd: runPath,
|
177
179
|
log: true
|
178
180
|
});
|
179
181
|
await waitForServer(`http://localhost:${port2}`, 1e4);
|
180
|
-
await cli(port2,
|
182
|
+
await cli(port2, "bash wp-config/configure-wp.sh");
|
181
183
|
};
|
182
|
-
var stop = async (port2
|
184
|
+
var stop = async (port2) => {
|
185
|
+
const runPath = getRunPath(port2);
|
183
186
|
await downAll({
|
184
|
-
cwd:
|
187
|
+
cwd: runPath,
|
185
188
|
commandOptions: ["--volumes", "--remove-orphans"],
|
186
189
|
composeOptions: ["-p", `port${port2}`],
|
187
190
|
log: true
|
188
191
|
});
|
189
192
|
};
|
190
|
-
var cli = async (port2,
|
193
|
+
var cli = async (port2, command2) => {
|
194
|
+
const runPath = getRunPath(port2);
|
191
195
|
await run("cli", command2, {
|
192
|
-
cwd:
|
196
|
+
cwd: runPath,
|
193
197
|
commandOptions: ["--rm"],
|
194
198
|
composeOptions: ["-p", `port${port2}`],
|
195
199
|
log: true
|
@@ -214,15 +218,15 @@ var generateFiles = (port2, configFilePath2) => {
|
|
214
218
|
const cliDockerfileTemplate = generateCliDockerfileTemplate(config);
|
215
219
|
const hash = createHash("sha256");
|
216
220
|
hash.update(dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port2);
|
217
|
-
const
|
218
|
-
if (!fs2.existsSync(
|
219
|
-
fs2.mkdirSync(
|
221
|
+
const runPath = getRunPath(port2);
|
222
|
+
if (!fs2.existsSync(runPath)) {
|
223
|
+
fs2.mkdirSync(runPath);
|
220
224
|
}
|
221
|
-
console.log(`writing files to run path: ${
|
222
|
-
fs2.writeFileSync(path2.resolve(
|
223
|
-
fs2.writeFileSync(path2.resolve(
|
224
|
-
fs2.writeFileSync(path2.resolve(
|
225
|
-
return
|
225
|
+
console.log(`writing files to run path: ${runPath}`);
|
226
|
+
fs2.writeFileSync(path2.resolve(runPath, "docker-compose.yml"), dockerComposeYmlTemplate);
|
227
|
+
fs2.writeFileSync(path2.resolve(runPath, "WordPress.Dockerfile"), wordPressDockerfileTemplate);
|
228
|
+
fs2.writeFileSync(path2.resolve(runPath, "CLI.Dockerfile"), cliDockerfileTemplate);
|
229
|
+
return runPath;
|
226
230
|
};
|
227
231
|
var getArgument = (argumentKey, processArgs) => {
|
228
232
|
for (let i = 3; i < processArgs.length; i++) {
|
@@ -242,9 +246,10 @@ var getCliCommand = (processArgs) => {
|
|
242
246
|
var getPort = (processArgs) => {
|
243
247
|
return getArgument("port", processArgs) || "8888";
|
244
248
|
};
|
245
|
-
var cleanup = (port2
|
249
|
+
var cleanup = (port2) => {
|
250
|
+
const runPath = getRunPath(port2);
|
246
251
|
fs2.rmSync(getWpConfigPath(port2), { recursive: true, force: true });
|
247
|
-
fs2.rmSync(
|
252
|
+
fs2.rmSync(runPath, { recursive: true, force: true });
|
248
253
|
};
|
249
254
|
|
250
255
|
// index.ts
|
@@ -254,11 +259,16 @@ if (!commandMap[command]) {
|
|
254
259
|
}
|
255
260
|
var port = getPort(process.argv);
|
256
261
|
var configFilePath = getConfigFilePath(process.argv);
|
257
|
-
var runPath = generateFiles(port, configFilePath);
|
258
262
|
var cliCommand = getCliCommand(process.argv);
|
263
|
+
generateFiles(port, configFilePath);
|
259
264
|
try {
|
260
|
-
await commandMap[command](port,
|
265
|
+
await commandMap[command](port, cliCommand);
|
261
266
|
} finally {
|
262
|
-
cleanup(port
|
267
|
+
cleanup(port);
|
263
268
|
}
|
269
|
+
export {
|
270
|
+
cli,
|
271
|
+
start,
|
272
|
+
stop
|
273
|
+
};
|
264
274
|
//# 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 ] ) {
|
@@ -9,11 +10,11 @@ if ( ! commandMap[ command ] ) {
|
|
9
10
|
|
10
11
|
const port = getPort( process.argv );
|
11
12
|
const configFilePath = getConfigFilePath( process.argv )
|
12
|
-
const runPath = generateFiles( port, configFilePath );
|
13
13
|
const cliCommand = getCliCommand( process.argv );
|
14
|
+
generateFiles( port, configFilePath );
|
14
15
|
|
15
16
|
try {
|
16
|
-
await commandMap[command](port,
|
17
|
+
await commandMap[command](port, cliCommand);
|
17
18
|
} finally {
|
18
|
-
cleanup( port
|
19
|
+
cleanup( port );
|
19
20
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@elementor/wp-lite-env",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.13",
|
4
4
|
"private": false,
|
5
5
|
"description": "A simple, lightweight, docker-based WordPress environment",
|
6
6
|
"main": "dist/index.js",
|
@@ -37,12 +37,12 @@
|
|
37
37
|
"@eslint/js": "^9.15.0",
|
38
38
|
"@jest/globals": "^29.7.0",
|
39
39
|
"@types/eslint__js": "^8.42.3",
|
40
|
-
"@types/node": "^22.
|
40
|
+
"@types/node": "^22.10.0",
|
41
41
|
"eslint": "~9.14.0",
|
42
42
|
"jest": "^29.7.0",
|
43
43
|
"ts-jest": "^29.2.5",
|
44
44
|
"tsup": "^8.3.5",
|
45
45
|
"typescript": "^5.6.3",
|
46
|
-
"typescript-eslint": "^8.
|
46
|
+
"typescript-eslint": "^8.16.0"
|
47
47
|
}
|
48
48
|
}
|
package/src/run.ts
CHANGED
@@ -30,7 +30,10 @@ const waitForServer = async ( url: string, timeoutMs: number ) => {
|
|
30
30
|
return false;
|
31
31
|
};
|
32
32
|
|
33
|
-
|
33
|
+
const getRunPath = ( port: string ) => path.resolve( os.tmpdir(), port );
|
34
|
+
|
35
|
+
export const start = async ( port: string ) => {
|
36
|
+
const runPath = getRunPath( port );
|
34
37
|
await upAll( {
|
35
38
|
commandOptions: [ '--build' ],
|
36
39
|
composeOptions: [ '-p', `port${ port }` ],
|
@@ -38,10 +41,11 @@ export const start = async ( port: string, runPath: string ) => {
|
|
38
41
|
log: true,
|
39
42
|
} );
|
40
43
|
await waitForServer( `http://localhost:${ port }`, 10000 );
|
41
|
-
await cli( port,
|
44
|
+
await cli( port, 'bash wp-config/configure-wp.sh' );
|
42
45
|
};
|
43
46
|
|
44
|
-
export const stop = async ( port: string
|
47
|
+
export const stop = async ( port: string ) => {
|
48
|
+
const runPath = getRunPath( port );
|
45
49
|
await downAll( {
|
46
50
|
cwd: runPath,
|
47
51
|
commandOptions: [ '--volumes', '--remove-orphans' ],
|
@@ -50,7 +54,8 @@ export const stop = async ( port: string, runPath: string ) => {
|
|
50
54
|
} );
|
51
55
|
};
|
52
56
|
|
53
|
-
const cli = async ( port: string,
|
57
|
+
export const cli = async ( port: string, command: string ) => {
|
58
|
+
const runPath = getRunPath( port );
|
54
59
|
await run( 'cli', command, {
|
55
60
|
cwd: runPath,
|
56
61
|
commandOptions: [ '--rm' ],
|
@@ -59,7 +64,7 @@ const cli = async ( port: string, runPath: string, command: string ) => {
|
|
59
64
|
} );
|
60
65
|
};
|
61
66
|
|
62
|
-
export const commandMap: { [key: string]: ( ( port: string ) => Promise<void> ) | ( ( port: string,
|
67
|
+
export const commandMap: { [key: string]: ( ( port: string ) => Promise<void> ) | ( ( port: string, command: string ) => Promise<void> ) } = {
|
63
68
|
start,
|
64
69
|
stop,
|
65
70
|
cli,
|
@@ -84,7 +89,7 @@ export const generateFiles = ( port: string, configFilePath: string ) => {
|
|
84
89
|
const cliDockerfileTemplate = generateCliDockerfileTemplate( config );
|
85
90
|
const hash = createHash( 'sha256' );
|
86
91
|
hash.update( dockerComposeYmlTemplate + wordPressDockerfileTemplate + cliDockerfileTemplate + port );
|
87
|
-
const runPath =
|
92
|
+
const runPath = getRunPath( port );
|
88
93
|
if ( ! fs.existsSync( runPath ) ) {
|
89
94
|
fs.mkdirSync( runPath );
|
90
95
|
}
|
@@ -119,7 +124,8 @@ export const getPort = ( processArgs: string[] ) => {
|
|
119
124
|
return getArgument( 'port', processArgs ) || '8888';
|
120
125
|
};
|
121
126
|
|
122
|
-
export const cleanup = ( port: string
|
127
|
+
export const cleanup = ( port: string ) => {
|
128
|
+
const runPath = getRunPath( port );
|
123
129
|
fs.rmSync( getWpConfigPath( port ), { recursive: true, force: true } );
|
124
130
|
fs.rmSync( runPath, { recursive: true, force: true } );
|
125
131
|
}
|