Skip to content

Instantly share code, notes, and snippets.

@ruzzbot
Created September 12, 2012 14:32
Show Gist options
  • Save ruzzbot/3707010 to your computer and use it in GitHub Desktop.
Save ruzzbot/3707010 to your computer and use it in GitHub Desktop.
VML grunt.js buildscript (bbb)
// This is the main application configuration file. It is a Grunt
// configuration file, which you can learn more about here:
// https://github.com/cowboy/grunt/blob/master/docs/configuring.md
// http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/
// If you need support for a pre-compiler or a new tool to play with, check out
// http://gruntjs.com/
module.exports = function(grunt) {
// directory paths
var dir = (function(){
var app = "app", // project specific js / amd-modules
assets = "assets", // assets container
build = "build"; // build directory
return {
"app": app,
"assets": assets,
"styles": assets+"/css",
"scripts": assets+"/js",
"build": build,
"prod": build+"/latest",
"dev": build+"/latest-dev"
}
})();
// Project Grunt Config
grunt.initConfig({
// load package-specific details
pkg: '<json:package.json>',
// directory paths(from above)
dir: dir,
// appended concatenated / minified files
meta: {
banner: [
'/*!',
'<%= pkg.name %> - v<%= pkg.version %> - ',
'<%= grunt.template.today("yyyy-mm-dd HH:MM:SS") %>',
'*/'
].join('')
},
// keep a time-stamp for release tags
timestamp: "<%= grunt.template.date( new Date(),'yyyymmdd_HHMM') %>",
// The clean task ensures all helper / build files are removed from
// production releases
clean: {
debug: ["<%= dir.dev %>"],
prod: [
"<%= dir.prod %>/test",
"<%= dir.prod %>/dist",
"<%= dir.prod %>/*.styl",
"<%= dir.prod %>/*.sass",
"<%= dir.prod %>/*.less",
"<%= dir.prod %>/*.coffee",
"<%= dir.prod %>/*.DS_Store",
"<%= dir.prod %>/grunt.js"
]
},
// The copy project to the specified folder to be processed for deployment
copy: {
debug: {
options: {
processContentExclude:[ dir.build, '.DS_Store' ]
},
files: { "<%= dir.dev %>": "**" }
},
dist: {
options: {
processContentExclude:[ dir.build, 'test', '.DS_Store' ]
},
files: { "<%= dir.prod %>": "<%= dir.dev %>/**" }
}
},
// Create a zip to attach to the prod roll TTP
compress: {
zip: {
options: {
mode: "zip"
},
files: {
"<%= dir.build %>/<%= pkg.name %>_<%= timestamp %>.zip": "<%= dir.build %>/latest/**"
}
}
},
// The lint task will run the build configuration and the application
// JavaScript through JSHint and report any errors. You can change the
// options for this task, by reading this:
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md
lint: {
files: [
"<%= dir.dev %>/<%= dir.app %>/config.js", "<%= dir.dev %>/<%= dir.app %>/**/*.js"
]
},
// The jshint option for scripturl is set to lax, because the anchor
// override inside main.js needs to test for them so as to not accidentally
// route.
jshint: {
options: {
scripturl: true
}
},
// The jst task compiles all application templates into JavaScript
// functions with the underscore.js template function from 1.2.4. You can
// change the namespace and the template options, by reading this:
// https://github.com/gruntjs/grunt-contrib/blob/master/docs/jst.md
//
// The concat task depends on this file to exist, so if you decide to
// remove this, ensure concat is updated accordingly.
jst: {
src: ["<%= dir.dev %>/<%= dir.app %>/templates/**/*.html"],
dest: ["<%= dir.dev %>/<%= dir.app %>/templates.js"]
},
// The handlebars task compiles all application templates into JavaScript
// functions using Handlebars templating engine.
//
// Since this task defaults to writing to the same file as the jst task,
// edit the debug task replacing jst with handlebars.
//
// The concat task depends on this file to exist, so if you decide to
// remove this, ensure concat is updated accordingly.
handlebars: {
src: ["<%= dir.dev %>/<%= dir.app %>/templates/**/*.html"],
dest: ["<%= dir.dev %>/<%= dir.app %>/templates.js"]
},
// The concatenate task is used here to merge the almond require/define
// shim and the templates into the application code. It's named
// dist/debug/require.js, because we want to only load one script file in
// index.html.
concat: {
dist: {
src: [
"<%= dir.dev %>/<%= dir.scripts %>/libs/almond.js",
"<%= dir.dev %>/<%= dir.assets %>/templates.js",
"<%= dir.dev %>/<%= dir.scripts %>/libs/require.js"
],
dest: dir.dev+"/"+dir.scripts+"/libs/require.js",
separator: ";"
}
},
// This task takes CSS files in order and concatenate them into a single
// file named index.css. It also minifies all the CSS as well.
mincss: {
src: ["<%= dir.dev %>/<%= dir.styles %>/index.css"],
dest: ["<%= dir.dev %>/<%= dir.styles %>/index.css"]
},
// Combines styles by injecting contents of @import statements
// Compiles assets ending in '.styl' before injecting
styles: {
// Output stylesheet file.
"build/assets/css/index.css": {
// Main CSS source file, containing the @imports.
src: "assets/css/index.css",
// Relative path for `@imports`.
paths: [ 'assets/css' ]
// Add additional stylesheets.
//additional: ["<%= dir.styles %>/production-fixes.css"]
}
},
// Takes the built require.js file and minifies it for filesize benefits.
min: {
src: ["<%= dir.prod %>/<%= dir.app %>/require.js"],
dest: ["<%= dir.prod %>/<%= dir.app %>/require.js"]
},
// Running the server without specifying an action will run the defaults,
// port: 8000 and host: 127.0.0.1. If you would like to change these
// defaults, simply add in the properties `port` and `host` respectively.
// Alternatively you can omit the port and host properties and the server
// task will instead default to process.env.PORT or process.env.HOST.
//
// Changing the defaults might look something like this:
//
// server: {
// host: "127.0.0.1", port: 9001
// debug: { ... can set host and port here too ...
// }
//
// To learn more about using the server task, please refer to the code
// until documentation has been written.
server: {
// Ensure the favicon is mapped correctly.
files: {
"favicon.ico": "favicon.ico"
},
debug: {
// Ensure the favicon is mapped correctly.
files: {
"favicon.ico": "favicon.ico"
},
// Map `server:debug` to `debug` folders.
folders: {
"app": "<%= dir.dev %>/app",
"<%= dir.scripts %>/libs": "<%= dir.dev %>/<%= dir.scripts %>/libs",
"<%= dir.styles %>": "<%= dir.dev %>/<%= dir.styles %>"
}
},
release: {
// This makes it easier for deploying, by defaulting to any IP.
host: "0.0.0.0",
// Ensure the favicon is mapped correctly.
files: {
"favicon.ico": "favicon.ico"
},
// Map `server:release` to `release` folders.
folders: {
"app": "<%= dir.app %>",
"<%= dir.scripts %>/libs": "<%= dir.prod %>/<%= dir.scripts %>/libs",
"<%= dir.styles %>": "<%= dir.prod %>/<%= dir.styles %>"
}
}
},
// This task uses James Burke's excellent r.js AMD build tool. In the
// future other builders may be contributed as drop-in alternatives.
requirejs: {
// Include the main configuration file.
mainConfigFile: dir.app+"/config.js",
// Output file.
out: dir.app+"/require.js",
// Root application module.
name: "config",
// Do not wrap everything in an IIFE.
wrap: false
},
// The headless QUnit testing environment is provided for "free" by Grunt.
// Simply point the configuration to your test directory.
qunit: {
all: ["test/qunit/*.html"]
},
// The headless Jasmine testing is provided by grunt-jasmine-task. Simply
// point the configuration to your test directory.
jasmine: {
all: ["test/jasmine/*.html"]
},
// Live-reload in browser after assets are loaded
reload: {
port: 6001,
proxy: {
host: 'localhost',
port: '<config.server.port>'
}
},
// The watch task can be used to monitor the filesystem and execute
// specific tasks when files are modified. By default, the watch task is
// available to compile stylus templates if you are unable to use the
// runtime builder (use if you have a custom server, PhoneGap, Adobe Air,
// etc.)
watch: {
files: ["grunt.js", "<%= dir.styles %>/**/*.styl"],
tasks: "styles reload"
}
});
// The debug task will remove all contents inside the dist/ folder, lint
// all your code, precompile all the underscore templates into
// dist/debug/templates.js, compile all the application code into
// dist/debug/require.js, and then concatenate the require/define shim
// almond.js and dist/debug/templates.js into the require.js file.
grunt.registerTask("debug", "clean:debug copy:debug jst requirejs concat styles");
// The release task will run the debug tasks and then minify the
// dist/debug/require.js file and CSS files.
grunt.registerTask("release", "debug copy:dist min mincss");
// VML Prod tasks will run both debug and release tasks and will create a .zip
// for prod-roll TTP requests.
grunt.registerTask("vml-prod", "release clean:prod compress");
grunt.registerTask("vml-live", "server:debug reload watch");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment