2014-10-03 01:14:41 +08:00
|
|
|
/* jshint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-14 09:46:29 +08:00
|
|
|
module.exports = function (grunt) {
|
2016-03-13 09:21:27 +08:00
|
|
|
|
|
|
|
require('load-grunt-tasks')(grunt);
|
|
|
|
|
2016-04-29 06:27:43 +08:00
|
|
|
// importing the Meteor settings:
|
2016-05-16 22:35:59 +08:00
|
|
|
var SETTINGS_DEV = require('./settings-development.json');
|
|
|
|
var SETTINGS_PROD = require('./settings-production.json');
|
2016-04-29 06:27:43 +08:00
|
|
|
|
|
|
|
// root URL in development/production:
|
2016-05-31 06:07:02 +08:00
|
|
|
var devRootURL = (SETTINGS_DEV.rootURL == undefined)
|
|
|
|
? 'http://127.0.0.1/html5client'
|
|
|
|
: SETTINGS_DEV.rootURL;
|
|
|
|
var prodRootURL = (SETTINGS_PROD.rootURL == undefined)
|
|
|
|
? 'http://127.0.0.1/html5client'
|
|
|
|
: SETTINGS_PROD.rootURL;
|
2016-04-29 06:27:43 +08:00
|
|
|
|
|
|
|
// command line string containing the Meteor's home directory in development/production:
|
2016-05-16 22:35:59 +08:00
|
|
|
var devHomeStr = (SETTINGS_DEV.home == undefined) ? '' : ('HOME=' + SETTINGS_DEV.home + ' ');
|
|
|
|
var prodHomeStr = (SETTINGS_PROD.home == undefined) ? '' : ('HOME=' + SETTINGS_PROD.home + ' ');
|
2016-04-29 06:27:43 +08:00
|
|
|
|
|
|
|
// final commands:
|
2016-05-31 06:07:02 +08:00
|
|
|
var METEOR_DEV_COMMAND = devHomeStr + 'ROOT_URL=' +
|
|
|
|
devRootURL + ' meteor --settings settings-development.json';
|
|
|
|
var METEOR_PROD_COMMAND = prodHomeStr + 'ROOT_URL=' +
|
|
|
|
prodRootURL + ' meteor --settings settings-production.json';
|
2016-04-29 06:27:43 +08:00
|
|
|
|
2014-10-03 01:14:41 +08:00
|
|
|
// configure Grunt
|
|
|
|
grunt.initConfig({
|
2016-03-13 09:21:27 +08:00
|
|
|
|
2016-03-21 10:43:08 +08:00
|
|
|
watch: {
|
|
|
|
scripts: {
|
|
|
|
files: ['**/*.js', '**/*.jsx'],
|
2016-05-06 06:09:13 +08:00
|
|
|
tasks: ['force:newer:jscs:check'],
|
2016-03-21 10:43:08 +08:00
|
|
|
options: {
|
|
|
|
event: ['all'],
|
2016-04-23 07:19:17 +08:00
|
|
|
spawn: true,
|
2016-03-21 10:43:08 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2016-03-13 09:21:27 +08:00
|
|
|
jscs: {
|
2016-03-14 08:12:01 +08:00
|
|
|
check: {
|
|
|
|
src: ['**/*.js', '**/*.jsx'],
|
|
|
|
options: {
|
|
|
|
config: '.jscsrc',
|
|
|
|
verbose: true,
|
|
|
|
esnext: true,
|
|
|
|
},
|
|
|
|
},
|
2016-04-23 07:19:17 +08:00
|
|
|
autofix: {
|
2016-03-14 08:12:01 +08:00
|
|
|
src: ['**/*.js', '**/*.jsx'],
|
|
|
|
options: {
|
|
|
|
config: '.jscsrc',
|
|
|
|
verbose: true,
|
|
|
|
esnext: true,
|
|
|
|
fix: true,
|
|
|
|
},
|
|
|
|
},
|
2016-03-13 09:21:27 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
shell: {
|
2016-04-25 20:56:49 +08:00
|
|
|
start_meteor_development: {
|
2016-05-16 22:35:59 +08:00
|
|
|
command: METEOR_DEV_COMMAND,
|
2016-03-14 09:46:29 +08:00
|
|
|
},
|
2016-04-25 20:56:49 +08:00
|
|
|
start_meteor_production: {
|
2016-05-16 22:35:59 +08:00
|
|
|
command: METEOR_DEV_COMMAND,
|
2016-04-29 06:42:04 +08:00
|
|
|
},
|
2016-03-14 09:46:29 +08:00
|
|
|
},
|
2016-03-21 10:43:08 +08:00
|
|
|
|
|
|
|
concurrent: {
|
|
|
|
options: {
|
|
|
|
logConcurrentOutput: true,
|
|
|
|
limit: 3,
|
|
|
|
},
|
2016-04-25 20:56:49 +08:00
|
|
|
meteor_watch_development: {
|
2016-04-29 06:42:04 +08:00
|
|
|
tasks: ['shell:start_meteor_development', 'watch'],
|
2016-04-25 20:56:49 +08:00
|
|
|
},
|
|
|
|
meteor_watch_production: {
|
2016-04-29 06:42:04 +08:00
|
|
|
tasks: ['shell:start_meteor_production', 'watch'],
|
2016-03-21 10:43:08 +08:00
|
|
|
},
|
2016-04-23 07:19:17 +08:00
|
|
|
},
|
2014-10-03 01:14:41 +08:00
|
|
|
});
|
|
|
|
|
2016-03-13 09:21:27 +08:00
|
|
|
grunt.loadNpmTasks('grunt-jscs');
|
|
|
|
grunt.loadNpmTasks('grunt-force-task');
|
2016-03-21 10:43:08 +08:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
|
|
grunt.loadNpmTasks('grunt-shell');
|
|
|
|
grunt.loadNpmTasks('grunt-concurrent');
|
2016-05-06 06:09:13 +08:00
|
|
|
grunt.loadNpmTasks('grunt-newer');
|
2014-10-03 01:14:41 +08:00
|
|
|
|
2016-04-26 23:03:09 +08:00
|
|
|
var mode = (grunt.option('mode') == 'production') ? 'production' : 'development';
|
2016-04-25 20:56:49 +08:00
|
|
|
|
2016-03-13 09:21:27 +08:00
|
|
|
// sets the default task to run JSCS first (forcing our way past warnings) and then start Meteor:
|
2016-05-06 06:09:13 +08:00
|
|
|
grunt.registerTask('default', ['force:newer:jscs:check', 'concurrent:meteor_watch_' + mode]);
|
2016-03-14 08:12:01 +08:00
|
|
|
|
|
|
|
// sets the autofix task to fix JSCS warning when possible and then start Meteor:
|
2016-05-06 06:09:13 +08:00
|
|
|
grunt.registerTask('autofix', ['force:newer:jscs:autofix', 'concurrent:meteor_watch_' + mode]);
|
2016-05-06 06:17:34 +08:00
|
|
|
|
|
|
|
// runs the linter task:
|
2016-05-06 06:27:27 +08:00
|
|
|
grunt.registerTask('quicklint', ['force:jscs:check']);
|
2016-05-06 06:17:34 +08:00
|
|
|
|
|
|
|
// runs the linter task and autofixes errors when possible:
|
2016-05-06 06:27:27 +08:00
|
|
|
grunt.registerTask('quickfix', ['force:jscs:autofix']);
|
2014-10-03 01:14:41 +08:00
|
|
|
};
|