-
Notifications
You must be signed in to change notification settings - Fork 12
/
start.js
93 lines (82 loc) · 2.07 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
const concurently = 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|api|client|api:client|api:client]
*
* Example:
* * node start install-children
* * node start test
* * node start api
* * node start client
* * node start api:client
*/
const getUppercaseArgs = () => {
validArgs = [
'install-children',
'test',
'api',
'client',
'api:client',
];
if (process.argv.length === 2) {
process.argv.push('api:client');
} 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(' LearnScape', { 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 api',
name: 'API',
prefixColor: 'cyan',
},
{
command: 'node start-helper client',
name: 'CLIENT',
prefixColor: 'yellow',
},
];
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;
}
concurently(commands, options)
.then((success, failure) => {})
.catch((err) => {
if (err) {
process.exit(1);
}
});
};
run();