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-08-23 22:35:06 +08:00
|
|
|
var SHELL_CONFIG = require('./private/config/server/shell.yaml');
|
|
|
|
var PROD_SHELL_CONFIG = require('./private/config/production/server/shell.yaml');
|
2016-04-29 06:27:43 +08:00
|
|
|
|
|
|
|
// root URL in development/production:
|
2016-08-24 05:35:28 +08:00
|
|
|
var rootURL = (SHELL_CONFIG.shell.rootURL == undefined)
|
2016-05-31 06:07:02 +08:00
|
|
|
? 'http://127.0.0.1/html5client'
|
2016-08-24 05:35:28 +08:00
|
|
|
: SHELL_CONFIG.shell.rootURL;
|
2016-04-29 06:27:43 +08:00
|
|
|
|
2016-08-23 22:35:06 +08:00
|
|
|
// command line string containing the Meteor's home directory in production:
|
2016-08-24 05:35:28 +08:00
|
|
|
var prodHomeStr = (PROD_SHELL_CONFIG.shell.home == undefined) ? ''
|
|
|
|
: ('HOME=' + PROD_SHELL_CONFIG.shell.home + ' ');
|
2016-04-29 06:27:43 +08:00
|
|
|
|
|
|
|
// final commands:
|
2016-08-23 22:35:06 +08:00
|
|
|
var METEOR_DEV_COMMAND = 'ROOT_URL=' +
|
|
|
|
rootURL + ' NODE_ENV=development' + ' meteor';
|
2016-05-31 06:07:02 +08:00
|
|
|
var METEOR_PROD_COMMAND = prodHomeStr + 'ROOT_URL=' +
|
2016-08-23 22:35:06 +08:00
|
|
|
rootURL + ' NODE_ENV=production' + ' meteor';
|
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-08-17 23:48:03 +08:00
|
|
|
command: METEOR_PROD_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
|
|
|
};
|