Created
November 8, 2014 20:27
-
-
Save tmlbl/c3b60b5ab5ca97f91f8e to your computer and use it in GitHub Desktop.
Task runner utilities fr JS project
This file contains hidden or 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
#!/bin/bash | |
# Run in mock production mode with docker | |
dockerEnv() { | |
mkdir -p images; | |
printf "Starting the mongodb container...\n"; | |
docker run -d --name="spacedb" beshippable/dbbase; | |
printf "Starting the application container...\n"; | |
docker run -v $(pwd):/app -p 8080:8080 -v $(pwd)/images:/img \ | |
--name="spacecam" -e NODE_ENV=prod --link spacedb:db \ | |
tmlbl/node node /app/server.js; | |
docker rm -f spacecam spacedb; | |
} | |
# Concatenate and uglify the source files | |
catAndUglify() { | |
printf "Concatenating and minifying source files...\n"; | |
mkdir -p public/dist; | |
cat public/js/shim.js public/js/detect.js \ | |
public/js/report.js public/js/init.js \ | |
public/js/indexCtrl.js | node_modules/.bin/uglifyjs -m \ | |
-o public/dist/app.min.js; | |
} | |
# Builds the docker image | |
buildImage() { | |
printf "Building the docker image...\n"; | |
docker build -t tmlbl/spacecam .; | |
} | |
# Runs a local server with nodemon | |
localServer() { | |
printf "Bringing up the development server...\n"; | |
export NODE_ENV=dev; | |
export DB_PORT='tcp://localhost:27017'; | |
node_modules/.bin/nodemon server.js; | |
} | |
if [ "$1" = "dist" ]; then | |
catAndUglify; | |
buildImage; | |
elif [ "$1" = "dev" ]; then | |
localServer; | |
elif [ "$1" = "docker" ]; then | |
catAndUglify; | |
dockerEnv; | |
else | |
printf "usage:\n\tdocker: run in mock production mode with docker\n"; | |
printf "\tdev: run simply with nodemon\n"; | |
printf "\tdist: prepare source files and build docker image\n"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment