/
index.js
90 lines (72 loc) · 2.54 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
const chalk = require('chalk')
const execSync = require('child_process').execSync
const runCmd = cmd => {
console.info(chalk.dim(`\n$ ${cmd}`))
execSync(cmd, {stdio: 'inherit'})
}
const lint = () => {
runCmd('./tasks/check.sh')
runCmd("tslint -c tslint.json 'src/**/*.{ts,tsx}'")
}
const runPrettier = (...flags) => {
runCmd(
[
'prettier',
'--print-width 85',
'--trailing-comma es5',
'--no-bracket-spacing',
'--no-semi',
'--single-quote',
...flags,
"'!(node_modules|build|coverage|dist)/**/*.{js,ts,tsx}'",
].join(' ')
)
}
const tasks = {
/****************************************************************************/
/** Linting *****************************************************************/
/****************************************************************************/
lint,
style: () => runPrettier('--write'),
/****************************************************************************/
/** Development *************************************************************/
/****************************************************************************/
start: () => {
/** Note that this builds the frontend with the hot-reloading dev server. */
runCmd('webpack --config webpack/server/development.ts')
runCmd('node build/backend.js')
},
/****************************************************************************/
/** Production **************************************************************/
/****************************************************************************/
'build:prod': () => {
runCmd('webpack --config webpack/frontend/production.ts')
runCmd('webpack --config webpack/server/production.ts')
},
'start:prod': () => {
runCmd('node dist/backend.js')
},
/****************************************************************************/
/** Testing *****************************************************************/
/****************************************************************************/
'test:ci': () => {
lint()
runCmd('NODE_ENV=ci jest')
runCmd('NODE_ENV=ci nightwatch --config test/nightwatch.js')
},
'test:watch': () => {
runCmd('NODE_ENV=test jest --watch')
},
test: () => {
lint()
runPrettier('--list-different')
runCmd('NODE_ENV=test jest --coverage')
runCmd('NODE_ENV=test nightwatch --config test/nightwatch.js')
},
}
const taskName = process.argv[2]
const task = tasks[taskName]
if (!task) {
throw Error(chalk.black.bgRed(`\n\n Task "${taskName}" is not defined\n`))
}
task()