2013-09-14 04:52:13 +08:00
|
|
|
/* jshint node:true */
|
2013-07-21 05:56:59 +08:00
|
|
|
'use strict';
|
|
|
|
module.exports = function (grunt) {
|
|
|
|
|
2013-09-14 04:52:13 +08:00
|
|
|
var config = {
|
2013-07-21 05:56:59 +08:00
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
2013-11-15 12:29:41 +08:00
|
|
|
baseDir: '.',
|
2013-09-14 04:52:13 +08:00
|
|
|
srcDir: 'src',
|
|
|
|
destDir: 'dist',
|
|
|
|
tempDir: 'tmp',
|
2013-12-03 03:43:39 +08:00
|
|
|
docsDir: 'docs/'
|
2013-09-14 04:52:13 +08:00
|
|
|
};
|
|
|
|
|
2015-02-05 19:27:58 +08:00
|
|
|
config.mode = grunt.option('mode') || 'backend';
|
2014-12-31 23:19:45 +08:00
|
|
|
config.modeOptions = {
|
2015-01-05 00:51:48 +08:00
|
|
|
zipSuffix: '',
|
2014-12-31 23:19:45 +08:00
|
|
|
requirejs: {
|
|
|
|
paths: { config: '../config.sample' },
|
|
|
|
excludeConfig: true,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (config.mode === 'backend') {
|
2015-01-05 00:51:48 +08:00
|
|
|
grunt.log.writeln('Setting backend build mode');
|
|
|
|
config.modeOptions.zipSuffix = '-backend';
|
2015-01-05 18:04:58 +08:00
|
|
|
config.modeOptions.requirejs.paths = {};
|
2015-01-05 15:47:29 +08:00
|
|
|
config.modeOptions.requirejs.excludeConfig = false;
|
2014-12-31 23:19:45 +08:00
|
|
|
}
|
|
|
|
|
2013-11-15 07:07:14 +08:00
|
|
|
// load plugins
|
|
|
|
require('load-grunt-tasks')(grunt);
|
2013-09-20 01:17:42 +08:00
|
|
|
|
2013-11-15 07:07:14 +08:00
|
|
|
// load task definitions
|
|
|
|
grunt.loadTasks('tasks');
|
2013-10-18 06:33:43 +08:00
|
|
|
|
2013-11-15 11:30:28 +08:00
|
|
|
// Utility function to load plugin settings into config
|
|
|
|
function loadConfig(config,path) {
|
2013-11-15 07:07:14 +08:00
|
|
|
require('glob').sync('*', {cwd: path}).forEach(function(option) {
|
2013-11-15 11:30:28 +08:00
|
|
|
var key = option.replace(/\.js$/,'');
|
|
|
|
// If key already exists, extend it. It is your responsibility to avoid naming collisions
|
|
|
|
config[key] = config[key] || {};
|
2013-11-16 00:44:06 +08:00
|
|
|
grunt.util._.extend(config[key], require(path + option)(config,grunt));
|
2013-09-20 01:17:42 +08:00
|
|
|
});
|
2013-11-15 11:30:28 +08:00
|
|
|
// technically not required
|
|
|
|
return config;
|
2013-11-15 07:07:14 +08:00
|
|
|
}
|
2013-09-20 04:45:09 +08:00
|
|
|
|
2013-11-15 07:07:14 +08:00
|
|
|
// Merge that object with what with whatever we have here
|
2013-11-15 11:30:28 +08:00
|
|
|
loadConfig(config,'./tasks/options/');
|
2013-09-20 01:17:42 +08:00
|
|
|
|
|
|
|
// pass the config to grunt
|
|
|
|
grunt.initConfig(config);
|
2014-08-11 22:37:31 +08:00
|
|
|
};
|