[ -e "tmp/dist" ] && rm -rf tmp/dist
mkdir -p tmp/dist
-# Collapse the serve trees into one directory
+### Collapse the serve trees into one directory
log "Collapsing serve trees..."
+
+# Copy the static files, derived files, and the whole data directory (bc lack of trailing /)
+# into dist. Note that you will need to load all the site pages in your browser to populate var
+# with the derived files.
rsync -Ca static/ var/ data tmp/dist/
+
+# We copy lib (which contains .co source files) to src to make it easy to link source content
+# to each other. Finding it in gitweb is a pain. Finding it in gerrit is almost impossible.
+# But this could go away when we move to github.
rsync -Ca lib/ tmp/dist/src/
-# browserify -o tmp/dist/vendor/browserify.js -r events -r seq
+
+# For some reason, the shell tool does not generate a file identical to the middleware. So whatever.
+# We curl here because we know that version works.
curl --silent --fail --url http://$DEV_HOST/vendor/browserify.js > tmp/dist/vendor/browserify.js
+# browserify -o tmp/dist/vendor/browserify.js -r events -r seq
+
log "ok!"
-# Bundle Vendor JS Bundle
+### Bundle Vendor JS Bundle
target=tmp/dist/vendor/vendor-bundle.min.js
log "Building Vendor Bundle ($target) ..."
for js in $(coke source_list | grep vendor); do
log "ok!"
-# Build App JS Bundle
+### Build App JS Bundle
+
target=tmp/dist/js/kraken/app-bundle
uglifyjs=$(which uglifyjs || echo "node_modules/uglify-js/bin/uglifyjs")
log "Building App JS Bundle (${target}.js) ..."
# TODO: bundle CSS
-# Finally, deploy the files
+### Finally, deploy the files
log "Deploying files..."
-# fix ownership and permissions before and after rsync.
+
+# Fix ownership and permissions before and after rsync.
fix_permissions
log "rsync -Caz $VERBOSE $DRY_RUN tmp/dist $DEPLOY_HOST:$DEPLOY_PATH"
rsync -Crz $VERBOSE $DRY_RUN tmp/dist $DEPLOY_HOST:$DEPLOY_PATH
fix_permissions
log "ok!"
+### Inform Supervisor to restart Node
if [ "$RESTART_SERVER" ]; then
log "Restarting Reportcard Server post-deploy..."
log "ssh -t $DEPLOY_HOST 'sudo supervisorctl restart reportcard'"