-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
106 lines (87 loc) · 3.03 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
102
103
104
105
106
'use strict';
module.exports = function (grunt) {
var fs = require('fs'),
// These are pairs [task, target] for which a copied tasks with an additional
// filter option are created. Those tasks are then passed to the watch task
// to be fired on file changes; the filter option makes sure tasks are fired
// only on changed files, making them a lot faster. Unfortunately, we can't
// just apply a filter to the basic configuration as no files would be
// processed during initial runs.
filteredTasks = [
['jshint', 'main'],
['jshint', 'src'],
['jshint', 'tests'],
['jsonlint', 'all'],
];
function filterNewFiles(src) {
// Returns a function that tells if a file was recently modified;
// it's used by jshint & defs tasks so that they run only on changed files.
var srcTime = fs.statSync(src).mtime.getTime();
// Don't watch files changed before last 10 seconds.
return srcTime > Date.now() - 10000;
}
grunt.initConfig({
compile: require('./grunt/config/compile'),
clean: require('./grunt/config/clean'),
copy: require('./grunt/config/copy'),
docco: require('./grunt/config/docco'),
jshint: require('./grunt/config/lint/jshint'),
jscoverage: require('./grunt/config/jscoverage'),
jsonlint: require('./grunt/config/lint/jsonlint'),
'merge-conflict': require('./grunt/config/lint/merge-conflict'),
mochaTest: require('./grunt/config/mocha-test'),
shell: require('./grunt/config/shell'),
uglify: require('./grunt/config/uglify'),
watch: require('./grunt/config/watch'),
});
// Add copies of watched tasks with an added filter option.
filteredTasks.forEach(function (taskAndTarget) {
var newTaskAndTarget = taskAndTarget.slice(0);
newTaskAndTarget[newTaskAndTarget.length - 1] =
newTaskAndTarget[newTaskAndTarget.length - 1] + 'Filtered';
grunt.config(newTaskAndTarget, grunt.config(taskAndTarget));
grunt.config(newTaskAndTarget.concat(['filter']), filterNewFiles);
});
// Load all grunt tasks matching the `grunt-*` pattern.
require('load-grunt-tasks')(grunt);
// Load all custom tasks.
grunt.loadTasks('grunt/tasks');
grunt.registerTask('install-git-hook', 'copy:install-git-hook');
grunt.registerTask('server', [
'build',
'watch',
]);
grunt.registerTask('lint', [
'jshint:main',
'jshint:src',
'jshint:tests',
'jsonlint:all',
]);
grunt.registerTask('build', [
'clean',
'compile:html',
'uglify:html',
]);
grunt.registerTask('gh-pages', [
'docco',
'shell:gh-pages',
]);
grunt.registerTask('reference', ['shell:reference']);
grunt.registerTask('perf', ['shell:perf']);
grunt.registerTask('test', ['mochaTest:dot']);
// TODO first make sure `dist/docs` exists.
grunt.registerTask('coverage', function () {
process.env.L20N_COV = 1;
grunt.file.mkdir('dist/docs');
grunt.task.run([
'jscoverage',
'mochaTest:coverage',
]);
});
grunt.registerTask('default', [
'merge-conflict',
'lint',
'build',
'test',
]);
};