File tree Expand file tree Collapse file tree 5 files changed +217
-0
lines changed Expand file tree Collapse file tree 5 files changed +217
-0
lines changed Original file line number Diff line number Diff line change 1+ .idea
2+ * .DS_Store
3+
4+ node_modules
5+ dist
6+ .tmp
7+ .sass-cache
8+ bower_components
9+ cache
10+
11+ # ########################################
12+ # https://gist.github.com/octocat/9257657
13+ # http://symfony.es/documentacion/como-configurar-bien-el-archivo-gitignore-para-las-aplicaciones-symfony2/
14+ # ########################################
15+
16+ # Compiled source #
17+ # ##################
18+ * .com
19+ * .class
20+ * .dll
21+ * .exe
22+ * .o
23+ * .so
24+
25+ # Packages #
26+ # ###########
27+ # it's better to unpack these files and commit the raw source
28+ # git has its own built in compression methods
29+ * .7z
30+ * .dmg
31+ * .gz
32+ * .iso
33+ * .jar
34+ * .rar
35+ * .tar
36+ * .zip
37+
38+ # Logs and databases #
39+ # #####################
40+ * .log
41+ * .sql
42+ * .sqlite
43+
44+ # OS generated files #
45+ # #####################
46+ .DS_Store
47+ .DS_Store ?
48+ ._ *
49+ .Spotlight-V100
50+ .Trashes
51+ Desktop.ini
52+ $RECYCLE.BIN /
53+ .AppleDouble
54+ .LSOverride
55+ ehthumbs.db
56+ Thumbs.db
57+
58+ # Editores #
59+ # ###########
60+ . * .sw [a-z ]
61+ * .un~
62+ Session.vim
63+ .netrwhist
64+ * .tmp
65+ * .bak
66+ * .swp
67+ /* .sublime-project
68+ * .sublime-workspace
69+ * .tmlanguage.cache
70+ * .tmPreferences.cache
71+ * .stTheme.cache
Original file line number Diff line number Diff line change 1+ # Intro
2+
3+ Better NPM scripts runner
4+
5+ - Avoid hard-coded commands in package.json
6+ - Cross-platform compatibility, originally needed by:
7+ - https://github.com/formly-js/angular-formly/issues/305
8+ - https://github.com/npm/npm/issues/2800
9+
10+ # Usage in package.json
11+
12+ From this:
13+ ```
14+ {
15+ "scripts": {
16+ "build:dist": "NODE_ENV=development webpack --config $npm_package_webpack --progress --colors",
17+ "test": "NODE_ENV=production karma start"
18+ }
19+ }
20+ ```
21+
22+ To this:
23+ ```
24+ {
25+ "devDependencies": {
26+ "better-npm-run": "~0.0.1"
27+ },
28+ "scripts": {
29+ "build:dist": "better-npm-run build:dist",
30+ "test": "better-npm-run test"
31+ },
32+ "betterScripts": {
33+ "build:dist": {
34+ "command": "webpack --config $npm_package_webpack --progress --colors",
35+ "env": {
36+ "NODE_ENV": "development"
37+ }
38+ },
39+ "build:prod": {
40+ "command": "webpack --config $npm_package_webpack --progress --colors",
41+ "env": {
42+ "NODE_ENV": "production"
43+ }
44+ },
45+ "build": [
46+ {
47+ "run": "build:dist"
48+ },
49+ {
50+ "run": "build:prod"
51+ }
52+ ],
53+ "test": {
54+ "command": "karma start",
55+ "env": {
56+ "NODE_ENV": "test"
57+ }
58+ }
59+ },
60+
61+ }
62+ ```
63+
64+ # Inspired by
65+
66+ - https://www.npmjs.com/package/with-package
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ console . log ( 'running better-npm-run in' , process . cwd ( ) ) ;
4+ var join = require ( 'path' ) . join ;
5+ var fullPackagePath = join ( process . cwd ( ) , 'package.json' ) ;
6+ var pkg = require ( fullPackagePath ) ;
7+ var exec = require ( './lib/exec.js' )
8+
9+ if ( ! pkg . scripts ) {
10+ process . stderr . write ( 'ERROR: No scripts found!' ) ;
11+ process . exit ( 1 ) ;
12+ }
13+ if ( ! pkg . betterScripts ) {
14+ process . stderr . write ( 'ERROR: No betterScripts found!' ) ;
15+ process . exit ( 1 ) ;
16+ }
17+ if ( ! process . argv [ 2 ] ) {
18+ process . stderr . write ( 'ERROR: No script name provided!' ) ;
19+ process . exit ( 1 ) ;
20+ }
21+ if ( ! pkg . betterScripts [ process . argv [ 2 ] ] ) {
22+ process . stderr . write ( 'ERROR: No betterScript with name "' + process . argv [ 2 ] + '" was found!' ) ;
23+ process . exit ( 1 ) ;
24+ }
25+
26+ console . log ( 'Executing script: ' + process . argv [ 2 ] + '\n' ) ;
27+
28+ exec ( pkg . betterScripts [ process . argv [ 2 ] ] ) ;
Original file line number Diff line number Diff line change 1+ var child_exec = require ( 'child_process' ) . exec ;
2+
3+ module . exports = function exec ( script ) {
4+
5+ var command_line = script . command ;
6+
7+ Object . keys ( script . env ) . forEach ( function ( key ) {
8+ var value = script . env [ key ] ;
9+
10+ if ( process . platform === 'win32' ) {
11+ command_line = 'set ' + key + '=' + script . env [ key ] + '&& ' + command_line ;
12+ } else {
13+ command_line = key + '=' + script . env [ key ] + ' ' + command_line ;
14+ }
15+ } ) ;
16+
17+ console . log ( 'to be executed:' + command_line ) ;
18+ var command = child_exec ( command_line ) ;
19+
20+ command . stdout . on ( 'data' , function ( data ) {
21+ process . stdout . write ( data ) ;
22+ } ) ;
23+ command . stderr . on ( 'data' , function ( data ) {
24+ process . stderr . write ( data ) ;
25+ } ) ;
26+ command . on ( 'error' , function ( err ) {
27+ process . stderr . write ( err ) ;
28+ } ) ;
29+
30+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " better-npm-run" ,
3+ "description" : " Better NPM scripts runner" ,
4+ "version" : " 0.0.1" ,
5+ "license" : " MIT" ,
6+ "author" :
" Benjamin Orozco <[email protected] >" ,
7+ "contributors" : [
8+ " Benjamin Orozco <[email protected] >" ,
9+ " Kent C. Dodds <[email protected] >" 10+ ],
11+ "repository" : {
12+ "type" : " git" ,
13+ "url" : " git://github.com/benoror/better-npm-run.git"
14+ },
15+ "main" : " index.js" ,
16+ "bin" : {
17+ "better-npm-run" : " index.js"
18+ },
19+ "scripts" : {
20+ "test" : " echo \" Error: no test specified\" && exit 1"
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments