Skip to content

Commit bc7b263

Browse files
committed
Silent mode feature added. Closing #60
Running with -s or --silent flag now will silence not only npm noise but also info messages of better-npm-run itself.
1 parent cd69d87 commit bc7b263

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,9 @@ using the shorter alias
122122
"dev": "shell-exec 'bnr install-hooks' 'bnr watch-client' 'bnr start-dev' 'bnr start-dev-api' 'bnr start-dev-worker' 'bnr start-dev-socket'",
123123
}
124124
```
125+
126+
Also for silence output, you can use `-s` or verbose `--silence` flags
127+
128+
```
129+
bnr watch-client -s
130+
```

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env node
22

3-
console.log('running better-npm-run in', process.cwd());
3+
var scriptName = process.argv[2];
4+
5+
var isSilent = process.argv.indexOf('-s') > -1 || process.argv.indexOf('--silent') > -1;
6+
7+
isSilent || console.log('running better-npm-run in', process.cwd());
48
var join = require('path').join;
59
var fullPackagePath = join(process.cwd(), 'package.json');
610
var pkg = require(fullPackagePath);
@@ -14,21 +18,28 @@ if (!pkg.betterScripts) {
1418
process.stderr.write('ERROR: No betterScripts found!');
1519
process.exit(1);
1620
}
17-
if (!process.argv[2]) {
21+
if (!scriptName) {
1822
process.stderr.write('ERROR: No script name provided!');
1923
process.exit(1);
2024
}
21-
if (!pkg.betterScripts[process.argv[2]]) {
22-
process.stderr.write('ERROR: No betterScript with name "'+process.argv[2]+'" was found!');
25+
if (!pkg.betterScripts[scriptName]) {
26+
process.stderr.write('ERROR: No betterScript with name "'+scriptName+'" was found!');
2327
process.exit(1);
2428
}
2529

26-
console.log('Executing script: ' + process.argv[2] + '\n');
2730

28-
exec(pkg.betterScripts[process.argv[2]], function (error, stdout, stderr) {
31+
isSilent || console.log('Executing script: ' + scriptName + '\n');
32+
33+
34+
exec(pkg.betterScripts[scriptName], isSilent, function (error, stdout, stderr) {
2935
process.stderr.write(stderr);
3036
process.stdout.write(stdout);
3137
if(error !== null) {
3238
console.log('exec error: '+error);
3339
}
3440
});
41+
42+
//
43+
// Silent mode feature added. Closing #60
44+
//
45+
// Running with -s or --silent flag will silence not only npm noise but also info messages of better-npm-run itself.

lib/exec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require('dotenv').config({silent: true});
33
var spawn = require('child_process').spawn;
44
var objectAssign = require('object-assign');
55

6-
module.exports = function exec(script) {
6+
module.exports = function exec(script, isSilent) {
77

88
var argv = process.argv.splice(3);
99
var command = (typeof script === 'string' ? script : script.command) + ' ' + argv.join(' ');
@@ -19,7 +19,7 @@ module.exports = function exec(script) {
1919
command = '"' + command.trim() + '"';
2020
}
2121

22-
console.log('to be executed:', command);
22+
isSilent || console.log('to be executed:', command);
2323
spawn(sh, [shFlag, command], {
2424
env: env,
2525
windowsVerbatimArguments: process.platform === 'win32',
@@ -28,4 +28,4 @@ module.exports = function exec(script) {
2828
process.exit(code);
2929
});
3030

31-
}
31+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test:params": "node index.js test:params --test",
2424
"test:command:object": "node index.js test:command:object",
2525
"test:command:string": "node index.js test:command:string",
26+
"test:silent": "node index.js test:command:object -s && node index.js test:command:object --silent",
2627
"test": "npm run test:env && npm run test:env-extend && npm run test:params && npm run test:command:object && npm run test:command:string"
2728
},
2829
"dependencies": {

0 commit comments

Comments
 (0)