Skip to content

Commit

Permalink
Cache node modules and meteor build
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Mar 29, 2018
1 parent c985dde commit c5358a3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ APP_CHECKOUT_DIR=$1
CACHE_DIR=$2
if [ -n "${BUILDPACK_CLEAR_CACHE+1}" ]; then
echo "-----> Clearing cache dir."
rm -rf "$CACHE_DIR/*"
rm -rf $CACHE_DIR/*
fi

#
Expand Down Expand Up @@ -171,7 +171,14 @@ echo "-----> and npm: `$METEOR_NPM --version`"
# If we use npm on root, run npm install. Don't use `--production` here, as we
# may need devDependencies (e.g. webpack) in order to build the meteor app.
if [ -e "$APP_SOURCE_DIR"/package.json ]; then
mkdir -p $CACHE_DIR/meteor-dev-modules
if [ -n "$(ls -A $CACHE_DIR/meteor-dev-modules)" ]; then
echo "-----> Reusing development node_modules cache"
mkdir -p $APP_SOURCE_DIR/node_modules
mv $CACHE_DIR/meteor-dev-modules/* $APP_SOURCE_DIR/node_modules
fi
$METEOR_NPM install
cp -a $APP_SOURCE_DIR/node_modules/* $CACHE_DIR/meteor-dev-modules/
fi

# Related to https://github.com/meteor/meteor/issues/2796 and
Expand All @@ -193,6 +200,12 @@ echo "-----> Building Meteor app with ROOT_URL: $ROOT_URL"
BUNDLE_DEST=`mktemp -d "$BUILDPACK_DIR/build-XXXX"`

# The actual invocation of `meteor build`!
mkdir -p $CACHE_DIR/meteor-build
rm -rf "$APP_SOURCE_DIR"/.meteor/local
if [ -n "$(ls -A $CACHE_DIR/meteor-build)" ]; then
echo "-----> Reusing meteor build cache"
fi
ln -s $CACHE_DIR/meteor-build "$APP_SOURCE_DIR"/.meteor/local
METEOR build $BUILD_OPTIONS --server $ROOT_URL $SERVER_ONLY_FLAG --directory $BUNDLE_DEST

echo "-----> Moving built slug to $COMPILE_DIR/app"
Expand All @@ -203,7 +216,14 @@ rmdir $BUNDLE_DEST
echo "-----> Installing npm production dependencies on built slug"
if [ -e "$COMPILE_DIR"/app/programs/server/package.json ]; then
cd "$COMPILE_DIR"/app/programs/server
mkdir -p $CACHE_DIR/meteor-prod-modules
if [ -n "$(ls -A $CACHE_DIR/meteor-prod-modules)" ]; then
echo "-----> Reusing production node_modules cache"
mkdir -p "$COMPILE_DIR"/app/programs/server/node_modules
mv $CACHE_DIR/meteor-prod-modules/* "$COMPILE_DIR"/app/programs/server/node_modules
fi
$METEOR_NPM install --production
cp -a "$COMPILE_DIR"/app/programs/server/node_modules/* $CACHE_DIR/meteor-prod-modules/
cd "$APP_SOURCE_DIR"
fi

Expand Down Expand Up @@ -235,5 +255,5 @@ done
#
if [ -n "${BUILDPACK_CLEAR_CACHE+1}" ]; then
echo "-----> Clearing cache dir."
rm -rf $METEOR_DIR
rm -rf $CACHE_DIR/*
fi

0 comments on commit c5358a3

Please sign in to comment.