This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGruntfile.js
351 lines (322 loc) · 8.13 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*global module:false*/
var fs = module.require('fs');
var path = module.require('path');
var os = module.require('os');
var md = module.require('matchdep');
module.exports = function fxGruntConfig (grunt) {
'use strict';
// VAR
var GRUNT_FILE = 'Gruntfile.js';
var BUILD_FILE = './dist/build.json';
var SRC_FILES = ['./src/*.js'];
var JSCS_FILE = '.jscsrc';
// TESTS
var SERVER_PORT = 8081;
var SERVER_URI = 'http://localhost:' + SERVER_PORT;
var TEST_PATHS = [
'/tests/framework.debug.js.test.html',
'/tests/framework.callback.js.test.html',
'/tests/framework.actions.js.test.html',
'/tests/framework.fx.js.test.html',
'/tests/framework.app.js.test.html',
'/tests/framework.storage.js.test.html'
];
var TEST_URIS = [];
var TEST_URIS_LT = [];
var TEST_URIS_CI = [];
var TEST_QS = '?noglobals=true';
// for qunit
var createTestUris = function () {
for (var c = 0; c < TEST_PATHS.length; c++) {
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '3.4.1');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '3.3.1');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '3.2.1');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '3.1.1');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '3.0.0');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '2.2.4');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '2.1.4');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '2.0.3');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '1.12.2');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '1.11.1');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '1.10.2');
TEST_URIS.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + '1.9.1');
}
};
var createTestUrisLt = function () {
for (var c = 0; c < TEST_PATHS.length; c++) {
TEST_URIS_LT.push(SERVER_URI + TEST_PATHS[c] + TEST_QS);
}
};
var createTestUrisCi = function () {
for (var c = 0; c < TEST_PATHS.length; c++) {
TEST_URIS_CI.push(SERVER_URI + TEST_PATHS[c] + TEST_QS + 'local');
}
};
var VERBOSE = !!~grunt.option.flags().indexOf('--verbose');
var config = {
pkg: grunt.file.readJSON('package.json'),
clean: {
options: {
force: true
},
doc: {
src: [
'docs/<%= pkg.name %>/<%= pkg.version %>/*'
]
}
},
buildnum: {
options: {
file: BUILD_FILE
}
},
babel: {
options: {
sourceMap: false,
presets: [[
'@babel/preset-env',
{
modules: false,
targets: {
ie: 11
}
}
]],
minified: true,
comments: false,
plugins: []
},
dist: {
files: {
'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js'
}
}
},
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %>' +
' - <%= meta.revision %> - build <%= buildnum.num %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> ' +
'<%= pkg.author.name %> (<%= pkg.author.url %>);\n' +
' * <%= pkg.license %> */'
},
revision: {
options: {
property: 'meta.revision',
ref: 'HEAD',
short: true
}
},
concat: {
options: {
process: true,
banner: '<%= meta.banner %>'
},
dist: {
src: SRC_FILES,
dest: 'dist/<%= pkg.name %>.js'
}
},
qunit: {
options: {
noGlobals: true,
timeout: 6000,
console: !!VERBOSE,
puppeteer: {
headless: !VERBOSE,
args: ['--media-cache-size=1', '--disk-cache-size=1']
}
},
all: {
options: {
urls: TEST_URIS
}
},
ci: {
options: {
urls: TEST_URIS_CI
}
},
latest: {
options: {
urls: TEST_URIS_LT
}
}
},
watch: {
files: SRC_FILES.concat(GRUNT_FILE),
tasks: ['jshint', 'complexity']
},
jshint: {
files: SRC_FILES.concat(GRUNT_FILE),
//force: true,
options: {
bitwise: false,
camelcase: false,
curly: true,
eqeqeq: false, // allow ==
forin: true,
//freeze: true,
immed: false, //
latedef: true, // late definition
newcap: true, // capitalize ctos
noempty: true,
nonew: true, // no new ..()
noarg: true,
plusplus: false,
quotmark: 'single',
undef: true,
maxparams: 5,
maxdepth: 5,
maxstatements: 30,
maxlen: 100,
//maxcomplexity: 10,
// relax options
//boss: true,
//eqnull: true,
esnext: true,
regexp: true,
strict: true,
trailing: false,
sub: true, // [] notation
smarttabs: true,
lastsemic: false, // enforce semicolons
white: true,
// env
browser: true,
globals: {
document: true,
console: true,
App: true,
window: true
}
}
},
uglify: {
prod: {
files: {
'dist/<%= pkg.name %>.min.js': '<%= concat.dist.dest %>'
}
},
options: {
banner: '<%= meta.banner %>',
sourceMap: 'dist/<%= pkg.name %>.min.js.map',
sourceMappingURL: '<%= pkg.name %>.min.js.map',
report: 'gzip',
mangle: true,
compress: {
global_defs: {
DEBUG: false
},
dead_code: true,
unused: true
},
preserveComments: false
}
},
connect: {
server: {
options: {
port: SERVER_PORT,
base: '.'
}
}
},
complexity: {
generic: {
src: SRC_FILES.concat(GRUNT_FILE),
options: {
//jsLintXML: 'report.xml', // create XML JSLint-like report
errorsOnly: false, // show only maintainability errors
cyclomatic: 10,
halstead: 25,
maintainability: 89
}
}
},
jscs: {
src: SRC_FILES.concat(GRUNT_FILE),
options: {
config: JSCS_FILE,
fix: true
}
},
jsdoc: {
dist: {
src: SRC_FILES.concat('README.md'),
options: {
destination: 'docs',
private: false,
package: './package.json',
template: './node_modules/minami'
}
}
}
};
var init = function (grunt) {
// Overrides some values
grunt.util.linefeed = '\n';
grunt.file.preserveBOM = false;
// Project configuration.
grunt.initConfig(config);
// fix source map url
grunt.registerTask('fix-source-map',
'Fixes the wrong file path in the source map', function () {
var sourceMapPath = grunt.template.process('<%= uglify.options.sourceMap %>');
var sourceMapUrl = grunt.template.process('<%= uglify.options.sourceMappingURL %>');
var diff = sourceMapPath.replace(sourceMapUrl, '');
var sourceMap = grunt.file.readJSON(sourceMapPath);
sourceMap.file = sourceMap.file.replace(diff, '');
var newSources = [];
sourceMap.sources.forEach(function (elem) {
newSources.push(elem.replace(diff, ''));
});
sourceMap.sources = newSources;
grunt.file.write(sourceMapPath, JSON.stringify(sourceMap));
});
// generate build number
grunt.registerTask('buildnum',
'Generates and updates the current build number', function () {
var options = this.options();
var getBuildNumber = function () {
var b = {};
try {
b = grunt.file.readJSON(options.file);
} catch (e) {}
b.lastBuild = b.lastBuild > 0 ? b.lastBuild + 1 : 1;
grunt.file.write(options.file, JSON.stringify(b));
return b.lastBuild;
};
var buildnum = getBuildNumber();
grunt.config.set('buildnum.num', buildnum);
grunt.log.writeln('New build num:', buildnum);
grunt.log.writeln('For version:', config.pkg.version);
});
// Default task.
grunt.registerTask('test', ['connect', 'qunit:all']);
grunt.registerTask('test-latest', ['connect', 'qunit:latest']);
grunt.registerTask('test-ci', ['connect', 'qunit:ci']);
grunt.registerTask('dev', ['jshint', 'jscs', 'complexity']);
grunt.registerTask('build', [
'buildnum',
'revision',
'concat',
'babel',
'fix-source-map'
]);
grunt.registerTask('doc', ['clean:doc','jsdoc']);
grunt.registerTask('ci', ['dev', 'test-ci', 'build', 'doc']);
grunt.registerTask('default', ['dev', 'test', 'build', 'doc']);
};
var load = function (grunt) {
md.filterDev('grunt-*').forEach(grunt.loadNpmTasks);
createTestUris();
createTestUrisCi();
createTestUrisLt();
init(grunt);
console.log('Running grunt on ' + os.platform());
};
// load the set-up
load(grunt);
};