-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 65a5b01
Showing
5 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.idea | ||
*.DS_Store | ||
|
||
node_modules | ||
dist | ||
.tmp | ||
.sass-cache | ||
bower_components | ||
cache | ||
|
||
######################################### | ||
# https://gist.github.com/octocat/9257657 | ||
# http://symfony.es/documentacion/como-configurar-bien-el-archivo-gitignore-para-las-aplicaciones-symfony2/ | ||
######################################### | ||
|
||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
Desktop.ini | ||
$RECYCLE.BIN/ | ||
.AppleDouble | ||
.LSOverride | ||
ehthumbs.db | ||
Thumbs.db | ||
|
||
# Editores # | ||
############ | ||
.*.sw[a-z] | ||
*.un~ | ||
Session.vim | ||
.netrwhist | ||
*.tmp | ||
*.bak | ||
*.swp | ||
/*.sublime-project | ||
*.sublime-workspace | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Intro | ||
|
||
Better NPM scripts runner | ||
|
||
- Avoid hard-coded commands in package.json | ||
- Cross-platform compatibility, originally needed by: | ||
- https://github.com/formly-js/angular-formly/issues/305 | ||
- https://github.com/npm/npm/issues/2800 | ||
|
||
# Usage in package.json | ||
|
||
From this: | ||
``` | ||
{ | ||
"scripts": { | ||
"build:dist": "NODE_ENV=development webpack --config $npm_package_webpack --progress --colors", | ||
"test": "NODE_ENV=production karma start" | ||
} | ||
} | ||
``` | ||
|
||
To this: | ||
``` | ||
{ | ||
"devDependencies": { | ||
"better-npm-run": "~0.0.1" | ||
}, | ||
"scripts": { | ||
"build:dist": "better-npm-run build:dist", | ||
"test": "better-npm-run test" | ||
}, | ||
"betterScripts": { | ||
"build:dist": { | ||
"command": "webpack --config $npm_package_webpack --progress --colors", | ||
"env": { | ||
"NODE_ENV": "development" | ||
} | ||
}, | ||
"build:prod": { | ||
"command": "webpack --config $npm_package_webpack --progress --colors", | ||
"env": { | ||
"NODE_ENV": "production" | ||
} | ||
}, | ||
"build": [ | ||
{ | ||
"run": "build:dist" | ||
}, | ||
{ | ||
"run": "build:prod" | ||
} | ||
], | ||
"test": { | ||
"command": "karma start", | ||
"env": { | ||
"NODE_ENV": "test" | ||
} | ||
} | ||
}, | ||
} | ||
``` | ||
|
||
# Inspired by | ||
|
||
- https://www.npmjs.com/package/with-package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
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 (!process.argv[2]) { | ||
process.stderr.write('ERROR: No script name provided!'); | ||
process.exit(1); | ||
} | ||
if (!pkg.betterScripts[process.argv[2]]) { | ||
process.stderr.write('ERROR: No betterScript with name "'+process.argv[2]+'" was found!'); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Executing script: ' + process.argv[2] + '\n'); | ||
|
||
exec(pkg.betterScripts[process.argv[2]]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var child_exec = require('child_process').exec; | ||
|
||
module.exports = function exec(script) { | ||
|
||
var command_line = script.command; | ||
|
||
Object.keys(script.env).forEach(function (key) { | ||
var value = script.env[key]; | ||
|
||
if(process.platform === 'win32') { | ||
command_line = 'set ' + key + '=' + script.env[key] + '&& ' + command_line; | ||
} else { | ||
command_line = key + '=' + script.env[key] + ' ' + command_line; | ||
} | ||
}); | ||
|
||
console.log('to be executed:' + command_line); | ||
var command = child_exec(command_line); | ||
|
||
command.stdout.on('data', function(data) { | ||
process.stdout.write(data); | ||
}); | ||
command.stderr.on('data', function(data) { | ||
process.stderr.write(data); | ||
}); | ||
command.on('error', function(err) { | ||
process.stderr.write(err); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "better-npm-run", | ||
"description": "Better NPM scripts runner", | ||
"version": "0.0.1", | ||
"license": "MIT", | ||
"author": "Benjamin Orozco <[email protected]>", | ||
"contributors": [ | ||
"Benjamin Orozco <[email protected]>", | ||
"Kent C. Dodds <[email protected]>" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/benoror/better-npm-run.git" | ||
}, | ||
"main": "index.js", | ||
"bin": { | ||
"better-npm-run": "index.js" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
} | ||
} |