forked from wielebenwir/commonsbooking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-env-cli
executable file
·52 lines (45 loc) · 1.23 KB
/
wp-env-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
const path = require('path');
const { spawn } = require('child_process');
const { readConfig } = require('@wordpress/env/lib/config');
function spawnCommandDirectly({ container, command, dockerComposeConfigPath }) {
const composeCommand = [
'-f',
dockerComposeConfigPath,
'exec -T',
container,
...command.split(' '), // The command will fail if passed as a complete string.
];
return new Promise((resolve, reject) => {
const childProc = spawn('docker-compose', composeCommand, {
stdio: 'inherit',
shell: true,
});
childProc.on('error', reject);
childProc.on('exit', (code) => {
// Code 130 is set if the user tries to exit with ctrl-c before using
// ctrl-d (so it is not an error which should fail the script.)
if (code === 0 || code === 130) {
resolve();
} else {
reject(code);
}
});
});
}
const run = async () => {
const configPath = path.resolve('.wp-env.json');
const { dockerComposeConfigPath } = await readConfig(configPath);
const container = process.argv[2];
const command = process.argv.splice(3).join(' ');
try {
await spawnCommandDirectly({
container,
command,
dockerComposeConfigPath,
});
} catch (errorCode) {
process.exit(errorCode);
}
};
run();