Update build with changes from crafting-guide.com

This commit is contained in:
Andrew Miner
2016-04-03 21:50:52 -07:00
parent 3ae13b5acd
commit c5012e8b5b
4 changed files with 99 additions and 53 deletions
+69 -9
View File
@@ -1,12 +1,9 @@
###
# Crafting Guide - Gruntfile.coffee
# #
# Copyright (c) 2014 by Redwood Labs # Copyright © 2015 by Redwood Labs
# All rights reserved. # All rights reserved.
### #
fs = require 'fs' fs = require 'fs'
util = require 'util'
######################################################################################################################## ########################################################################################################################
@@ -15,6 +12,29 @@ module.exports = (grunt)->
grunt.loadTasks tasks for tasks in grunt.file.expand './node_modules/grunt-*/tasks' grunt.loadTasks tasks for tasks in grunt.file.expand './node_modules/grunt-*/tasks'
grunt.config.init grunt.config.init
compress:
static:
options:
mode: 'gzip'
files: [
{expand: true, cwd:'./build/static', src:'**/*.cg', dest:'./dist/'}
]
copy:
data:
files: [
{expand:true, cwd:'./data/', src:'**/*', dest:'./build/'}
]
build_to_dist:
files: [
{expand:true, cwd:'./build/', src:'**/*', dest:'./dist/'}
]
clean:
build: ['./build']
dist: ['./dist']
mochaTest: mochaTest:
options: options:
bail: true bail: true
@@ -32,11 +52,33 @@ module.exports = (grunt)->
files: ['./data/**/*.cg'] files: ['./data/**/*.cg']
tasks: ['mochaTest'] tasks: ['mochaTest']
grunt.registerTask 'default', 'build' # Compound Tasks ###################################################################################################
grunt.registerTask 'build', [ ] grunt.registerTask 'build', 'build the project to be run from a local server',
['copy:data']
grunt.registerTask 'dist', [ 'test' ] grunt.registerTask 'default', 'run tests to verify data files',
['test']
grunt.registerTask 'deploy:prod', 'deploy the project to production via CircleCI',
['script:deploy:prod']
grunt.registerTask 'deploy:staging', 'deploy the project to staging via CircleCI',
['script:deploy:staging']
grunt.registerTask 'dist', 'build the project to be run from Amazon S3',
['build', 'copy:build_to_dist', 'compress']
grunt.registerTask 'test', 'run unit tests',
['mochaTest']
grunt.registerTask 'upload:prod', 'upload the project to the production Amazon S3 environment',
['dist', 'script:s3_upload:prod']
grunt.registerTask 'upload:staging', 'upload the project the staging Amazon S3 environment',
['dist', 'script:s3_upload:staging']
# Code Tasks #######################################################################################################
grunt.registerTask 'use-local-deps', -> grunt.registerTask 'use-local-deps', ->
grunt.file.mkdir './node_modules' grunt.file.mkdir './node_modules'
@@ -45,7 +87,25 @@ module.exports = (grunt)->
fs.symlinkSync '../../crafting-guide/', './node_modules/crafting-guide' fs.symlinkSync '../../crafting-guide/', './node_modules/crafting-guide'
fs.symlinkSync '../../crafting-guide-common/', './node_modules/crafting-guide-common' fs.symlinkSync '../../crafting-guide-common/', './node_modules/crafting-guide-common'
grunt.registerTask 'test', ['mochaTest'] # Script Tasks #####################################################################################################
grunt.registerTask 'script:deploy:prod', "deploy code by copying to the production branch", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/deploy', args:['--production'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:deploy:staging', "deploy code by copying to the staging branch", ->
done = this.async()
grunt.util.spawn cmd:'./scripts/deploy', args:['--staging'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:s3_upload:prod', 'uploads all static content to S3', ->
done = this.async()
grunt.util.spawn cmd:'./scripts/s3_upload', args:['--prod'], opts:{stdio:'inherit'}, (error)-> done(error)
grunt.registerTask 'script:s3_upload:staging', 'uploads all static content to S3', ->
done = this.async()
grunt.util.spawn cmd:'./scripts/s3_upload', args:['--staging'], opts:{stdio:'inherit'}, (error)-> done(error)
# Command-Line Argument Processing #################################################################################
args = process.argv[..] args = process.argv[..]
while args.length > 0 while args.length > 0
+10 -2
View File
@@ -1,5 +1,13 @@
dependencies:
pre:
- sudo -H pip install s3cmd
- npm install -g grunt-cli
deployment: deployment:
all: staging:
branch: master branch: master
commands: commands:
- ./scripts/deploy --staging && ./scripts/deploy --production - grunt upload:staging
production:
branch: master
commands:
- grunt upload:prod
+14 -18
View File
@@ -6,35 +6,31 @@ else
export AWS_CONFIG_FILE="$HOME/.aws/config" export AWS_CONFIG_FILE="$HOME/.aws/config"
fi fi
SOURCE_DIR="./data/" ENVIRONMENT=""
SITE="crafting-guide.com"
TARGET=""
while [[ "$1" != "" ]]; do while [[ "$1" != "" ]]; do
case "$1" in case "$1" in
"--staging") TARGET="staging";; "--staging") ENVIRONMENT="staging";;
"--production") TARGET="production";; "--production") ENVIRONMENT="production";;
*) die "Please specify environment: --staging or --production";;
esac esac
shift shift
done done
if [[ "$TARGET" == "" ]]; then SOURCE_DIR="./dist/"
echo "Please choose either --staging or --production for the target." SITE="staging.crafting-guide.com"
exit 1 [[ "$ENVIRONMENT" == "production" ]] && SITE="crafting-guide.com"
fi TARGET_DIR="s3://$SITE/"
if [[ "$TARGET" == "staging" ]]; then
TARGET_DIR="s3://new.$SITE/data/"
elif [[ "$TARGET" == "production" ]]; then
TARGET_DIR="s3://$SITE/data/"
fi
S3CMD_CFG="$HOME/.s3cfg" S3CMD_CFG="$HOME/.s3cfg"
if [[ ! -e "$S3CMD_CFG" ]]; then
echo "[default]" > "$S3CMD_CFG" echo "[default]" > "$S3CMD_CFG"
cat $AWS_CONFIG_FILE | grep "aws_access_key_id" | sed "s/aws_access_key_id/access_key/" >> "$S3CMD_CFG" cat $AWS_CONFIG_FILE | grep "aws_access_key_id" | sed "s/aws_access_key_id/access_key/" >> "$S3CMD_CFG"
cat $AWS_CONFIG_FILE | grep "aws_secret_access_key" | sed "s/aws_secret_access_key/secret_key/" >> "$S3CMD_CFG" cat $AWS_CONFIG_FILE | grep "aws_secret_access_key" | sed "s/aws_secret_access_key/secret_key/" >> "$S3CMD_CFG"
fi
HEADERS="--add-header=cache-control:max-age=1800"
GZIP="--add-header=content-encoding:gzip"
CMD="sync $SOURCE_DIR $TARGET_DIR -r -P $HEADERS --stop-on-error --exclude=*"
echo "Preparing to upload to S3..." echo "Preparing to upload to S3..."
s3cmd sync -r -P --add-header="cache-control:max-age=1800" $SOURCE_DIR $TARGET_DIR s3cmd $CMD -m 'image/png' --include="*.png" || exit 1
s3cmd $CMD $GZIP -m 'text/plain' --include="*.cg" || exit 1
echo "S3 Upload Complete" echo "S3 Upload Complete"
-18
View File
@@ -1,18 +0,0 @@
#!/bin/bash
MODULE=$(basename $PWD)
QUIET="NO"
while [[ "$1" != "" ]]; do
case "$1" in
"-q") QUIET="YES";;
esac
shift
done
CHANGES=$(git log --oneline origin/master..master | while read LINE; do echo " $LINE"; done)
if [[ "$CHANGES" != "" ]]; then
printf "\nUnpublished changes for $MODULE:\n$CHANGES\n\n"
elif [[ "$QUIET" == "NO" ]]; then
printf "No unpublished changes for $MODULE\n\n"
fi