Created
July 2, 2012 19:56
-
-
Save JamesKyburz/3035320 to your computer and use it in GitHub Desktop.
npm install --save --devonly
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
#!/usr/bin/env bash | |
if command -v npm-$1 > /dev/null | |
then | |
npm-$1 ${@:2} | |
else | |
TMP1=`mktemp /tmp/tmp.XXXXXX` | |
trap "rm -f $TMP1" SIGINT SIGTERM SIGHUP SIGQUIT | |
cat <<'__END__' > $TMP1 | |
hasParameter = (param) -> (x for x in process.argv when x is param).length is 1 | |
assets = (asset for asset in process.argv[3..] when !/^--/.test asset) | |
save = hasParameter '--save' | |
devonly = hasParameter '--devonly' | |
uninstall = hasParameter 'uninstall' | |
fs = require 'fs' | |
exec = require('child_process').exec | |
exec "npm #{process.argv[2..].join(' ')}", (err, stdout, stderr) -> | |
for x in [err, stdout, stderr] | |
console.log x if x | |
unless err | |
fs.readFile './package.json', 'utf8', (err, data) -> | |
throw err if err | |
json = JSON.parse data | |
if save | |
for asset in assets | |
json["devDependencies"][asset] = json["dependencies"][asset] | |
delete json["dependencies"][asset] | |
if uninstall && save | |
for asset in assets | |
delete json["dependencies"][asset] | |
delete json["devDependencies"][asset] | |
fs.writeFile './package.json', JSON.stringify(json, null, 2), 'utf-8', (err) -> | |
throw err if err | |
__END__ | |
coffee $TMP1 $@ | |
rm -f $TMP1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment