Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.js
More file actions
Latest commit
79 lines (71 loc) · 2.09 KB
/
Copy pathdev.js
File metadata and controls
79 lines (71 loc) · 2.09 KB
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
/**
* Concurrently run our various dev tasks.
*
* Usage: node dev
**/
constapp=require('.')
,chalk=require('chalk'),{bold}=chalk
,{red, green, blue, cyan, yellow}=bold
,dev=module.exports=()=>run({
server: task(app.package.scripts['start'],{color: blue}),
build: task(app.package.scripts['build-watch'],{color: green}),
lint: task(app.package.scripts['lint-watch'],{color: cyan}),
test: task(app.package.scripts['test-watch'],{color: yellow})
});
consttaskEnvironment=(path=require('path'))=>{
constenv={};
for(constkeyinprocess.env){
env[key]=process.env[key];
}
Object.assign(env,{
NODE_ENV: 'development',
PATH: [path.join(app.root,'node_modules','.bin')
,process.env.PATH].join(path.delimiter)
});
returnenv;
};
functionrun(tasks){
Object.keys(tasks)
.map(name=>tasks[name](name));
}
functiontask(command,{
spawn=require('child_process').spawn,
path=require('path'),
color
}={}){
returnname=>{
conststdout=log({name, color},process.stdout)
,stderr=log({name, color,text: red},process.stderr)
,proc=spawn(command,{
shell: true,
stdio: 'pipe',
env: taskEnvironment(),
}).on('error',stderr)
.on('exit',(code,signal)=>{
stderr(`Exited with code ${code}`);
if(signal)stderr(`Exited with signal ${signal}`);
});
proc.stdout.on('data',stdout);
proc.stderr.on('data',stderr);
};
}
functionlog({
name,
ts=timestamp,
color=none,
text=none,
},out=process.stdout){
returndata=>data.toString()
// Strip out screen-clearing control sequences, which really
// muck up the output.
.replace('\u001b[2J','')
.replace('\u001b[1;3H','')
.split('\n')
.forEach(line=>out.write(`${color(`${ts()}${name} \t⎹ `)}${text(line)}\n`));
}
constdateformat=require('dateformat');
functiontimestamp(){
returndateformat('yyyy-mm-dd HH:MM:ss (Z)');
}
functionnone(x){returnx;}
if(module===require.main){dev();}