-
Notifications
You must be signed in to change notification settings - Fork 32
/
Gruntfile.js
executable file
·143 lines (114 loc) · 2.92 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
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
cors: {
options: {
port: 4790,
base: '.'
}
},
hole: {
options: {
port: 4791,
base: '.'
}
}
},
jshint: {
all: ['src/*.js', 'tests/*.js'],
options: {
newcap: false, // "Tolerate uncapitalized constructors"
node: true,
expr: true, // - true && call() "Expected an assignment or function call and instead saw an expression."
supernew: true, // - "Missing '()' invoking a constructor."
laxbreak: true,
white: true,
globals: {
define: true,
test: true,
expect: true,
module: true,
asyncTest: true,
start: true,
ok: true,
equal: true,
notEqual: true,
deepEqual: true,
window: true,
document: true,
performance: true
}
}
},
qunit: {
all: ['tests/index.html'],
options: {
'--web-security': 'no',
coverage: {
src: ['wormhole.js'],
instrumentedFiles: 'temp/',
htmlReport: 'report/coverage',
coberturaReport: 'report/',
linesThresholdPct: 100,
functionsThresholdPct: 100,
branchesThresholdPct: 100,
statementsThresholdPct: 100
}
}
},
requirejs: {
src: 'src/module.js',
dst: 'wormhole.js'
},
watch: {
scripts: {
files: 'src/*.*',
tasks: ['requirejs'],
options: { interrupt: true }
}
},
version: {
src: ['src/module.js']
}
});
grunt.registerTask('requirejs', 'RequireJS to plain/javascript', function () {
var deps = {};
function file(name) {
return config.src.split('/').slice(0, -1).concat(name).join('/') + '.js';
}
function parse(src, exports) {
var content = grunt.file.read(src);
content = content.trim().replace(/define\((\[.*?\]).*?\n/, function (_, str) {
JSON.parse(str).forEach(function (name) {
deps[name] = parse(file(name));
});
return '';
});
if (!exports) {
content = content.replace(/\/\/\s+Export[\s\S]+/, '');
}
return content.replace(/\}\);$/, '');
}
var config = grunt.config(this.name);
var content = parse(config.src, true);
var intro = '(function (window, document) {\n"use strict";\n';
var outro = '})(window, document);';
for (var name in deps) {
intro += deps[name] + '\n\n';
}
grunt.log.oklns('Build:', config.dst);
grunt.log.oklns('Deps:', Object.keys(deps).join(', '));
grunt.file.write(config.dst, intro + content + outro);
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-qunit-istanbul');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-version');
grunt.registerTask('dev', ['connect', 'requirejs', 'watch']);
grunt.registerTask('build', ['version', 'requirejs']);
grunt.registerTask('test', ['jshint', 'build', 'connect', 'qunit']);
grunt.registerTask('default', ['test']);
};