-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
101 lines (89 loc) · 2.57 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Grunt jshint/watch boilerplate configuration.
*
* @author Ryan Nickell
*/
module.exports = function(grunt) {
/*
* Helper method to load configuration files for Grunt
*/
function loadConfig(path) {
var glob = require('glob');
var object = {};
var key;
glob.sync('*', {cwd: path}).forEach(function(option) {
key = option.replace(/\.js$/,'');
object[key] = require(path + option);
});
return object;
}
/*
* Establish what files need to be examined.
* The user must create a jshint-files.json file that contains:
* {
* "src" : [
* "file.js"
* ]
* }
*
* The same rules apply to globbing as you'd expect.
*/
var jshintSrc = [];
var jshintFilesJson = 'jshint-files.json';
if( grunt.file.exists( jshintFilesJson ) ) {
var jshintFile = grunt.file.readJSON( jshintFilesJson );
if( jshintFile.src && jshintFile.src.length ) {
jshintSrc = jshintFile.src;
}
} else {
console.log('');
console.log('----------------------------------------');
console.log('WARNING: No jshint-files.json file found');
console.log('----------------------------------------');
console.log('');
}
jshintSrc.push( 'Gruntfile.js' );
var config = {
pkg: grunt.file.readJSON('package.json'),
jshint: {
options: {
reporter: require('jshint-stylish'),
jshintrc: true
},
all: {
src: jshintSrc
}
},
watch: {
scripts: {
files: jshintSrc,
tasks: ['jshint'],
options: {
spawn: false
}
}
}
};
/*
* Merge any optional grunt configuration from the ./grunt/options/ directory.
*
* This is useful when you want to change the watch tasks configuration to execute
* additional tasks.
*/
grunt.util._.merge(config, loadConfig('./grunt/options/'));
// Project configuration.
grunt.initConfig(config);
/*
* Only JSHint the files that change by dynamically modifying the
* file list.
*
* See: https://github.com/gruntjs/grunt-contrib-watch
*/
grunt.event.on('watch', function(action, filepath, target) {
grunt.config('jshint.all.src', filepath);
});
// Load all available tasks
require('load-grunt-tasks')(grunt);
// Default task(s).
grunt.registerTask('default', ['jshint']);
};