Created
September 11, 2013 21:04
-
-
Save j0hnsmith/6529758 to your computer and use it in GitHub Desktop.
Install node & npm in a Heroku Python project. The official Heroku Python buildpack now has (experimental) support for a pre_compile hook, this pre_compile script installs node & npm. Put it in bin/pre_compile in your project then npm packages in npm_requirements.txt will be installed automatically, conceptually similar to the way Python 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
#!/usr/bin/env bash | |
set -eo pipefail | |
NODE_VERSION=0.8.12 | |
NODE_BASENAME=node-v${NODE_VERSION}-linux-x64 | |
NODE_ARCHIVE="http://nodejs.org/dist/v${NODE_VERSION}/${NODE_BASENAME}.tar.gz" | |
curl -s -L -o tmp-nodejs.tar.gz $NODE_ARCHIVE | |
tar -zxvf tmp-nodejs.tar.gz > /dev/null | |
rm tmp-nodejs.tar.gz | |
export PATH=$NODE_BASENAME/bin:$PATH | |
echo "path" $PATH | |
echo "which node" `which node` | |
function indent() { | |
c='s/^/ /' | |
case $(uname) in | |
Darwin) sed -l "$c";; | |
*) sed -u "$c";; | |
esac | |
} | |
function run_npm_install_global() { | |
package="$1" | |
echo "-----> Installing" $package | |
npm install -g $package 2>&1 | indent | |
if [ "${PIPESTATUS[*]}" != "0 0" ]; then | |
echo " ! Failed to install dependencies with npm" | |
exit 1 | |
fi | |
} | |
# install dependencies with npm | |
echo "-----> Installing dependencies with npm" | |
for dependency in $(cat $BUILD_DIR/npm_requirements.txt) | |
do | |
run_npm_install_global $dependency | |
done | |
echo "Dependencies installed" | indent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment