-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·56 lines (39 loc) · 1.59 KB
/
init
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
#! /usr/bin/node
const commander = require('/usr/lib/node_modules/commander/index.js')
const spawn = require('child_process').spawn
const execSync = require('child_process').execSync
const noop = value => value
commander
.option('--babel-source-dir <s>', 'Folder in which source files are', noop, 'source')
.option('--babel-out-dir <s>', 'Folder into which source files are to be compiled', noop, 'build')
.option('--entry-file <s>', 'File to start app from', noop, 'build/index.js')
.option('--no-babel', 'Do not run babel')
.option('--no-watch', 'Compile once and exit')
.option('--run-args <s>', 'Arguments to pass to your script')
.parse(process.argv)
const babelOutDir = commander.babelOutDir
const babelSourceDir = commander.babelSourceDir
const entryFile = commander.entryFile
const babel = commander.babel
const watch = commander.watch
const runArgs = commander.runArgs
const inherit = {stdio: 'inherit'}
if (watch) {
execSync('tmux start-server', inherit)
execSync('tmux new -s node-development -d', inherit)
const main_window = 'node-development:0'
execSync('npm install', inherit)
execSync('tmux split-window -p 10 "eye --*glob=package.json npm install"', inherit)
execSync(`tmux send-keys -t ${main_window}.0 \
"nodemon" " ${entryFile}" \
" ${runArgs}" ENTER`, inherit)
if (babel) {
execSync(
`tmux split-window -h \\
"babel -w --out-dir ${babelOutDir} ${babelSourceDir}"`, inherit)
}
execSync('tmux attach-session -t node-development', inherit)
}
else {
execSync(`babel --out-dir ${babelOutDir} ${babelSourceDir}`, inherit)
}