h5ai/mkrfile.js

168 lines
4.7 KiB
JavaScript
Raw Normal View History

/*jshint node: true */
'use strict';
2014-08-23 00:00:58 +02:00
var path = require('path');
var $ = require('fquery');
2014-08-23 00:00:58 +02:00
var pkg = require('./package.json');
2014-08-23 00:00:58 +02:00
var root = path.resolve(__dirname);
var src = path.join(root, 'src');
var build = path.join(root, 'build');
2014-08-17 01:38:06 +02:00
2015-04-14 04:21:05 +02:00
function getBuildSuffixSync() {
try {
var out = require('child_process').execSync('git rev-list v' + pkg.version + '..HEAD', {cwd: root, encoding: 'utf8'});
var lines = out.trim().split(/\r?\n/);
return '+' + ('000' + lines.length).substr(-3) + '~' + lines[0].substring(0, 7);
} catch (e) {}
return '+X';
2014-08-30 18:53:16 +02:00
}
2014-08-23 00:00:58 +02:00
2015-04-09 01:50:20 +02:00
$.plugin('fquery-autoprefixer');
2014-08-23 00:00:58 +02:00
$.plugin('fquery-cssmin');
$.plugin('fquery-handlebars');
$.plugin('fquery-includeit');
$.plugin('fquery-jade');
$.plugin('fquery-jshint');
$.plugin('fquery-jszip');
$.plugin('fquery-less');
$.plugin('fquery-uglifyjs');
2014-08-17 01:38:06 +02:00
2014-08-17 17:30:22 +02:00
2014-08-23 00:00:58 +02:00
module.exports = function (suite) {
2014-08-23 00:00:58 +02:00
suite.defaults('release');
2015-04-14 04:21:05 +02:00
suite.target('check-version', [], 'add git info to dev builds').task(function () {
2015-04-14 04:21:05 +02:00
if (pkg.develop) {
pkg.version += getBuildSuffixSync();
2014-08-30 14:19:06 +02:00
$.report({type: 'info', method: 'check-version', message: 'version set to ' + pkg.version});
2015-04-14 04:21:05 +02:00
}
2014-08-15 22:07:53 +02:00
});
2014-08-23 00:00:58 +02:00
suite.target('clean', [], 'delete build folder').task(function () {
2014-08-23 00:00:58 +02:00
$(build, {dirs: true}).delete();
2014-08-15 22:07:53 +02:00
});
2014-08-23 00:00:58 +02:00
suite.target('lint', [], 'lint all JavaScript files with JSHint').task(function () {
2015-04-14 01:38:49 +02:00
var fs = require('fs');
var jshint = JSON.parse(fs.readFileSync('.jshintrc', 'utf8'));
2013-08-13 00:36:39 +02:00
2014-08-15 22:07:53 +02:00
$(src + '/_h5ai/client/js: **/*.js, ! lib/**')
2015-04-14 01:38:49 +02:00
.jshint(jshint, jshint.globals);
2014-08-15 22:07:53 +02:00
});
2015-04-10 20:48:26 +02:00
suite.target('build', ['check-version', 'lint'], 'build all updated files, optionally use :uncompressed (e.g. mkr build :uncompressed)').task(function () {
2014-08-16 13:52:45 +02:00
var header = '/* ' + pkg.name + ' ' + pkg.version + ' - ' + pkg.homepage + ' */\n';
2014-08-30 18:53:16 +02:00
var env = {pkg: pkg};
2015-04-14 03:19:50 +02:00
var mapSrc = $.map.p(src, build).s('.less', '.css').s('.jade', '');
var mapRoot = $.map.p(root, path.join(build, '_h5ai'));
2013-08-16 16:22:23 +02:00
2014-08-15 22:07:53 +02:00
$(src + ': _h5ai/client/js/*.js')
.newerThan(mapSrc, $(src + ': _h5ai/client/js/**'))
2014-08-23 00:00:58 +02:00
.includeit()
2015-04-09 23:22:37 +02:00
.if(!suite.args.uncompressed, function () { this.uglifyjs(); })
2014-08-16 13:52:45 +02:00
.wrap(header)
2014-08-23 00:00:58 +02:00
.write(mapSrc, true);
2014-08-15 22:07:53 +02:00
$(src + ': _h5ai/client/css/*.less')
.newerThan(mapSrc, $(src + ': _h5ai/client/css/**'))
2015-04-25 21:13:25 +02:00
.includeit()
2014-08-15 22:07:53 +02:00
.less()
2015-03-29 01:59:39 +01:00
.autoprefixer()
2015-04-09 23:22:37 +02:00
.if(!suite.args.uncompressed, function () { this.cssmin(); })
2014-08-16 13:52:45 +02:00
.wrap(header)
2014-08-23 00:00:58 +02:00
.write(mapSrc, true);
2014-09-04 00:55:27 +02:00
$(src + ': **/*.jade')
2014-08-15 22:07:53 +02:00
.newerThan(mapSrc)
2014-09-04 00:55:27 +02:00
.jade(env)
2014-08-23 00:00:58 +02:00
.write(mapSrc, true);
2014-09-04 00:55:27 +02:00
$(src + ': **, ! _h5ai/client/js/**, ! _h5ai/client/css/**, ! **/*.jade')
2014-08-15 22:07:53 +02:00
.newerThan(mapSrc)
2014-09-04 00:55:27 +02:00
.handlebars(env)
2014-08-23 00:00:58 +02:00
.write(mapSrc, true);
2014-06-18 17:58:59 +02:00
2014-08-15 22:07:53 +02:00
$(root + ': *.md')
.newerThan(mapRoot)
2014-08-23 00:00:58 +02:00
.write(mapRoot, true);
2014-08-15 22:07:53 +02:00
});
2015-04-09 23:22:37 +02:00
suite.target('deploy', ['build'], 'deploy to a specified path (e.g. mkr deploy :dest=/some/path)').task(function () {
2015-04-09 23:22:37 +02:00
if (!$._.isString(suite.args.dest)) {
$.report({
type: 'err',
message: 'no destination path (e.g. mkr deploy :dest=/some/path)'
});
}
2014-08-15 22:07:53 +02:00
2015-04-09 23:22:37 +02:00
var mapper = $.map.p(build, path.resolve(suite.args.dest));
2014-06-18 17:58:59 +02:00
2015-04-09 23:22:37 +02:00
$(build + ': _h5ai/**')
.newerThan(mapper)
.write(mapper, true);
2014-08-15 22:07:53 +02:00
});
2014-08-23 00:00:58 +02:00
suite.target('release', ['clean', 'build'], 'create a zipball').task(function () {
2014-08-15 22:07:53 +02:00
2014-08-23 00:00:58 +02:00
var target = path.join(build, pkg.name + '-' + pkg.version + '.zip');
$(build + ': **')
2015-04-07 18:33:20 +02:00
.jszip({dir: build, level: 9})
2014-08-23 00:00:58 +02:00
.write(target, true);
2014-08-15 22:07:53 +02:00
});
2015-04-18 13:53:05 +02:00
suite.target('build-test', ['check-version'], 'build a test suite').task(function () {
var env = {pkg: pkg};
$(src + '/_h5ai/client/css/styles.less')
2015-04-25 21:13:25 +02:00
.includeit()
.less()
.autoprefixer()
.write(build + '/test/h5ai-styles.css', true);
$(src + '/_h5ai/client/js/scripts.js')
.includeit()
.write(build + '/test/h5ai-scripts.js', true);
$(root + '/test/styles.less')
2015-04-25 21:13:25 +02:00
.includeit()
.less()
.autoprefixer()
.write(build + '/test/styles.css', true);
$(root + '/test/scripts.js')
.includeit()
.write(build + '/test/scripts.js', true);
$(root + '/test/index.html.jade')
2015-04-18 13:53:05 +02:00
.jade(env)
.write(build + '/test/index.html', true);
$.report({
type: 'info',
message: 'browse to file://' + build + '/test/index.html'
});
});
};