2013-07-25 09:46:03 +02:00
|
|
|
module.exports = function(grunt) {
|
2015-01-05 05:42:11 +01:00
|
|
|
var path = require('path');
|
2013-07-30 22:28:26 +02:00
|
|
|
var cfg = require('./package.json');
|
2013-07-25 09:46:03 +02:00
|
|
|
grunt.initConfig({
|
2014-07-06 17:32:06 +02:00
|
|
|
jst: {
|
|
|
|
compile: {
|
|
|
|
options: {
|
2015-01-16 22:07:27 +01:00
|
|
|
namespace: 'templates',
|
2014-07-06 17:32:06 +02:00
|
|
|
templateSettings: {
|
|
|
|
evaluate : /\{\[([\s\S]+?)\]\}/g,
|
|
|
|
interpolate : /\{\{([\s\S]+?)\}\}/g
|
|
|
|
},
|
|
|
|
processName: function (filepath) {
|
|
|
|
// E.g. src/templates/trimmed_chat.html
|
|
|
|
return filepath.match(/src\/templates\/([a-z_]+)\.html/)[1];
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
files: {
|
|
|
|
"builds/templates.js": ["src/templates/*.html"]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-16 22:07:27 +01:00
|
|
|
json: {
|
|
|
|
main: {
|
|
|
|
options: {
|
|
|
|
namespace: 'locales',
|
|
|
|
includePath: true,
|
|
|
|
processName: function(filename) {
|
|
|
|
return filename.toLowerCase().match(/^locale\/(.*)\/lc_messages/)[1];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
src: ['locale/**/LC_MESSAGES/*.json'],
|
|
|
|
dest: 'builds/locales.js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-25 09:46:03 +02:00
|
|
|
jshint: {
|
2013-07-28 22:51:25 +02:00
|
|
|
options: {
|
|
|
|
trailing: true
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
src : [
|
|
|
|
'converse.js',
|
|
|
|
'mock.js',
|
|
|
|
'main.js',
|
|
|
|
'tests_main.js',
|
|
|
|
'spec/*.js'
|
|
|
|
]
|
|
|
|
}
|
2013-07-30 21:41:55 +02:00
|
|
|
},
|
|
|
|
cssmin: {
|
|
|
|
options: {
|
|
|
|
banner: "/*"+
|
|
|
|
"* Converse.js (Web-based XMPP instant messaging client) \n"+
|
|
|
|
"* http://conversejs.org \n"+
|
|
|
|
"* Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com> \n"+
|
|
|
|
"* Dual licensed under the MIT and GPL Licenses \n"+
|
|
|
|
"*/"
|
|
|
|
},
|
|
|
|
minify: {
|
2014-06-29 20:49:22 +02:00
|
|
|
dest: 'css/converse.min.css',
|
|
|
|
src: ['css/converse.css']
|
2013-07-30 21:41:55 +02:00
|
|
|
}
|
2015-01-05 05:42:11 +01:00
|
|
|
},
|
|
|
|
touch: {
|
|
|
|
npm: ['stamp-npm'],
|
|
|
|
bower: ['stamp-bower']
|
2013-07-25 09:46:03 +02:00
|
|
|
}
|
|
|
|
});
|
2013-07-30 21:41:55 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
2013-07-25 09:46:03 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
2014-07-06 17:32:06 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-jst');
|
2015-01-16 22:07:27 +01:00
|
|
|
grunt.loadNpmTasks('grunt-json');
|
2013-07-30 21:41:55 +02:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
2015-01-05 05:42:11 +01:00
|
|
|
grunt.loadNpmTasks('grunt-touch');
|
2013-07-30 21:41:55 +02:00
|
|
|
|
2013-07-28 22:51:25 +02:00
|
|
|
grunt.registerTask('test', 'Run Tests', function () {
|
|
|
|
var done = this.async();
|
|
|
|
var child_process = require('child_process');
|
|
|
|
var exec = child_process.exec;
|
2013-07-30 23:39:24 +02:00
|
|
|
exec('./node_modules/.bin/phantomjs '+
|
2013-07-28 22:51:25 +02:00
|
|
|
'node_modules/jasmine-reporters/test/phantomjs-testrunner.js '+
|
|
|
|
__dirname+'/tests.html',
|
|
|
|
function (err, stdout, stderr) {
|
|
|
|
if (err) {
|
|
|
|
grunt.log.write('Tests failed with error code '+err.code);
|
|
|
|
grunt.log.write(stderr);
|
|
|
|
}
|
|
|
|
grunt.log.write(stdout);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-07-29 23:13:31 +02:00
|
|
|
|
2013-07-30 21:41:55 +02:00
|
|
|
grunt.registerTask('fetch', 'Set up the development environment', function () {
|
2013-07-29 23:13:31 +02:00
|
|
|
var done = this.async();
|
|
|
|
var child_process = require('child_process');
|
|
|
|
var exec = child_process.exec;
|
2014-03-17 21:37:40 +01:00
|
|
|
exec('./node_modules/.bin/bower update',
|
2013-07-29 23:13:31 +02:00
|
|
|
function (err, stdout, stderr) {
|
|
|
|
if (err) {
|
|
|
|
grunt.log.write('build failed with error code '+err.code);
|
|
|
|
grunt.log.write(stderr);
|
|
|
|
}
|
|
|
|
grunt.log.write(stdout);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-10-05 08:46:53 +02:00
|
|
|
grunt.registerTask('jsmin', 'Create a new release', function () {
|
|
|
|
var done = this.async();
|
|
|
|
var child_process = require('child_process');
|
|
|
|
var exec = child_process.exec;
|
2013-11-17 15:55:38 +01:00
|
|
|
var callback = function (err, stdout, stderr) {
|
2015-01-05 05:42:11 +01:00
|
|
|
grunt.log.write(stdout);
|
2013-11-17 15:55:38 +01:00
|
|
|
if (err) {
|
|
|
|
grunt.log.write('build failed with error code '+err.code);
|
|
|
|
grunt.log.write(stderr);
|
2015-01-05 05:42:11 +01:00
|
|
|
done(false);
|
|
|
|
} else
|
|
|
|
done();
|
2013-11-17 15:55:38 +01:00
|
|
|
};
|
2015-01-05 05:42:11 +01:00
|
|
|
var rjsext = (process.platform === 'win32') ? '.cmd' : '';
|
|
|
|
var rjs = path.resolve('./node_modules/.bin/r.js' + rjsext);
|
|
|
|
exec(rjs + ' -o src/build.js && ' +
|
|
|
|
rjs + ' -o src/build.js optimize=none out=builds/converse.js && ' +
|
|
|
|
rjs + ' -o src/build-no-jquery.js &&' +
|
|
|
|
rjs + ' -o src/build-no-jquery.js optimize=none out=builds/converse.nojquery.js && ' +
|
|
|
|
rjs + ' -o src/build-no-locales-no-otr.js && ' +
|
|
|
|
rjs + ' -o src/build-no-locales-no-otr.js optimize=none out=builds/converse-no-locales-no-otr.js && ' +
|
|
|
|
rjs + ' -o src/build-no-otr.js &&' +
|
|
|
|
rjs + ' -o src/build-no-otr.js optimize=none out=builds/converse-no-otr.js && ' +
|
|
|
|
rjs + ' -o src/build-website-no-otr.js &&' +
|
|
|
|
rjs + ' -o src/build-website.js', callback);
|
2014-10-28 17:43:39 +01:00
|
|
|
// XXX: It might be possible to not have separate build config files. For example:
|
|
|
|
// 'r.js -o src/build.js paths.converse-dependencies=src/deps-no-otr paths.locales=locale/nolocales out=builds/converse-no-locales-no-otr.min.js'
|
2013-10-05 08:46:53 +02:00
|
|
|
});
|
|
|
|
|
2014-12-07 01:19:01 +01:00
|
|
|
grunt.registerTask('minify', 'Create a new minified builds', ['cssmin', 'jsmin']);
|
2013-07-30 21:41:55 +02:00
|
|
|
|
2013-07-29 23:13:31 +02:00
|
|
|
grunt.registerTask('check', 'Perform all checks (e.g. before releasing)', function () {
|
2013-07-28 22:51:25 +02:00
|
|
|
grunt.task.run('jshint', 'test');
|
|
|
|
});
|
2013-07-25 09:46:03 +02:00
|
|
|
};
|