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 ( ) ) ;
48var join = require ( 'path' ) . join ;
59var fullPackagePath = join ( process . cwd ( ) , 'package.json' ) ;
610var 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.
0 commit comments