-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.js
executable file
·46 lines (41 loc) · 1.27 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
#!/usr/bin/env node
var program = require('commander');
program
.option('-e, --encoding [type]', 'Specify the encoding of dotenv file')
.option('-p, --path [type]', 'Specify a custom path of dotenv file')
.option('-s, --silent', 'silent')
.parse(process.argv);
var scriptName = program.args[0];
if (!program.silent) {
console.log('running better-npm-run in', process.cwd());
}
var join = require('path').join;
var fullPackagePath = join(process.cwd(), 'package.json');
var pkg = require(fullPackagePath);
var exec = require('./lib/exec.js');
if (!pkg.scripts) {
process.stderr.write('ERROR: No scripts found!');
process.exit(1);
}
if (!pkg.betterScripts) {
process.stderr.write('ERROR: No betterScripts found!');
process.exit(1);
}
if (!scriptName) {
process.stderr.write('ERROR: No script name provided!');
process.exit(1);
}
if (!pkg.betterScripts[scriptName]) {
process.stderr.write('ERROR: No betterScript with name "' + scriptName + '" was found!');
process.exit(1);
}
if(!program.silent) {
console.log('Executing script: ' + scriptName + '\n');
}
exec(pkg.betterScripts[scriptName], program, function (error, stdout, stderr) {
process.stderr.write(stderr);
process.stdout.write(stdout);
if(error !== null) {
console.log('exec error: '+error);
}
});