forked from web-animations/web-animations-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
145 lines (133 loc) · 4.76 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-gjslint');
grunt.loadNpmTasks('grunt-checkrepo');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-saucelabs');
grunt.loadNpmTasks('grunt-git-status');
var targetConfig = require('./target-config.js');
var uglifyTargets = {};
var genTargets = {};
var testTargets = {};
for (var target in targetConfig) {
var suffix = target === targetConfig.defaultTarget ? '' : '-' + target;
uglifyTargets[target] = {
options: {
sourceMap: true,
sourceMapName: 'web-animations' + suffix + '.min.js.map',
banner: grunt.file.read('templates/boilerplate'),
wrap: true,
compress: {
global_defs: {
"WEB_ANIMATIONS_TESTING": false
},
dead_code: true
},
mangle: {
eval: true
},
},
nonull: true,
dest: 'web-animations' + suffix + '.min.js',
src: targetConfig[target].src,
};
genTargets[target] = targetConfig[target];
testTargets[target] = {};
}
grunt.initConfig({
uglify: uglifyTargets,
gen: genTargets,
checkrepo: {
all: {
clean: true,
},
},
'git-status': {
all: {
},
},
gjslint: {
options: {
flags: [
'--nojsdoc',
'--strict',
'--disable 7,121,110', // 7: Wrong blank line count
// 121: Illegal comma at end of object literal
// 110: Line too long
],
reporter: {
name: 'console'
}
},
all: {
src: [
'src/*.js',
'test/*.js',
'test/js/*.js',
],
}
},
test: testTargets,
sauce: testTargets,
});
grunt.task.registerMultiTask('gen', 'Generate web-animations-<target>.js, web-animations-<target>.html, test/runner-<target>.js', function() {
var target = this.target;
var config = targetConfig[target];
(function() {
var template = grunt.file.read('templates/web-animations.js')
var filename = 'web-animations' + (target === targetConfig.defaultTarget ? '' : '-' + target) + '.js';
var contents = grunt.template.process(template, {data: {target: target}});
grunt.file.write(filename, contents);
grunt.log.writeln('File ' + filename + ' created');
})();
(function() {
var template = grunt.file.read('templates/web-animations.html')
var filename = 'web-animations' + (target === targetConfig.defaultTarget ? '' : '-' + target) + '.html';
var contents = grunt.template.process(template, {data: {src: config.src}});
grunt.file.write(filename, contents);
grunt.log.writeln('File ' + filename + ' created');
})();
(function() {
var template = grunt.file.read('templates/runner.html')
var filename = 'test/runner' + (target === targetConfig.defaultTarget ? '' : '-' + target) + '.html';
var contents = grunt.template.process(template, {data: {target: target}});
grunt.file.write(filename, contents);
grunt.log.writeln('File ' + filename + ' created');
})();
});
grunt.task.registerMultiTask('test', 'Run <target> tests under Karma', function() {
var done = this.async();
var karmaConfig = require('karma/lib/config').parseConfig(require('path').resolve('test/karma-config.js'), {});
var config = targetConfig[this.target];
karmaConfig.files = ['test/runner.js'].concat(config.src, config.test);
var karmaServer = require('karma').server;
karmaServer.start(karmaConfig, function(exitCode) {
done(exitCode === 0);
});
});
grunt.task.registerMultiTask('sauce', 'Run <target> tests under Karma on Saucelabs', function() {
var done = this.async();
var karmaConfig = require('karma/lib/config').parseConfig(require('path').resolve('test/karma-config-ci.js'), {});
var config = targetConfig[this.target];
karmaConfig.files = ['test/runner.js'].concat(config.src, config.test);
karmaConfig.sauceLabs.testName = 'web-animation-next ' + this.target + ' Unit tests';
var karmaServer = require('karma').server;
karmaServer.start(karmaConfig, function(exitCode) {
done(exitCode === 0);
});
});
grunt.task.registerTask('clean', 'Remove files generated by grunt', function() {
grunt.file.expand('web-animations-*').concat(grunt.file.expand('test/runner-*.html')).forEach(function(file) {
grunt.file.delete(file);
grunt.log.writeln('File ' + file + ' removed');
});
});
for (var target in targetConfig) {
grunt.task.registerTask(target, [
'uglify:' + target,
'gen:' + target,
'gjslint',
]);
}
grunt.task.registerTask('default', ['uglify', 'gen', 'gjslint']);
};