Permalink
Browse files

Adding build tasks. Updating references.

  • Loading branch information...
1 parent 7342d26 commit 730bf09afebea99f0a75e0c3fdd46e3c9bf5023e @daffl daffl committed Nov 16, 2012
Showing with 504 additions and 7 deletions.
  1. +68 −0 build/tasks/beautify.js
  2. +39 −0 build/tasks/build.js
  3. +29 −0 build/tasks/docco.js
  4. +103 −0 build/tasks/downloads.js
  5. +52 −0 build/tasks/shell.js
  6. +38 −0 build/tasks/strip.js
  7. +137 −0 build/tasks/utils.js
  8. +1 −1 can
  9. +1 −1 canui
  10. 0 docs.html
  11. +1 −1 documentjs
  12. +1 −1 funcunit
  13. +1 −1 jquery
  14. +31 −0 package.json
  15. +1 −1 site/docs.html
  16. +1 −1 steal
@@ -0,0 +1,68 @@
+/*
+ * grunt-beautify.git
+ * https://github.com/pix/grunt-beautify
+ *
+ * Copyright (c) 2012 Camille Moncelier
+ * Licensed under the MIT license.
+ */
+
+module.exports = function (grunt) {
+
+ // Please see the grunt documentation for more information regarding task and
+ // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
+ // ==========================================================================
+ // TASKS
+ // ==========================================================================a
+ var default_options = {
+ indentSize : 2
+ };
+
+ var merge = function () {
+ var out = {};
+
+ for (var i = 0; i < arguments.length; i++) {
+ for (var key in arguments[i]) {
+ out[key] = arguments[i][key];
+ }
+ }
+ return out;
+ };
+
+ grunt.registerMultiTask('beautify', 'Javascript beautifier', function () {
+ var beautifier = require('node-beautify');
+
+ var options = null;
+ var tmp = grunt.config(['beautifier', this.target, 'options']);
+ if (typeof tmp === 'object') {
+ grunt.verbose.writeln('Using "' + this.target + '" beautifier options.');
+ options = tmp;
+ } else {
+ tmp = grunt.config('beautifier.options');
+ if (typeof tmp === 'object') {
+ grunt.verbose.writeln('Using master beautifier options.');
+ options = tmp;
+ } else {
+ grunt.verbose.writeln('Using beautifier default options.');
+ options = default_options;
+ }
+ }
+
+ // Beautify specified files.
+ var excludes = grunt.config(['beautifier', this.target, 'exclude']);
+ grunt.file.expandFiles(this.file.src).filter(function (file) {
+ for (var i = 0; i < excludes.length; i++) {
+ if (excludes[i].test(file)) {
+ grunt.log.writeln('Not beautifying ' + file);
+ return false;
+ }
+ }
+ return true;
+ }).forEach(function (filepath) {
+ grunt.log.writeln('Beautifying ' + filepath);
+ var result = beautifier.beautifyJs(grunt.file.read(filepath), options);
+ grunt.file.write(filepath, result);
+ });
+
+ });
+
+};
View
@@ -0,0 +1,39 @@
+var path = require("path");
+var jsDir = path.join( __dirname, "../..");
+
+module.exports = function( grunt ) {
+ grunt.registerMultiTask('build', 'Runs build files.', function() {
+ var done = this.async();
+ var target = this.target;
+ var files = Array.isArray(this.file.src) ? this.file.src : [this.file.src];
+ // TODO grunt.file.expandFiles(this.file.src);
+ var series = files.map(function (file) {
+ return function(callback) {
+ var options = grunt.config.process(['build', target]);
+ var args = [file, options.out || 'dist/', options.version || 'edge'];
+ var libraries = Array.isArray(options.libraries) ? options.libraries : [];
+
+ args.push.apply(args, libraries);
+
+ grunt.verbose.writeflags(options, 'Options');
+ grunt.log.writeln('Running ./js ' + args.join(' '));
+
+ grunt.utils.exec({
+ cmd : "./js",
+ args : args,
+ opts : {
+ cwd: jsDir
+ }
+ }, function(error, result, code) {
+ callback(error, result, code);
+ });
+
+ grunt.log.write("Building " + file + " with Steal...\n");
+ }
+ });
+ grunt.utils.async.parallel(series, function(error, results) {
+ grunt.log.writeln('Done building');
+ done();
+ })
+ });
+};
View
@@ -0,0 +1,29 @@
+/**
+ * Grunt Docco task. Based on https://github.com/DavidSouther/grunt-docco
+ */
+var docco = require('docco');
+
+module.exports = function(grunt) {
+ grunt.registerMultiTask('docco', 'Docco processor.', function() {
+ var _ = grunt.utils._;
+ var options = grunt.config(['docco', this.target]);
+ var defaults = _.extend({
+ exclude : [/\.min\./]
+ }, grunt.config('strip')._options);
+ grunt.verbose.writeflags(options, 'Options');
+ var done = this.async();
+ var src = grunt.file.expandFiles(this.file.src).filter(function(file) {
+ for(var i = 0; i < defaults.exclude.length; i++) {
+ if(defaults.exclude[i].test(file)) {
+ return false;
+ }
+ }
+ return true;
+ });
+
+ docco.document(src, options.docco || {}, function(err, result, code){
+ grunt.log.writeln("Doccoed [" + src.join(", ") + "]; " + err ? err : "(No errors)" + "\n" + result + " " + code);
+ done();
+ });
+ });
+}
@@ -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
@@ -0,0 +1,52 @@
+/*
+ * grunt-shell
+ * 0.1.2 - 2012-06-28
+ * github.com/sindresorhus/grunt-shell
+ *
+ * (c) Sindre Sorhus
+ * sindresorhus.com
+ * MIT License
+ */
+module.exports = function (grunt) {
+ 'use strict';
+
+ var _ = grunt.utils._;
+ var log = grunt.log;
+
+ grunt.registerMultiTask('shell', 'Run shell commands', function () {
+ var exec = require('child_process').exec;
+ var done = this.async();
+ var data = _.extend([], grunt.config.get('shell')._options, this.data);
+ var dataOut = data.stdout;
+ var dataErr = data.stderr;
+
+ if (_.isFunction(data.callback)) {
+ data.callback.call(this);
+ return;
+ }
+
+ var command = grunt.template.process(this.file.src);
+ log.writeln('Running ' + command);
+ exec(command, data.execOptions, function (err, stdout, stderr) {
+ if (stdout) {
+ if (_.isFunction(dataOut)) {
+ dataOut(stdout);
+ } else if (dataOut === true) {
+ log.write(stdout);
+ }
+ }
+
+ if (err) {
+ if (_.isFunction(dataErr)) {
+ dataErr(stderr);
+ } else if (data.failOnError === true) {
+ grunt.fatal(err);
+ } else if (dataErr === true) {
+ log.error(err);
+ }
+ }
+
+ done();
+ });
+ });
+};
View
@@ -0,0 +1,38 @@
+var path = require('path');
+
+// A grunt task that strips multiline comments
+module.exports = function (grunt) {
+ grunt.registerMultiTask('strip', 'Remove multiline comments from files', function () {
+ var _ = grunt.utils._;
+ var options = grunt.config.process(['strip', this.target]);
+ var defaults = _.extend({
+ exclude : [/\.min\./]
+ }, grunt.config('strip')._options);
+ grunt.file.expandFiles(this.file.src).forEach(function (file) {
+ for(var i = 0; i < defaults.exclude.length; i++) {
+ if(defaults.exclude[i].test(file)) {
+ return;
+ }
+ }
+ var outFile = options.out ? path.join(options.out, path.basename(file)) : file;
+ // TODO use Grunt internals
+ 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, "")
+ .replace(/\/\/(\s*)\n/gim, "");
+
+ // Remove double semicolons from steal pluginify
+ code = code.replace(/;[\s]*;/gim, ";");
+ code = code.replace(/(\/\/.*)\n[\s]*;/gi, "$1");
+
+ // Only single new lines
+ code = code.replace(/(\n){3,}/gim, "\n\n");
+
+ grunt.file.write(outFile, code);
+ });
+ });
+}
Oops, something went wrong.

0 comments on commit 730bf09

Please sign in to comment.