summaryrefslogtreecommitdiffstats
path: root/tasks
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-08-25 12:51:17 -0500
committerkpdecker <kpdecker@gmail.com>2013-08-25 12:51:17 -0500
commitda3788384b4d7e632bde58c92a3a8c8ab6da197c (patch)
tree3342dfe18d4d6f4c5865844337a3c3ca943a61e9 /tasks
parent5aacdadff8e9cce935899f056a3090c231b5558f (diff)
downloadhandlebars.js-da3788384b4d7e632bde58c92a3a8c8ab6da197c.zip
handlebars.js-da3788384b4d7e632bde58c92a3a8c8ab6da197c.tar.gz
handlebars.js-da3788384b4d7e632bde58c92a3a8c8ab6da197c.tar.bz2
AWS publish tasks
Diffstat (limited to 'tasks')
-rw-r--r--tasks/publish.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/tasks/publish.js b/tasks/publish.js
new file mode 100644
index 0000000..9c3d1d6
--- /dev/null
+++ b/tasks/publish.js
@@ -0,0 +1,69 @@
+var _ = require('underscore'),
+ async = require('async'),
+ AWS = require('aws-sdk'),
+ git = require('./util/git');
+
+module.exports = function(grunt) {
+ grunt.registerTask('publish', function() {
+ var done = this.async();
+ initSDK();
+
+ git.commitInfo(function(err, info) {
+ if (info.isMaster) {
+ publish(fileMap(['-latest', '-' + info.head]), done);
+ } else {
+ // Silently ignore for branches
+ done();
+ }
+ });
+ });
+ grunt.registerTask('publish:version', function() {
+ var done = this.async();
+ initSDK();
+
+ git.commitInfo(function(err, info) {
+ if (!info.tagName) {
+ throw new Error('The current commit must be tagged');
+ }
+ publish(fileMap(['-' + info.tagName]), done);
+ });
+ });
+
+ function initSDK() {
+ var bucket = process.env.S3_BUCKET_NAME,
+ key = process.env.S3_ACCESS_KEY_ID,
+ secret = process.env.S3_SECRET_ACCESS_KEY;
+
+ if (!bucket || !key || !secret) {
+ throw new Error('Missing S3 config values');
+ }
+
+ AWS.config.update({accessKeyId: key, secretAccessKey: secret});
+ }
+ function publish(files, callback) {
+ var s3 = new AWS.S3(),
+ bucket = process.env.S3_BUCKET_NAME;
+
+ async.forEach(_.keys(files), function(file, callback) {
+ var params = {Bucket: bucket, Key: file, Body: grunt.file.read(files[file])};
+ s3.putObject(params, function(err, data) {
+ if (err) {
+ throw err;
+ } else {
+ grunt.log.writeln('Published ' + file + ' to build server.');
+ callback();
+ }
+ });
+ },
+ callback);
+ }
+ function fileMap(suffixes) {
+ var map = {};
+ _.each(['handlebars.js', 'handlebars.min.js', 'handlebars.runtime.js', 'handlebars.runtime.min.js'], function(file) {
+ _.each(suffixes, function(suffix) {
+ map[file.replace(/\.js$/, suffix + '.js')] = 'dist/' + file;
+ });
+ });
+ return map;
+ }
+};