forked from t-ho/mern-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
106 lines (94 loc) · 2.42 KB
/
start.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
const concurrently = require('concurrently');
const chalk = require('chalk');
const figlet = require('figlet');
const _ = require('lodash');
/**
* This script run npm proccesses concurrently
*
* Usage: node start [install-children|test|server|client|mobile|server:client:mobile|server:client|server:mobile]
*
* Example:
* * node start install-children
* * node start test
* * node start server
* * node start client
* * node start mobile
* * node start server:client:mobile
* * node start server:client
* * node start server:mobile
*/
const getUppercaseArgs = () => {
validArgs = [
'install-children',
'test',
'server',
'client',
'mobile',
'server:client:mobile',
'server:client',
'server:mobile',
];
if (process.argv.length === 2) {
process.argv.push('server:client:mobile');
} else if (process.argv.length > 3) {
throw new Error(`[-] Invalid command. Please specify only one argument`);
}
if (_.findIndex(validArgs, (arg) => arg === process.argv[2]) === -1) {
throw new Error(`[-] Invalid argument "${process.argv[2]}"`);
}
const args = process.argv[2].split(':').map((arg) => arg.toUpperCase());
return args;
};
const run = () => {
const artText = figlet.textSync(' MERN STACK', { font: 'ANSI Shadow' });
console.log(chalk.cyan(artText));
const upperCaseArgs = getUppercaseArgs();
let availableCommands = [
{
command: 'node start-helper install-children',
name: 'INSTALL-CHILDREN',
prefixColor: 'gray',
},
{
command: 'node start-helper test',
name: 'TEST',
prefixColor: 'cyan',
},
{
command: 'node start-helper server',
name: 'SERVER',
prefixColor: 'cyan',
},
{
command: 'node start-helper client',
name: 'CLIENT',
prefixColor: 'yellow',
},
{
command: 'node start-helper mobile',
name: 'MOBILE',
prefixColor: 'gray',
},
];
const commands = _.filter(availableCommands, (command) => {
return _.some(upperCaseArgs, (arg) => command.name === arg);
});
const options = {
prefix: 'name',
restartTries: 0,
restartDelay: 0,
successCondition: 'all',
};
if (_.isEqual(upperCaseArgs, ['INSTALL-CHILDREN'])) {
options.raw = true;
}
const { result } = concurrently(commands, options);
result
.then((success, failure) => {})
.catch((err) => {
if (err) {
process.exit(1);
}
});
};
run();