From b82bcfbd471d8ebab32d0736ca806fec1fa6bf91 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 25 Nov 2010 01:42:24 -0800 Subject: [PATCH] A package.json install that works. It's an ugly hack, but it works. --- install.sh | 24 ++++++++++++++++++++++++ package.json | 3 ++- uninstall.sh | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 install.sh create mode 100755 uninstall.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8ad7d20 --- /dev/null +++ b/install.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +dir=$npm_config_root/.npm/$npm_package_name/$npm_package_version/package + +# add lines to the bashrc. +has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true) +if [ "x$has" != "x" ]; then + exit 0 +fi +cat <>~/.bashrc +# ADDED BY npm FOR NVM +NVM_DIR=$dir +. \$NVM_DIR/nvm.sh +nvm use +# END ADDED BY npm FOR NVM +NVM_CODE + +cat <" +, "scripts" : + { "install" : "./install.sh" , "uninstall" : "./uninstall.sh" } } diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..a139d2c --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,23 @@ +#!/bin/bash + + +has=$(cat ~/.bashrc | egrep "^# ADDED BY npm FOR NVM$" || true) +if [ "x$has" == "x" ]; then + echo "doesn't have it, exiting" + exit 0 +fi +tmp=~/.bashrc.tmp +cat ~/.bashrc | { + incode=0 + while read line; do + if [ "$line" == "# ADDED BY npm FOR NVM" ]; then + incode=1 + elif [ "$line" == "# END ADDED BY npm FOR NVM" ] \ + && [ $incode -eq 1 ]; then + incode=0 + elif [ $incode -eq 0 ]; then + echo "$line" >> $tmp + fi + done +} +mv $tmp ~/.bashrc