AWS publish tasks
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "~0.2.9",
|
||||
"aws-sdk": "~1.5.0",
|
||||
"benchmark": "~1.0",
|
||||
"dustjs-linkedin": "~2.0.2",
|
||||
"eco": "~1.1.0-rc-3",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user