h5ai/makefile.js

170 lines
3.4 KiB
JavaScript
Raw Normal View History

/*jshint node: true */
'use strict';
2012-09-13 18:25:20 -04:00
var path = require('path'),
2012-09-13 18:25:20 -04:00
pkg = require('./package.json'),
root = path.resolve(__dirname),
src = path.join(root, 'src'),
build = path.join(root, 'build'),
jshint = {
// Enforcing Options
bitwise: true,
curly: true,
eqeqeq: true,
forin: true,
latedef: true,
newcap: true,
noempty: true,
plusplus: true,
trailing: true,
undef: true,
// Environments
browser: true,
// Globals
predef: [
'modulejs'
]
},
2012-09-13 18:25:20 -04:00
handlebarsEnv = {
pkg: pkg
},
mapSrc = function (blob) {
2012-08-15 06:20:42 -04:00
return blob.source.replace(src, build).replace(/\.less$/, '.css').replace(/\.jade$/, '');
},
2012-09-13 18:25:20 -04:00
mapRoot = function (blob) {
2012-09-13 18:25:20 -04:00
return blob.source.replace(root, path.join(build, '_h5ai'));
};
module.exports = function (make) {
var Event = make.Event,
$ = make.fQuery,
2012-09-13 18:25:20 -04:00
moment = make.moment;
2012-09-18 10:30:17 -04:00
make.version('>=0.8.1');
make.defaults('build');
make.before(function () {
2012-09-13 18:25:20 -04:00
handlebarsEnv.stamp = moment().format('YYYY-MM-DD HH:mm:ss');
});
2012-09-13 18:25:20 -04:00
make.target('check-version', [], 'add git info to dev builds').async(function (done, fail) {
2012-09-13 18:25:20 -04:00
if (!/-dev$/.test(pkg.version)) {
done();
return;
}
2012-09-13 18:25:20 -04:00
$.git(root, function (err, result) {
2012-09-18 10:30:17 -04:00
pkg.version += '-' + result.revListOriginMasterHead.length + '-' + result.revParseHead.slice(0, 7);
2012-09-13 18:25:20 -04:00
Event.info({
method: 'check-version',
message: 'version set to ' + pkg.version
});
2012-09-13 18:25:20 -04:00
done();
});
2012-09-13 18:25:20 -04:00
});
2012-09-13 18:25:20 -04:00
make.target('clean', [], 'delete build folder').sync(function () {
2012-09-13 18:25:20 -04:00
$.rmfr($.I_AM_SURE, build);
});
2012-09-13 18:25:20 -04:00
make.target('lint', [], 'lint all JavaScript files with JSHint').sync(function () {
2012-10-05 13:55:48 -04:00
$(src + '/_h5ai/client/js: **/*.js, ! lib/**')
2012-09-13 18:25:20 -04:00
.jshint(jshint);
});
2012-09-13 18:25:20 -04:00
make.target('build', ['check-version'], 'build all updated files').sync(function () {
2012-10-05 13:55:48 -04:00
$(src + ': _h5ai/client/js/*.js')
.modified(mapSrc, $(src + ': _h5ai/client/js/**'))
2012-09-13 18:25:20 -04:00
.includify()
.uglifyjs()
.write($.OVERWRITE, mapSrc);
2012-10-05 13:55:48 -04:00
$(src + ': _h5ai/client/css/*.less')
.modified(mapSrc, $(src + ': _h5ai/client/css/**'))
2012-09-13 18:25:20 -04:00
.less()
.cssmin()
.write($.OVERWRITE, mapSrc);
2012-09-13 18:25:20 -04:00
$(src + ': **/*.jade')
.modified(mapSrc)
.handlebars(handlebarsEnv)
.jade()
.write($.OVERWRITE, mapSrc);
2012-10-05 14:00:45 -04:00
$(src + ': **, ! _h5ai/client/js/**, ! _h5ai/client/css/**, ! **/*.jade')
2012-09-13 18:25:20 -04:00
.modified(mapSrc)
.handlebars(handlebarsEnv)
.write($.OVERWRITE, mapSrc);
2012-09-13 18:25:20 -04:00
$(root + ': README*, LICENSE*')
.modified(mapRoot)
.write($.OVERWRITE, mapRoot);
});
2012-09-13 18:25:20 -04:00
make.target('build-uncompressed', ['check-version'], 'build all updated files without compression').sync(function () {
2012-10-05 13:55:48 -04:00
$(src + ': _h5ai/client/js/*.js')
.modified(mapSrc, $(src + ': _h5ai/client/js/**'))
2012-09-13 18:25:20 -04:00
.includify()
// .uglifyjs()
.write($.OVERWRITE, mapSrc);
2012-10-05 13:55:48 -04:00
$(src + ': _h5ai/client/css/*.less')
.modified(mapSrc, $(src + ': _h5ai/client/css/**'))
2012-09-13 18:25:20 -04:00
.less()
// .cssmin()
.write($.OVERWRITE, mapSrc);
2012-09-13 18:25:20 -04:00
$(src + ': **/*.jade')
.modified(mapSrc)
.handlebars(handlebarsEnv)
.jade()
.write($.OVERWRITE, mapSrc);
2012-10-05 13:55:48 -04:00
$(src + ': **, ! _h5ai/client/js/**, ! _h5ai/client/css/**, ! **/*.jade')
2012-09-13 18:25:20 -04:00
.modified(mapSrc)
.handlebars(handlebarsEnv)
.write($.OVERWRITE, mapSrc);
2012-09-13 18:25:20 -04:00
$(root + ': README*, LICENSE*')
.modified(mapRoot)
.write($.OVERWRITE, mapRoot);
});
2012-09-13 18:25:20 -04:00
make.target('release', ['clean', 'build'], 'create a zipball').async(function (done, fail) {
2012-10-05 13:55:48 -04:00
$(build + ': **').shzip({
2012-10-05 14:29:37 -04:00
target: path.join(build, pkg.name + '-' + pkg.version + '.zip'),
2012-09-13 18:25:20 -04:00
dir: build,
callback: done
});
2012-09-13 18:25:20 -04:00
});
};