Permalink
Browse files

swapping out Jakefile for grunt

  • Loading branch information...
Sam Breed
Sam Breed committed Feb 11, 2012
1 parent b5f3959 commit 5d670357d6dd37278059dcf4e905ef7215d27b30
Showing with 86 additions and 320 deletions.
  1. +0 −290 Jakefile.js
  2. +0 −21 build.json
  3. +41 −0 build/config.js
  4. +15 −0 build/index.js
  5. +26 −0 build/tasks/clean/clean.js
  6. 0 dist/{readme.md → .gitkeep}
  7. +4 −9 package.json
View
@@ -1,290 +0,0 @@
-var // Dependency References
- fs = require( "fs" ),
- _ = require( "underscore" ),
- jshint = require( "jshint" ).JSHINT,
- colors = require( "colors" ),
- uglifyjs = require( "uglify-js" ),
- Buffer = require( "buffer" ).Buffer,
- zlib = require( "zlib" ),
- dateFormat = require( "dateformat" ),
- stats = require( "stats" ),
- cp = require("child_process"),
- exec = cp.exec,
- spawn = cp.spawn,
- assert = require("assert"),
- child;
-
-var // Shortcut References
- slice = Array.prototype.slice,
- now = new Date();
-
-var // Program References
- $$ = {},
- // Get options, defaults merged with build.json file.
- config = _.extend({}, true, {
-
- // Meta Build Info
- "meta": {
- "buildDate": dateFormat( now, "m/d/yyyy" )
- },
-
- // Overridden with build.json
- "files": {},
-
- // License Banner Template
- "banner": [
- "// <%= label %> - v<%= version %> - <%= buildDate %>",
- "// <%= homeurl %>",
- "// <%= copyright %>; Licensed <%= license.join(', ') %>"
- ].join( "\n" ),
-
- // JSHint Optional Settings
- "jshint": {
- unused: true,
- unuseds: true,
- devel: true,
- undef: true,
- noempty: true,
- evil: true,
- forin: false,
- maxerr: 100,
- loopfunc: true,
- eqnull: true
- // "curly": true,
- // "eqnull": true,
- // "immed": true,
- // "newcap": true,
- // "noarg": true,
- // "undef": true,
- // "browser": true,
- // "predef": [ "jQuery" ]
- },
-
- // Uglify Optional Settings
- "uglify": {
- "mangle": {
- "except": [ "$" ]
- },
- "squeeze": {},
- "codegen": {}
- }
- },
- readJson( "build.json", true )
- ),
- // Setup Distribution File Banner (License Block)
- banner = _.template( typeof config.banner == "string" ? config.banner : "" );
-
-// Logging Utility Functions
-function header( msg ) {
- writeln( "\n" + msg.underline );
-}
-function write( msg ) {
- process.stdout.write( (msg != null && msg) || "" );
-}
-function writeln( msg ) {
- console.log( (msg != null && msg) || "" );
-}
-function ok( msg ) {
- writeln( msg ? "\n>> ".green + msg : "OK".green );
-}
-function error( msg ) {
- writeln( msg ? "\n>> ".red + msg : "ERROR".red );
-}
-
-
-// Read a file.
-function readFile( filepath ) {
- var src;
- write( "Reading " + filepath + "..." );
- try {
- src = fs.readFileSync( filepath, "UTF-8" );
- ok();
- return src;
- } catch( e ) {
- error();
- fail( e.message );
- }
-}
-
-// Write a file.
-function writeFile( filepath, contents, silent ) {
- // if ( config.nowrite ) {
- // writeln('Not'.underline + ' writing ' + filepath + ' (dry run).');
- // return true;
- // }
-
- if ( arguments.length < 3 ) {
- silent = true;
- }
-
- silent || write( "Writing " + filepath + "..." );
-
- try {
- fs.writeFileSync( filepath, contents, "UTF-8" );
- } catch( e ) {
- error();
- fail( e );
- }
-
- ok();
- return true;
-}
-
-// Read and parse a JSON file.
-function readJson( filepath, silent ) {
- var result;
-
- silent || write( "Reading " + filepath + "..." );
-
- try {
- result = JSON.parse(
- fs.readFileSync( filepath, "UTF-8" )
- );
- } catch( e ) {
- silent || error();
- fail( e.message );
- }
-
- silent || ok();
- return result;
-}
-
-
-// # Lint some source code.
-// From http://jshint.com
-function hint( src, path ) {
- write( "Validating with JSHint...");
-
- if ( jshint( src, config.jshint ) ) {
- ok();
- } else {
- error();
-
- jshint.errors.forEach(function( e ) {
- if ( !e ) { return; }
- var str = e.evidence ? e.evidence.inverse : "";
-
- str = str.replace( /\t/g, " " ).trim();
- error( path + " [L" + e.line + ":C" + e.character + "] " + e.reason + "\n " + str );
- });
- fail( "JSHint found errors." );
- }
-}
-
-// # Minify with UglifyJS.
-// From https://github.com/mishoo/UglifyJS
-function uglify( src ) {
- write( "Uglifying..." );
-
- var jsp = uglifyjs.parser,
- pro = uglifyjs.uglify,
- ast;
-
- try {
- ast = jsp.parse( src );
- ast = pro.ast_mangle( ast, config.uglify.mangle || {});
- ast = pro.ast_squeeze( ast, config.uglify.squeeze || {});
- src = pro.gen_code( ast, config.uglify.codegen || {});
-
- } catch( e ) {
- error();
- error( "[L" + e.line + ":C" + e.col + "] " + e.message + " (position: " + e.pos + ")" );
- fail( e.message );
- return false;
- }
-
- ok();
- return src;
-}
-
-// Return deflated src input.
-function gzip( src ) {
- return zlib.deflate( new Buffer( src ) );
-}
-
-// Jake Tasks
-
-desc( "Hint & Minify" );
-task( "default", [ "hint", "min" ], function() {
- // Nothing
-});
-
-desc( "Validate with JSHint." );
-task( "hint", function() {
-
- header( "Validating with JSHint" );
-
- _.keys( config.files ).forEach(function( minpath ) {
-
- var files = config.files[ minpath ],
- concat = files.src.map(function( path ) {
- var src = readFile( path );
-
- config.jshint.devel = config.jshint.debug = files.debug;
-
- if ( files.prehint ) {
- hint( src, path );
- }
-
- return src;
- }).join( "\n" );
-
- if ( files.src.length ) {
- write( "Hnting concatenated source: " + files.src.length + " scripts..." );
- ok();
- if ( files.posthint ) {
- hint( concat, "post" );
- }
- }
- });
-});
-
-desc( "Minify with Uglify-js." );
-task( "min", function() {
-
- header( "Minifying with Uglify-js" );
-
- _.keys( config.files ).forEach(function( minpath ) {
-
- var file = config.files[ minpath ],
- concat = file.src.map( function( path ) {
- return readFile( path );
- }).join( "\n" ),
-
- intro, fullpath, min;
-
-
- fullpath = minpath + ".js";
- minpath = minpath + ".min.js"
-
- // Generate intro block with banner template,
- // Inject meta build data
- intro = banner( _.extend( file.meta, config.meta ) );
-
- // Without a newline, the min source code will run on the same
- // Line as the intro lic/banner block
- if ( intro ) {
- intro += "\n";
- }
-
- // Provide information about current file being built
- if ( file.src.length ) {
- write( "Concatenating " + file.src.length + " script(s)" );
- ok();
- }
-
- // Write full sized, concatenated source
- writeFile( fullpath, concat, false );
-
- // Minify/Uglify and Write compressed, concatenated source
- if ( min = uglify( concat ) ) {
-
- min = intro + min;
-
- if ( writeFile( minpath, min, false ) ) {
- ok( "Compressed size: " + (gzip( min ).length + "").yellow + " bytes gzipped (" + ( min.length + "" ).yellow + " bytes minified)." );
- }
- }
- });
-});
-
View
@@ -1,21 +0,0 @@
-{
- "files": {
- "dist/underscore.deferred": {
- "src": [
- "lib/underscore.deferred.js"
- ],
- "prehint": true,
- "posthint": false,
- "debug": true,
-
- "meta": {
- "label": "underscore.deferred",
- "author": "",
- "version": "0.0.0",
- "homeurl": "",
- "license": [],
- "copyright": ""
- }
- }
- }
-}
View
@@ -0,0 +1,41 @@
+config.init({
+
+ lint: {
+ files: ["lib/*"]
+ },
+
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ eqnull: true,
+ browser: true,
+ node: true
+ },
+ globals: {
+ jQuery: true,
+ ender: true
+ }
+ },
+
+ min: {
+ "dist/underscore.deferred.js": ["lib/underscore.deferred.js"]
+ },
+
+ qunit: {
+ files: ["test/**/*.html"]
+ },
+
+ clean: {
+ folder: "dist"
+ }
+
+});
+
+// Run the following tasks...
+task.registerTask("default", "lint min");
+task.registerTask("test", "qunit clean min lint");
View
@@ -0,0 +1,15 @@
+var fs = require("fs");
+var grunt = require("grunt");
+
+// Auto-load tasks
+var taskList = fs.readdirSync(__dirname + "/tasks").filter(function(task) {
+ return fs.statSync(__dirname + "/tasks/" + task).isDirectory();
+}).map(function(task) {
+ return "build/tasks/" + task;
+}).concat("build/tasks");
+
+grunt.cli({
+ base: "./",
+ config: "build/config.js",
+ tasks: taskList
+}, function() { });
View
@@ -0,0 +1,26 @@
+/*
+ * Grunt Task File
+ * ---------------
+ *
+ * Task: Clean
+ * Description: Remove the contents of a given folder
+ * Dependencies: rimraf
+ *
+ */
+
+task.registerBasicTask("clean", "Remove the contents of a given folder", function(data, name) {
+ var folder = require("path").resolve(data);
+
+ // Delete all files inside the folder
+ task.helper("clean", folder);
+
+ // Fail task if errors were logged.
+ if (task.hadErrors()) { return false; }
+
+ // Otherwise, print a success message.
+ log.writeln("Folder \"" + folder + "\" contents removed.");
+});
+
+task.registerHelper("clean", function(folder) {
+ require("rimraf").sync(folder);
+});
File renamed without changes.
Oops, something went wrong.

0 comments on commit 5d67035

Please sign in to comment.