This repository has been archived by the owner on Feb 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·99 lines (92 loc) · 2.81 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
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env node
const [executor, bin, command, ...args] = process.argv
const isCI = require('is-ci')
const { paths, run, cpy, clean, error, log } = require('./utils')
const runner = require('./runner')
const { klap } = require('klap')
const configMap = {
jest: 'jest.config.js',
prettier: 'prettier.config.json',
tslint: 'tslint.config.json',
}
process.env.COMMAND = command
log(`woking on '${command}'`)
const execKlap = async command => {
const pkg = require(paths.app('package.json'))
await klap(command, pkg)
}
;(async () => {
switch (command) {
case 'init':
require('./init')()
break
case 'eject':
const type = configMap[process.argv[3]]
if (paths.config(type) !== paths.app(type)) {
cpy(paths.config(type), paths.app(type))
log(`Done !! ${type} is now available in project root.`)
} else {
error(`${type} is already ejected.`)
}
break
case 'build':
process.env.NODE_ENV = 'production'
clean('dist/*.*')
execKlap(command)
run(`${paths.bin('tsc')} -p ${paths.app('tsconfig.json')}`)
break
case 'watch':
process.env.NODE_ENV = 'development'
clean('dist/*.*')
execKlap(command)
break
case 'start':
process.env.NODE_ENV = 'development'
clean('dist/*.*')
execKlap(command)
break
case 'test':
process.env.NODE_ENV = 'test'
const jestFlags = isCI ? '--coverage' : '--watch'
run(`${paths.bin('jest')} --config ${paths.config('jest.config.js')} ${jestFlags}`)
break
case 'coverage':
process.env.NODE_ENV = 'test'
run(`${paths.bin('jest')} --config ${paths.config('jest.config.js')} --coverage`)
break
case 'coveralls':
process.env.NODE_ENV = 'test'
run(`${paths.bin('jest')} --config ${paths.config('jest.config.js')} --coverage`)
run(`${paths.bin('coveralls')} < ${paths.app('coverage', 'lcov.info')}`)
break
case 'format':
run(
`${paths.bin(
'prettier'
)} --write "{public,src,tests}/**/*.{tsx,ts,json,yml,html,css,md,mdx,gql,less,scss,jsx,js}"`
)
break
case 'lint':
run(`${paths.bin('tslint')} --fix -t codeFrame -p tsconfig.json -c ${paths.config('tslint.config.json')}`)
break
case 'setup':
;['git clean -fdX', runner.install()].map(cmd => run(cmd))
break
case 'pub':
;[runner.script('setup'), runner.script('format'), runner.script('lint'), runner.script('coverage')]
.filter(Boolean)
.map(cmd => run(cmd))
try {
run('git diff --quiet')
} catch (e) {
error('Working directory not clean. Aborting release !!')
process.exit(1)
}
runner.publish()
run('git push --follow-tags')
break
default:
error('No Such Command !!')
break
}
})()