-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
87 lines (80 loc) · 1.89 KB
/
cli.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
#!/usr/bin/env node
const shell = require( 'shelljs' );
const path = require( 'path' );
const program = require( 'commander' );
const inquirer = require( 'inquirer' );
const { readdirSync, statSync } = require( 'fs' );
const dirs = ( dirPath ) =>
readdirSync( dirPath ).filter( ( folder ) =>
statSync( path.join( dirPath, folder ) ).isDirectory()
);
const themesDirPath = path.join( __dirname, 'htdocs/wp-content/themes' );
program
.version( '0.0.0', 'v, version' )
.description( 'A CLI for running npm scripts' )
.option( '-s, -start', 'run prompt', runAll )
.option( '-d, -dev', 'run development', startDev )
.option( '-p -prod', 'run production', startProd )
.parse( process.argv );
function runTask( task = 'dev', theme ) {
shell.exec( `npm run ${ task } -- --env theme=${ theme }`, {
env: { FORCE_COLOR: true, ...process.env },
} );
}
function runAll() {
const themes = dirs( themesDirPath );
const questions = [
{
type: 'list',
name: 'q1',
message: 'Which command would you like to run?',
choices: [
'dev',
'dev:editor',
'dev:frontend',
'dev-all',
'prod',
'prod:editor',
'prod:frontend',
'prod-all',
],
},
{
type: 'list',
name: 'q2',
message: 'And for what theme?',
choices: themes,
},
];
inquirer.prompt( questions ).then( function ( answers ) {
runTask( answers.q1, answers.q2 );
} );
}
function startDev() {
const themes = dirs( themesDirPath );
const questions = [
{
type: 'list',
name: 'q1',
message: 'Which theme?',
choices: themes,
},
];
inquirer.prompt( questions ).then( function ( answers ) {
runTask( 'dev', answers.q1 );
} );
}
function startProd() {
const themes = dirs( themesDirPath );
const questions = [
{
type: 'list',
name: 'q1',
message: 'Which theme?',
choices: themes,
},
];
inquirer.prompt( questions ).then( function ( answers ) {
runTask( 'prod', answers.q1 );
} );
}