-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGruntfile.js
454 lines (423 loc) · 12.6 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
"use strict";
/* eslint-env es6,node */
module.exports = function(grunt) {
// Log time how long tasks take
require("grunt-timer").init(grunt, { deferLogs: true, friendlyTime: true, color: "cyan"});
const nabiProject = require("./lib/nabiProject");
const CONFIG = nabiProject.readConfig();
//grunt.log.writeln("\n### nabi config ###\n" + JSON.stringify(CONFIG.sapDeploy, null, 2));
grunt.initConfig({
libraryName: "nabi.m",
dir: {
src: "src",
test: "test",
dist: "dist",
build: "build",
buildReportsCoverage: "build/reports/coverage",
buildBabel: "build/babel",
nodeModules: "node_modules",
ui5labBrowser: "node_modules/ui5lab-browser/dist"
},
karma: {
options: {
browsers: ["Chrome"],
basePath: ".",
files: [
{ pattern: "src/nabi/m/**", included: false, served: true, watched: true },
{ pattern: "test/nabi/m/unit/**", included: false, served: true, watched: true },
{ pattern: "test/nabi/m/integration/**", included: false, served: true, watched: true },
{ pattern: "test/nabi/m/samplecomp/**/*", included: false, served: true, watched: true }
],
frameworks: ["qunit", "openui5"],
openui5: {
path: "http://localhost:8080/resources/sap-ui-core.js",
useMockServer: false
},
client: {
//clearContext: true,
//useIframe: false,
//captureConsole: true,
openui5: {
config: {
theme: "sap_belize",
libs: "nabi.m",
bindingSyntax: "complex",
compatVersion: "edge",
animation: "false",
//frameOptions: "deny", // this would make the QUnit results in browser "not clickable" etc.
preload: "async",
resourceRoots: {
"nabi.m": "./base/src/nabi/m/",
"test.nabi.m": "./base/test/nabi/m/"
// NEVER DO THIS because it would lead to "non-instrumentalized" sources (i.e. coverage not detected):
//"nabi.m": "http://localhost:8080/resources/nabi/m/",
//"test.nabi.m": "http://localhost:8080/test-resources/nabi/m/"
}
},
tests: [
"test/nabi/m/unit/allTests",
"test/nabi/m/integration/AllJourneys" // remove this in case in case it take too long, i.e. tdd/dev time
]/*,
mockserver: {
config: {
autoRespond: true
},
rootUri: '/my/service/',
metadataURL: '/base/test/mock.xml',
mockdataSettings: { }
}
*/
}
},
reporters: ["progress"],
port: 9876,
logLevel: "INFO",
browserConsoleLogOptions: {
level: "warn"
}
},
ci: {
singleRun: true,
browsers: ["ChromeHeadless"],
preprocessors: {
// src files for which we want to get coverage.
// Exclude thirdparty libs, irrelevant folders (i.e. themes, test), and maybe also library.js and UI5 Renderers (your decision).
"{src/nabi/m,src/nabi/m/!(thirdparty|themes|test)}/!(library|*Renderer)*.js": ["coverage"]
},
coverageReporter: {
includeAllSources: true,
dir: "<%= dir.buildReportsCoverage %>",
reporters: [
{ type: "html", subdir: "report-html"},
{ type: "cobertura", subdir: "." }, //jenkins
{ type: "text"}
],
check: {
each: {
statements: 30,
branches: 30,
functions: 30,
lines: 30
}
}
},
reporters: ["progress", "coverage"]
},
watch: {
client: {
clearContext: false,
qunit: {
showUI: true
}
}
},
coverage: { //same as ci, but without the checks
singleRun: true,
browsers: ["ChromeHeadless"],
preprocessors: {
// src files for which we want to get coverage.
// Exclude thirdparty libs, irrelevant folders (i.e. themes, test), and maybe also library.js and UI5 Renderers (your decision).
"{src/nabi/m,src/nabi/m/!(thirdparty|themes|test)}/!(library|*Renderer)*.js": ["coverage"]
},
coverageReporter: {
includeAllSources: true,
dir: "<%= dir.buildReportsCoverage %>",
reporters: [
{ type: "html", subdir: "report-html"},
{ type: "cobertura", subdir: "." }, //jenkins
{ type: "text"}
],
},
reporters: ["progress", "coverage"]
}
},
babel : {
options : {
// see .babelrc
},
dist : {
files : [{
expand: true,
cwd: "<%= dir.dist %>/resources",
src: [
"**/*.js",
"!nabi/m/themes/**",
"!nabi/m/thirdparty/**",
"!nabi/m/**/*-dbg.js",
"!nabi/m/**/*-dbg.controller.js"
],
dest: "<%= dir.dist %>/resources/" //trailing slash is important
}]
},
srcToBuildBabel : {
files : [{
expand: true,
cwd: "<%= dir.src %>",
src: [
"**/*.js",
"!nabi/m/themes/**",
"!nabi/m/thirdparty/**"
],
dest: "<%= dir.buildBabel %>/" //trailing slash is important
}]
}
},
concurrent: {
options: {
logConcurrentOutput: true
},
serveSrcBabel: {
tasks: ["watch:babel", "serve:srcWithBabel"]
},
serveSrcEdge : {
tasks: ["watch:babel", "serve:srcWithBabel", "karma:watch"]
}
},
watch: {
babel: {
//cwd: "<%= dir.src %>", //this seems not to work with the next LoC as expected
//files: ["**/*.js", "!nabi/m/themes/**", "!nabi/m/thirdparty/**"],
files: ["<%= dir.src %>/**/*.js", "!<%= dir.src %>/nabi/m/themes/**", "!<%= dir.src %>/nabi/m/thirdparty/**"],
tasks: ["clean:buildBabel", "babel:srcToBuildBabel"],
options: {
interrupt: true
}
}
},
connect: {
options: {
port: 8080,
hostname: "*",
middleware: function(connect, options, middlewares) {
// inject a custom middleware into the array of default middlewares
middlewares.unshift(
connect().use("/upload", function(req, res, next) {
//nabiProject.handleHttpFileUpload(false, req, res, next);
nabiProject.handleHttpFileUpload(true, req, res, next); //ONLY FOR LOCAL DEV!!!
return undefined;
})
);
return middlewares;
}
},
src: {},
srcWithBabel: {},
dist: {}
},
openui5_connect: {
options : {
cors: {
origin: 'http://localhost:<%= karma.options.port %>'
}
},
src: {
options: {
resources: [
"<%= dir.nodeModules %>/@openui5/sap.ui.core/src",
"<%= dir.nodeModules %>/@openui5/sap.m/src",
"<%= dir.nodeModules %>/@openui5/sap.f/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.layout/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.unified/src",
"<%= dir.nodeModules %>/@openui5/themelib_sap_belize/src",
"<%= dir.src %>"
],
testresources: [
"<%= dir.test %>",
"<%= dir.ui5labBrowser %>/test-resources"
]
}
},
srcWithBabel: {
options: {
resources: [
"<%= dir.nodeModules %>/@openui5/sap.ui.core/src",
"<%= dir.nodeModules %>/@openui5/sap.m/src",
"<%= dir.nodeModules %>/@openui5/sap.f/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.layout/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.unified/src",
"<%= dir.nodeModules %>/@openui5/themelib_sap_belize/src",
// the order of these two is important because contents from buildBabel shall be preferred over src
"<%= dir.buildBabel %>",
"<%= dir.src %>"
],
testresources: [
"<%= dir.test %>",
"<%= dir.ui5labBrowser %>/test-resources"
]
}
},
dist: {
options: {
resources: [
"<%= dir.nodeModules %>/@openui5/sap.ui.core/src",
"<%= dir.nodeModules %>/@openui5/sap.m/src",
"<%= dir.nodeModules %>/@openui5/sap.f/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.layout/src",
"<%= dir.nodeModules %>/@openui5/sap.ui.unified/src",
"<%= dir.nodeModules %>/@openui5/themelib_sap_belize/src",
"<%= dir.dist %>/resources"
],
testresources: [
"<%= dir.dist %>/test-resources",
"<%= dir.ui5labBrowser %>/test-resources"
]
}
}
},
openui5_theme: {
theme: {
files: [
{
expand: true,
cwd: "<%= dir.src %>",
src: "**/themes/*/library.source.less",
dest: "<%= dir.dist %>/resources"
}
],
options: {
rootPaths: [
"<%= dir.nodeModules %>/@openui5/sap.ui.core/src",
"<%= dir.nodeModules %>/@openui5/themelib_sap_belize/src",
"<%= dir.src %>"
],
library: {
name: "<%= libraryName %>"
}
}
}
},
openui5_preload: {
library: {
options: {
resources: "<%= dir.dist %>/resources",
dest: "<%= dir.dist %>/resources",
compatVersion : "1.44"
},
libraries: {
"nabi/m": {
src : [
"nabi/m/**",
"!nabi/m/thirdparty/**",
"!nabi/m/**/*-dbg.js",
"!nabi/m/**/*-dbg.controller.js"
]
}
}
}
},
clean: {
dist: ["<%= dir.dist %>/"],
build: ["<%= dir.build %>/"],
buildBabel: ["<%= dir.buildBabel %>/"],
coverage: "<%= dir.buildReportsCoverage %>"
},
copy: {
srcToDist: {
files: [
{ // first all resources incl. themes, thirdparty and even less files (won't harm)
expand: true,
src: [ "**", "nabi/m/.library" ],
cwd: "<%= dir.src %>",
dest: "<%= dir.dist %>/resources/", //trailing slash is important
}, {
//finally the test resources
expand: true,
cwd: "<%= dir.test %>",
src: ["**"],
dest: "<%= dir.dist %>/test-resources"
}
]
},
srcToDistDbg : {
files : [
{ // rename ui5 js files to *-dbg.js / *-dbg.controller.js
expand: true,
src: ["**/*.js", "!nabi/m/themes/**", "!nabi/m/thirdparty/**"],
cwd: "<%= dir.src %>",
dest: "<%= dir.dist %>/resources/", //trailing slash is important
rename: nabiProject.fileRename
}
]
},
distToDistDbg : {
files : [
{ // rename ui5 js files to *-dbg.js / *-dbg.controller.js
expand: true,
src: ["**/*.js", "!nabi/m/themes/**", "!nabi/m/thirdparty/**"],
cwd: "<%= dir.dist %>/resources",
dest: "<%= dir.dist %>/resources/", //trailing slash is important
rename: nabiProject.fileRename
}
]
}
},
jsdoc : {
dist : {
src : ["src/**/*.js", "README.md", "!nabi/m/themes/**", "!nabi/m/thirdparty/**"],
options : {
destination : "jsdoc",
template : "node_modules/ink-docstrap/template",
configure : "node_modules/ink-docstrap/template/jsdoc.conf.json"
}
}
},
eslint: {
src: ["<%= dir.src %>"],
test: ["<%= dir.test %>"],
gruntfile: ["Gruntfile.js"]
},
compress: {
dist : {
options: {
archive: "<%= dir.dist %>/nabi-m.zip"
},
expand: true,
cwd: "<%= dir.dist %>/resources/nabi/m",
src: ["**/*"],
dot : true,
dest: "/"
}
},
nwabap_ui5uploader: CONFIG.sapDeploy
});
// These plugins provide necessary tasks.
// Maybe I'll switch to this in future: require("load-grunt-tasks")(grunt);
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-jsdoc");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-openui5");
grunt.loadNpmTasks("grunt-eslint");
grunt.loadNpmTasks("grunt-concurrent");
grunt.loadNpmTasks("grunt-karma");
grunt.loadNpmTasks("grunt-nwabap-ui5uploader");
// Default task
grunt.registerTask("default", [
"lint",
"build",
"serve:dist"
]);
// Server tasks
grunt.registerTask("serve", function(target) {
grunt.task.run("openui5_connect:" + (target || "src") + ":keepalive");
});
grunt.registerTask("serve:tdd", ["clean:coverage", "openui5_connect:src", "karma:watch"]);
grunt.registerTask("serve:devEdge", ["clean:coverage", "clean:buildBabel", "babel:srcToBuildBabel", "concurrent:serveSrcEdge"]);
grunt.registerTask("serve:babel", ["clean:buildBabel", "babel:srcToBuildBabel", "concurrent:serveSrcBabel"]);
grunt.registerTask("serve:srcBabel", ["clean:buildBabel", "babel:srcToBuildBabel", "serve:srcWithBabel"]);
grunt.registerTask("serve:distBabel", ["build:babel","serve:dist"]);
// Test tasks
grunt.registerTask("test", ["clean:coverage", "openui5_connect:src", "karma:coverage"]);
grunt.registerTask("test:ci",["clean:coverage", "openui5_connect:src", "karma:ci"]);
// Linting tasks
grunt.registerTask("lint", ["eslint"]);
// Build tasks
grunt.registerTask("build", ["clean:dist", "openui5_theme", "copy:srcToDist", "copy:srcToDistDbg", "openui5_preload", "compress:dist"]);
grunt.registerTask("build:babel", ["clean:dist", "openui5_theme", "copy:srcToDist", "babel:dist", "copy:distToDistDbg", "openui5_preload", "compress:dist"]);
// SAP deployments
grunt.registerTask("sapdeploy", ["lint", "build", "nwabap_ui5uploader"]);
grunt.registerTask("sapdeploy:babel", ["lint", "build:babel", "nwabap_ui5uploader"]);
};