Permalink
Browse files

Updating build for automatic deploys

  • Loading branch information...
1 parent f0b513d commit ddc93d2599cc4c4cd6336ce6bda29efb9fb10492 @daffl daffl committed Nov 13, 2012
Showing with 304 additions and 32 deletions.
  1. +1 −0 .gitignore
  2. +63 −0 build/downloads.json
  3. +103 −0 build/tasks/downloads.js
  4. +1 −1 build/tasks/shell.js
  5. +3 −2 build/tasks/strip.js
  6. +115 −8 build/tasks/utils.js
  7. +14 −20 grunt.js
  8. +4 −1 package.json
View
@@ -11,3 +11,4 @@ docs*
build/ci/can
build/ci/funcunit
build/ci/steal
+build/gh-pages
View
@@ -0,0 +1,63 @@
+{
+ "jquery": {
+ "src": "dist/<%= pkg.version %>/can.jquery.js",
+ "description": "Can jQuery <%= pkg.version %> Development",
+ "filename": "can.jquery-<%= pkg.version %>.js"
+ },
+ "jqueryMin": {
+ "src": "dist/<%= pkg.version %>/can.jquery.min.js",
+ "description": "Can jQuery <%= pkg.version %> Production",
+ "filename": "can.jquery-<%= pkg.version %>.min.js"
+ },
+ "zepto": {
+ "src": "dist/<%= pkg.version %>/can.zepto.js",
+ "description": "Can Zepto <%= pkg.version %> Development",
+ "filename": "can.zepto-<%= pkg.version %>.js"
+ },
+ "zeptoMin": {
+ "src": "dist/<%= pkg.version %>/can.zepto.min.js",
+ "description": "Can Zepto <%= pkg.version %> Production",
+ "filename": "can.zepto-<%= pkg.version %>.min.js"
+ },
+ "yui": {
+ "src": "dist/<%= pkg.version %>/can.yui.js",
+ "description": "Can YUI <%= pkg.version %> Development",
+ "filename": "can.yui-<%= pkg.version %>.js"
+ },
+ "yuiMin": {
+ "src": "dist/<%= pkg.version %>/can.yui.min.js",
+ "description": "Can YUI <%= pkg.version %> Production",
+ "filename": "can.yui-<%= pkg.version %>.min.js"
+ },
+ "mootools": {
+ "src": "dist/<%= pkg.version %>/can.mootools.js",
+ "description": "Can Mootools <%= pkg.version %> Development",
+ "filename": "can.mootools-<%= pkg.version %>.js"
+ },
+ "mootoolsMin": {
+ "src": "dist/<%= pkg.version %>/can.mootools.min.js",
+ "description": "Can Mootools <%= pkg.version %> Production",
+ "filename": "can.mootools-<%= pkg.version %>.min.js"
+ },
+ "dojo": {
+ "src": "dist/<%= pkg.version %>/can.dojo.js",
+ "description": "Can Dojo <%= pkg.version %> Development",
+ "filename": "can.dojo-<%= pkg.version %>.js"
+ },
+ "dojoMin": {
+ "src": "dist/<%= pkg.version %>/can.dojo.min.js",
+ "description": "Can Dojo <%= pkg.version %> Production",
+ "filename": "can.dojo-<%= pkg.version %>.min.js"
+ },
+ "dist" : {
+ "src" : "dist/can.js.<%= pkg.version %>.zip",
+ "description" : "CanJS <%= pkg.version %>",
+ "filename" : "can.js.<%= pkg.version %>.zip",
+ "content_type" : "application/zip"
+ },
+ "_options" : {
+ "repository" : "canjs",
+ "user" : "bitovi",
+ "overwrite" : true
+ }
+}
View
@@ -0,0 +1,103 @@
+var program = require("commander");
+var GitHubApi = require("github");
+var authenticated = false;
+var fs = require('fs');
+var github = new GitHubApi({
+ version : "3.0.0"
+});
+var getCredentials = function (callback) {
+ if(authenticated) {
+ return callback();
+ }
+
+ program.prompt("Github Username: ", function (name) {
+ var username = name;
+
+ program.password("Github Password: ", "*", function (pass) {
+ var password = pass;
+ process.stdin.pause();
+ github.authenticate({
+ type : "basic",
+ username : username,
+ password : password
+ });
+ authenticated = true;
+ callback();
+ });
+
+ });
+}
+
+module.exports = function (grunt) {
+ grunt.registerMultiTask('downloads', 'Uploads generated files as GitHub downloads.', function () {
+ if(this.target == '_options') {
+ return;
+ }
+
+ var _ = grunt.utils._;
+ var done = this.async();
+ var ops = grunt.config(['downloads', this.target]);
+ var defaults = _.extend({}, grunt.config(['downloads', '_options']));
+ var sourceFile = this.file.src;
+
+ var desc = grunt.template.process(ops.description);
+ var name = grunt.template.process(ops.filename);
+
+ grunt.log.writeln('Deploying ' + desc);
+ fs.readFile(sourceFile, function (err, buf) {
+ if (err) {
+ return grunt.fail.fatal(err);
+ }
+
+ var createDownload = function() {
+ github.httpSend({
+ "user" : defaults.user,
+ "repo" : defaults.repository,
+ "name" : name,
+ "size" : buf.length,
+ "description" : desc,
+ "content_type" : ops.content_type || "text/javascript"
+ }, {
+ "url" : "/repos/:user/:repo/downloads",
+ "method" : "POST",
+ "params" : {
+ "$user" : null,
+ "$repo" : null,
+ "$name" : null,
+ "$size" : null,
+ "description" : null,
+ "$content_type" : null
+ }
+ }, function (err, socket) {
+ if(err) {
+ return grunt.fail.fatal(err);
+ }
+ var data = JSON.parse(socket.data);
+
+ grunt.utils.s3.postToS3({
+ key : data.path,
+ acl : data.acl,
+ success_action_status : "201",
+ Filename : data.name,
+ AWSAccessKeyId : data.accesskeyid,
+ policy64 : data.policy,
+ signature64 : data.signature,
+ contentType : data.mime_type,
+ data : buf,
+ bucket : "github"
+ }, function (e) {
+ if(e) {
+ return grunt.fail.fatal(e);
+ }
+ grunt.log.writeln('Successfully created GitHub download and uploaded to S3.');
+ done();
+ })
+ });
+ }
+
+ grunt.log.writeln('Uploading to ' + defaults.user + '/' + defaults.repository + '/' + name);
+ getCredentials(createDownload);
+
+ });
+ });
+}
View
@@ -25,7 +25,7 @@ module.exports = function (grunt) {
return;
}
- var command = grunt.template.process(data.command);
+ var command = grunt.template.process(this.file.src);
log.writeln('Running ' + command);
exec(command, data.execOptions, function (err, stdout, stderr) {
if (stdout) {
View
@@ -16,13 +16,14 @@ module.exports = function (grunt) {
}
var outFile = options.out ? path.join(options.out, path.basename(file)) : file;
// TODO use Grunt internals
- grunt.log.writeln('Stripping ' + file + ' of all multiline comments, writing result to ' + outFile);
+ grunt.log.writeln('Stripping ' + file + ' of all multiline and empty inline comments');
// Put new index.html into production mode
var code = grunt.file.read(file);
// Remove multiline comments
- code = code.replace(/\/\*([\s\S]*?)\*\//gim, "");
+ code = code.replace(/\/\*([\s\S]*?)\*\//gim, "")
+ .replace(/\/\/(\s*)\n/gim, "");
// Remove double semicolons from steal pluginify
code = code.replace(/;[\s]*;/gim, ";");
View
@@ -9,22 +9,129 @@ var spawn = require("child_process").spawn;
// opts: nodeSpawnOptions
// }
-module.exports = function(grunt) {
- grunt.utils.exec = function(options, callback) {
+module.exports = function (grunt) {
+ grunt.utils.exec = function (options, callback) {
var build = grunt.utils.spawn(options, callback);
- build.stdout.on("data", function( buf ) {
- grunt.log.write( "" + buf );
+ build.stdout.on("data", function (buf) {
+ grunt.log.write("" + buf);
});
- build.stderr.on("data", function( buf ) {
- grunt.log.write( "" + buf );
+ build.stderr.on("data", function (buf) {
+ grunt.log.write("" + buf);
});
- build.on("exit", function( code ) {
+ build.on("exit", function (code) {
callback(null, code);
});
return build;
- }
+ };
+
+ // Generated by CoffeeScript 1.3.1
+ (function () {
+ var crypto, https, joinBuffers, postToS3, readText, signPolicy, url, _ref;
+
+ url = require('url');
+
+ https = require('https');
+
+ crypto = require('crypto');
+
+ _ref = require('tafa-misc-util'), joinBuffers = _ref.joinBuffers, readText = _ref.readText;
+
+ signPolicy = function (secretKey, policy) {
+ var data, hmac, json, key, policy64, signature64;
+ json = JSON.stringify(policy);
+ policy64 = new Buffer(json).toString('base64');
+ data = new Buffer(policy64, 'utf-8');
+ key = new Buffer(secretKey, 'utf-8');
+ hmac = crypto.createHmac('sha1', key);
+ hmac.update(data);
+ signature64 = hmac.digest('base64');
+ return {
+ signature64 : signature64,
+ policy64 : policy64
+ };
+ };
+
+ postToS3 = function (_arg, callback) {
+ var AWSAccessKeyId, Filename, acl, addParam, arr, boundary, bucket, buf, ca, contentType, customUrl, data, host, hostname, key, options, policy64, port, protocol, req, req_body, signature64, success_action_status, _ref1;
+ AWSAccessKeyId = _arg.AWSAccessKeyId, policy64 = _arg.policy64, signature64 = _arg.signature64, bucket = _arg.bucket, key = _arg.key, data = _arg.data, boundary = _arg.boundary, customUrl = _arg.customUrl, ca = _arg.ca, acl = _arg.acl, success_action_status = _arg.success_action_status, Filename = _arg.Filename, contentType = _arg.contentType;
+ if (callback == null) {
+ callback = (function () {
+ });
+ }
+ if (customUrl) {
+ _ref1 = url.parse(customUrl), protocol = _ref1.protocol, hostname = _ref1.hostname, port = _ref1.port;
+ if (protocol !== "https:") {
+ return callback(new Error("customUrl must be https://"));
+ }
+ host = hostname;
+ port || (port = 443);
+ } else {
+ host = "" + bucket + ".s3.amazonaws.com";
+ port = 443;
+ }
+ boundary || (boundary = '----------R46EARkAg4SAXSjufGsb6m');
+ buf = function (x) {
+ return new Buffer(x);
+ };
+ arr = [];
+ addParam = function (k, v) {
+ arr.push(buf('--' + boundary + '\r\n'));
+ arr.push(buf('Content-Disposition: form-data; name="' + k + '"\r\n\r\n'));
+ return arr.push(buf(v), buf('\r\n'));
+ };
+ addParam('key', key);
+ addParam('acl', acl);
+ addParam('success_action_status', success_action_status);
+ addParam('Filename', Filename);
+ addParam('AWSAccessKeyId', AWSAccessKeyId);
+ addParam('Policy', policy64);
+ addParam('Signature', signature64);
+ addParam('Content-Type', contentType);
+ arr.push(buf('--' + boundary + '\r\n'));
+ arr.push(buf('Content-Disposition: form-data; name="file"; filename="data"\r\n'));
+ arr.push(buf("Content-Length: " + data.length + "\r\n"));
+ arr.push(buf('Content-Transfer-Encoding: binary\r\n\r\n'));
+ arr.push(data, buf('\r\n'));
+ arr.push(buf('--' + boundary + '--'));
+ req_body = joinBuffers(arr);
+ options = {
+ host : host,
+ port : port,
+ path : '/',
+ method : 'POST',
+ headers : {
+ 'Host' : "" + bucket + ".s3.amazonaws.com",
+ 'Content-Type' : 'multipart/form-data; boundary=' + boundary,
+ 'Content-Length' : req_body.length
+ }
+ };
+ if (ca) {
+ options.ca = ca;
+ }
+ req = https.request(options, function (res) {
+ var _ref2;
+ if ((200 <= (_ref2 = res.statusCode) && _ref2 < 300)) {
+ return callback(null);
+ } else {
+ return readText(res, function (text) {
+ return callback({
+ responseCode : res.statusCode,
+ responseText : text
+ });
+ });
+ }
+ });
+ return req.end(req_body);
+ };
+
+ grunt.utils.s3 = {
+ postToS3 : postToS3,
+ signPolicy : signPolicy
+ };
+
+ }).call(this);
}
View
@@ -3,7 +3,7 @@ module.exports = function (grunt) {
var _ = grunt.utils._;
var excludes = [/\.min\./, /\/amd/, /qunit\.js/];
var outFiles = {
- edge : '<%= meta.out %>/edge/**/*!(.min).js',
+ edge : '<%= meta.out %>/edge/**/*.js',
latest : '<%= meta.out %>/<%= pkg.version %>/**/*.js',
_options : {
exclude : excludes
@@ -64,29 +64,23 @@ module.exports = function (grunt) {
}
},
shell : {
- bundleLatest : {
- command : 'cd <%= meta.out %> && zip -r can.js.<%= pkg.version %>.zip <%= pkg.version %>/'
- },
- getGhPages : {
- command : 'git clone -b gh-pages <%= pkg.repository.url %> build/tmp'
- },
- copyLatest : {
- command : 'rm -rf build/tmp/release/<%= pkg.version %> && ' +
- 'cp -R <%= meta.out %>/<%= pkg.version %> build/tmp/release/<%= pkg.version %> && ' +
- 'rm -rf build/tmp/release/latest && ' +
- 'cp -R <%= meta.out %>/<%= pkg.version %> build/tmp/release/latest'
- },
- updateGhPages : {
- command : 'cd build/tmp && git commit -a -m "Updating release" && git push origin'
- },
- cleanup : {
- command : 'rm -rf build/tmp'
- },
+ bundleLatest : 'cd <%= meta.out %> && zip -r can.js.<%= pkg.version %>.zip <%= pkg.version %>/',
+ getGhPages : 'git clone -b gh-pages <%= pkg.repository.url %> build/gh-pages',
+ copyLatest : 'rm -rf build/gh-page/release/<%= pkg.version %> && ' +
+ 'cp -R <%= meta.out %>/<%= pkg.version %> build/gh-pages/release/<%= pkg.version %> && ' +
+ 'rm -rf build/gh-pages/release/latest && ' +
+ 'cp -R <%= meta.out %>/<%= pkg.version %> build/gh-pages/release/latest',
+ copyEdge : 'rm -rf build/gh-pages/release/edge && ' +
+ 'cp -R <%= meta.out %>/edge build/gh-pages/release/edge',
+ updateGhPages : 'cd build/gh-pages && git add . --all && git commit -m "Updating release (latest: <%= pkg.version %>)" && ' +
+ 'git push origin',
+ cleanup : 'rm -rf build/gh-pages',
_options : {
stdout : true,
failOnError : true
}
},
+ downloads : '<json:build/downloads.json>',
docco : outFiles,
strip : outFiles
});
@@ -95,5 +89,5 @@ module.exports = function (grunt) {
grunt.registerTask("edge", "build:edge build:edgePlugins strip:edge beautify:dist");
grunt.registerTask("latest", "build:latest build:latestPlugins strip:latest beautify:dist docco:latest");
- grunt.registerTask("deploy", "shell:getGhPages shell:copyLatest shell:updateGhPages shell:cleanup");
+ grunt.registerTask("deploy", "latest shell:getGhPages shell:copyLatest shell:updateGhPages shell:cleanup shell:bundleLatest downloads");
};
Oops, something went wrong.

0 comments on commit ddc93d2

Please sign in to comment.