priority-ignore/grunt.js

210 lines
6.2 KiB
JavaScript
Raw Normal View History

2012-07-09 20:16:06 +00:00
/* mode:javascript; tab-width:2; indent-tabs-mode:nil; */
/*global module:false*/
2012-07-10 16:00:40 +00:00
var path, _und, async;
2012-07-09 20:16:06 +00:00
path = require('path');
_und = require('underscore');
2012-07-10 16:00:40 +00:00
async = require('async');
2012-07-09 21:36:08 +00:00
2012-07-09 20:16:06 +00:00
module.exports = function(grunt) {
2012-07-09 21:36:08 +00:00
grunt.loadNpmTasks('grunt-coffee');
grunt.loadNpmTasks('grunt-recess');
2012-07-09 21:41:26 +00:00
grunt.loadNpmTasks('grunt-requirejs');
2012-07-09 20:16:06 +00:00
// Project configuration.
grunt.initConfig({
pkg: '<json:PriorityIgnore.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
qunit: {
files: ['test/**/*.html']
},
lint: {
files: ['grunt.js', 'src/**/*.js', 'test/**/*.js']
},
watch: {
files: '<config:lint.files>',
tasks: 'lint qunit'
},
server: {
port: 8081,
base: './dist/'
},
haml: {
src: ['src/**/*.haml'],
2012-07-10 16:00:40 +00:00
dest: './src'
2012-07-09 20:16:06 +00:00
},
templatize: {
2012-07-09 21:36:08 +00:00
src: ['src/**/*_tmpl.html'],
2012-07-09 20:16:06 +00:00
dest: './src'
},
2012-07-09 21:36:08 +00:00
coffee: {
dev: {
src: ['src/**/*.coffee'],
dest: 'src',
options: {
bare: false
}
}
},
2012-07-09 20:16:06 +00:00
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},
2012-07-09 21:41:26 +00:00
requirejs: {
dir: 'dist-compiled',
appDir: 'dist',
2012-07-09 21:41:26 +00:00
baseUrl: '.',
paths: {
2012-07-10 16:00:40 +00:00
jquery : '../libs/jquery/jquery-1.7.2'
2012-07-09 21:41:26 +00:00
},
pragmas: {
doExclude: true
},
modules: [{name: 'priority'}],
skipModuleInsertion: false,
optimizeAllPluginResources: true,
findNestedDependencies: true
},
2012-07-10 16:00:40 +00:00
install: {
src: [
'src/index.html',
'src/priority.js',
'src/*_tmpl.js',
'src/style.css',
'libs/jquery/jquery-1.7.2.js',
'libs/require.js' ],
dest: 'dist'
},
2012-07-09 21:36:08 +00:00
recess: {
dev: {
src: ['src/style.less'],
dest: 'src/style.css',
options: {
compile: true
}
}
},
2012-07-10 16:00:40 +00:00
mocha: {
src: ['test/*_mocha.coffee']
},
2012-07-09 20:16:06 +00:00
uglify: {}
});
// Default task.
grunt.registerTask('default', 'lint qunit concat min');
grunt.registerHelper('haml', function(src, dest, done) {
var args = {
cmd: 'haml',
args: ["--unix-newlines", "--no-escape-attrs", "--double-quote-attributes", src]
2012-07-10 16:00:40 +00:00
};
2012-07-09 20:16:06 +00:00
grunt.utils.spawn(args, function(err, result) {
if (err) console.log(err);
2012-07-09 20:16:06 +00:00
var out = path.basename(src, '.haml');
2012-07-10 16:00:40 +00:00
grunt.file.write(path.join(dest, out + '.html'), result.stdout);
done();
2012-07-09 20:16:06 +00:00
});
});
grunt.registerTask('haml', 'Compile HAML', function() {
var done = this.async(),
sources = grunt.file.expandFiles(grunt.config([this.name, 'src'])),
dest = grunt.config([this.name, 'dest']);
2012-07-10 16:00:40 +00:00
async.forEachSeries(sources,
function(path, cb) { grunt.helper('haml', path, dest, cb) },
2012-07-10 16:00:40 +00:00
done);
2012-07-09 20:16:06 +00:00
});
grunt.registerHelper('templatize', function(src, dest, done) {
var file = grunt.file.read(src),
out = path.basename(src, '.html');
2012-07-10 16:00:40 +00:00
grunt.file.write(path.join(dest, out + '.js'), 'define(' + _und.template(file).source + ');');
if (done) {
done();
}
2012-07-09 20:16:06 +00:00
});
grunt.registerTask('templatize', 'Compile Underscored HTML to Javascript', function() {
var done = this.async(),
sources = grunt.file.expandFiles(grunt.config([this.name, 'src'])),
dest = grunt.config([this.name, 'dest']);
2012-07-10 16:00:40 +00:00
if (sources.length === 0) {
2012-07-09 21:36:08 +00:00
return done();
2012-07-10 16:00:40 +00:00
}
async.forEachSeries(sources,
function(path, cb) { grunt.helper('templatize', path, dest, null); cb(); },
done);
});
grunt.registerTask('dev', 'coffee:dev recess:dev templatize haml install');
2012-07-09 20:16:06 +00:00
2012-07-10 16:00:40 +00:00
grunt.registerHelper('install', function(src, dest, done) {
grunt.file.copy(src, path.join(dest, path.basename(src)));
if (done) { done(); }
});
grunt.registerTask('install', function() {
var sources = grunt.file.expandFiles(grunt.config([this.name, 'src'])),
dest = grunt.config([this.name, 'dest']);
sources.forEach(function(path) { grunt.helper('install', path, dest, null);});
});
grunt.registerHelper('mocha', function(command, test, done) {
var args = {
cmd: 'mocha',
args: ['--compilers', 'coffee:coffee-script', '-R', 'dot', '-C', test]
};
grunt.utils.spawn(args, function(err, result) {
if (err) {
console.log(err.stderr)
done();
return;
}
console.log(result.stdout);
done();
2012-07-09 20:16:06 +00:00
});
});
2012-07-10 16:00:40 +00:00
grunt.registerTask('mocha', 'Run Mocha Tests', function() {
var done = this.async(),
task = this.name,
sources = grunt.file.expandFiles(grunt.config([this.name, 'src'])),
dest = grunt.config([this.name, 'dest']);
2012-07-09 20:16:06 +00:00
2012-07-10 16:00:40 +00:00
sources.sort();
async.forEachSeries(
sources,
function(path, cb) {
grunt.helper('mocha', grunt.config([task, 'cmd']), path, cb);
},
done);
});
2012-07-09 20:16:06 +00:00
};