forked from zbraniecki/l20n.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
118 lines (99 loc) · 2.94 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
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
/* jshint node:true */
var fs = require('fs');
module.exports = function (grunt) {
// 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.
var 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;
}
// Load all grunt tasks matching the `grunt-*` pattern.
require('load-grunt-tasks')(grunt);
grunt.loadTasks('./build/tasks');
grunt.initConfig({
copy: require('./build/copy'),
clean: require('./build/clean'),
jshint: require('./build/lint/jshint'),
jsonlint: require('./build/lint/jsonlint'),
karma: require('./build/karma'),
'merge-conflict': require('./build/lint/merge-conflict'),
mochaTest: require('./build/mocha-test'),
rollup: require('./build/rollup'),
shell: require('./build/shell'),
uglify: require('./build/uglify'),
watch: require('./build/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);
});
grunt.registerTask('reference', ['shell:reference']);
grunt.registerTask('perf', ['shell:perf']);
grunt.registerTask('lint', [
'jshint:main',
'jshint:src',
'jshint:tests',
'jsonlint:all',
]);
grunt.registerTask('test', [
'mochaTest:dot'
]);
grunt.registerTask('test-browser', [
'rollup:testing',
'compat:testing',
'karma'
]);
grunt.registerTask('bundle', [
'rollup',
]);
grunt.registerTask('build', [
'lint',
'test',
'bundle',
]);
grunt.registerTask('web', [
'lint',
'test',
'rollup:web',
'rollup:bridge',
]);
grunt.registerTask('gaia', [
'lint',
'test',
'rollup:gaia',
'rollup:gaiabuild',
'rollup:bridge',
'compat:gaia:gecko',
'compat:bridge:gecko',
'copy:gaia'
]);
grunt.registerTask('release', [
'lint',
'test',
'bundle',
'compat',
'uglify'
]);
grunt.registerTask('default', [
'web'
]);
};