Commit 5085334c authored by Tom Spencer's avatar Tom Spencer

Added heroku prebuild and postbuild scripts

parent a8cf29ac
......@@ -118,11 +118,14 @@ header "Restoring cache"
restore_cache | output "$LOG_FILE"
build_dependencies() {
local has_prebuild_script=$(read_json "$BUILD_DIR/package.json" ".scripts[\"heroku-prebuild\"]")
local has_postbuild_script=$(read_json "$BUILD_DIR/package.json" ".scripts[\"heroku-postbuild\"]")
if $PREBUILD; then
echo "Prebuild detected (node_modules already exists)"
rebuild_node_modules "$BUILD_DIR"
rebuild_node_modules "$BUILD_DIR" "$has_prebuild_script" "$has_postbuild_script"
else
install_node_modules "$BUILD_DIR"
install_node_modules "$BUILD_DIR" "$has_prebuild_script" "$has_postbuild_script"
fi
}
......
install_node_modules() {
local build_dir=${1:-}
local has_prebuild_script=${2:-}
local has_postbuild_script=${3:-}
if [ -e $build_dir/package.json ]; then
cd $build_dir
if [ -n "$has_prebuild_script" ]; then
echo "Running prebuild script"
npm run heroku-prebuild
fi
echo "Pruning any extraneous modules"
npm prune --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
if [ -e $build_dir/npm-shrinkwrap.json ]; then
......@@ -11,6 +17,10 @@ install_node_modules() {
echo "Installing node modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
if [ -n "$has_postbuild_script" ]; then
echo "Running postbuild script"
npm run heroku-postbuild
fi
else
echo "Skipping (no package.json)"
fi
......@@ -18,9 +28,15 @@ install_node_modules() {
rebuild_node_modules() {
local build_dir=${1:-}
local has_prebuild_script=${2:-}
local has_postbuild_script=${3:-}
if [ -e $build_dir/package.json ]; then
cd $build_dir
if [ -n "$has_prebuild_script" ]; then
echo "Running prebuild script"
npm run heroku-prebuild
fi
echo "Rebuilding any native modules"
npm rebuild 2>&1
if [ -e $build_dir/npm-shrinkwrap.json ]; then
......@@ -29,6 +45,10 @@ rebuild_node_modules() {
echo "Installing any new modules (package.json)"
fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
if [ -n "$has_postbuild_script" ]; then
echo "Running postbuild script"
npm run heroku-postbuild
fi
else
echo "Skipping (no package.json)"
fi
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "~0.10.0"
},
"scripts" : {
"heroku-prebuild" : "echo heroku-prebuild hook message",
"heroku-postbuild" : "echo heroku-postbuild hook message"
}
}
......@@ -471,6 +471,15 @@ testMultiExport() {
assertCapturedSuccess
}
testPrePostBuildScripts() {
compile "pre-post-build-scripts"
assertCaptured "Running prebuild script"
assertCaptured "echo heroku-prebuild hook message"
assertCaptured "Running postbuild script"
assertCaptured "echo heroku-postbuild hook message"
assertCapturedSuccess
}
# Utils
pushd $(dirname 0) >/dev/null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment