forked from 10up/wp-local-docker-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·108 lines (97 loc) · 3.51 KB
/
index.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env node
const chalk = require( 'chalk' );
const commandUtils = require( './src/command-utils' );
const config = require( './src/configure' );
const snapshots = require( './src/wpsnapshots' );
const help = function() {
let help = `
Usage: 10updocker COMMAND
Commands:
cache Manages the build cache
configure Set up a configuration for WP Local Docker
create Create a new docker environment
delete Deletes a specific docker environment
image Manages docker images used by this environment
logs Shows logs from the specified container in your current environment (Defaults to all containers)
migrate Migrates a V1 WP Local Docker environment to a new V2 environment.
restart Restarts a specific docker environment
shell Opens a shell for a specified container in your current environment (Defaults to the phpfpm container)
start Starts a specific docker environment
stop Stops a specific docker environment
wp Runs a wp-cli command in your current environment
wpsnapshots Runs a wp snapshots command
Run '10updocker COMMAND help' for more information on a command.
`;
console.log( help );
};
const version = function() {
var pjson = require('./package.json');
console.log( 'WP Local Docker' );
console.log( `Version ${pjson.version}` );
};
const init = async function() {
let command = commandUtils.command();
let configured = await config.checkIfConfigured();
let bypassCommands = [ undefined, 'configure', 'help', '--version', '-v' ];
let isBypass = bypassCommands.indexOf( command ) !== -1;
// Configure using defaults if not configured already
if ( configured === false && isBypass === false ) {
await config.configureDefaults();
}
// Don't even run the command to check if docker is running if we have one of the commands that don't need it
if ( isBypass === false ) {
let isRunning = commandUtils.checkIfDockerRunning();
// Show warning if docker isn't running
if ( isRunning === false ) {
console.error( chalk.red( "Error: Docker doesn't appear to be running. Please start Docker and try again" ) );
process.exit();
}
}
await commandUtils.checkForUpdates();
switch ( command ) {
case 'configure':
config.command();
break;
case 'create':
await require('./src/create').command();
break;
case 'start':
case 'stop':
case 'restart':
case 'delete':
case 'remove':
case 'upgrade':
await require('./src/environment').command();
break;
case 'snapshots':
case 'wpsnapshots':
await require('./src/wpsnapshots').command();
break;
case 'cache':
await require('./src/cache').command();
break;
case 'image':
await require('./src/image').command();
break;
case 'shell':
await require( './src/shell' ).command();
break;
case 'wp':
await require( './src/wp' ).command();
break;
case 'logs':
await require( './src/logs' ).command();
break;
case 'migrate':
await require( './src/migrate' ).command();
break;
case '--version':
case '-v':
version();
break;
default:
help();
break;
}
};
init();