-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·403 lines (397 loc) · 17.3 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
/**
* Created by kenhuang on 2018/10/23.
*/
module.exports = function (grunt) {
grunt.initConfig({
/* 'build/libs/exploded/<%= pkg.warName %>/WEB-INF/html' */
pkg: grunt.file.readJSON('package.json'),
frontend:'src/main/frontend',
tmp:'build/tmp',
webapp:'src/main/webapp/WEB-INF',
jslib:'<%= webapp %>/js/lib',
csslib:'<%= webapp %>/css/lib',
banner:'/*!<%= pkg.name %> - <%= pkg.version %>-<%=grunt.template.today("yyyy-mm-dd") %> */\n',
/***********************************************************************************************************************
* 公共部分
**********************************************************************************************************************/
/*包含*/
includes: {
jspatch:{
//将polyfill合并成IE*.js
options: {
flatten: true,
includePath: '<%= frontend %>/js/lib',
includeRegexp: /^\s*\/\/\s*import\s+['"]?([^'"]+\.js)['"]?\s*$/
},
cwd: '<%= frontend %>/js/patch',
src: ['**/*.js'],
dest: '<%= jslib %>'
}
},
/*css/js内容合并*/
concat: {
bcsjs:{
//合并BCS的相关js文件
options: {
stripBanners: true,
separator: ';\n',
banner: '<%= banner %>',
process: function(src, filepath) {
return '// Source: ' + filepath + '\n' +
src.replace(/(^|\n)[ \t]*?import.*?from[ \t]*?['"].*?['"].*?/g, '\n');
}
},
src:['<%= frontend %>/js/bcs/model/Browser.js',
'<%= frontend %>/js/bcs/view/BCSView.js',
'<%= frontend %>/js/bcs/view/BCSControl.js',
'<%= frontend %>/js/bcs/**/*.js'],
dest:'<%= tmp %>/js/BCS.js'
},
css:{
options: {
stripBanners: true,
separator: '\n',
banner: '<%= banner %>'
},
src:['<%= frontend %>/css/*.css',
'!<%= frontend %>/css/mediaelementplayer.css'
],
dest:'<%= csslib %>/patch.css'
},
},
/***********************************************************************************************************************
* js
**********************************************************************************************************************/
/*语法检查*/
// http://jshint.com/docs
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
jshint: {
options: {
"maxerr": 50, // {int} Maximum error before stopping
// Enforcing
"bitwise": false, //Prohibit bitwise operators (&, |, ^, etc.)
"camelcase": false, //Identifiers must be in camelCase
"curly": true, //Require {} for every new block or scope
"eqeqeq": true, //Require triple equals (===) for comparison
"forin": true, //Require filtering for in loops with obj.hasOwnProperty()
"freeze": false, //prohibits overwriting prototypes of native objects
"immed": false, //Require immediate invocations to be wrapped in parens
"latedef": false, //Require variables/functions to be defined before being used
"newcap": false, //Require capitalization of all constructor functions
"noarg": false, //Prohibit use of `arguments.caller` and `arguments.callee`
"noempty": true, //Prohibit use of empty block福龙开发区英明路13号s
"nonbsp": true, //Prohibit "non-breaking whitespace" characters.
"nonew": false, //Prohibit use of constructors for side-effects
"plusplus": false, //Prohibit use of `++` and `--`
"quotmark": false,
"undef": true, //Require all non-global variables to be declared
"unused": false,
"strict": false, //Requires all functions run in ES5 Strict Mode
"maxparams": false, // {int} Max number of formal params allowed per function
"maxdepth": false, // {int} Max depth of nested blocks (within functions)
"maxstatements": false, // {int} Max number statements per function
"maxcomplexity": false, // {int} Max cyclomatic complexity per function
"maxlen": false, // {int} Max number of characters per line
"varstmt": false,
// Relaxing
"asi": true, //Tolerate Automatic Semicolon Insertion (no semicolons)
"boss": false, //Tolerate assignments where comparisons would be expected
"debug": false, //Allow debugger statements e.g. browser breakpoints.
"eqnull": false, //Tolerate use of `== null`
"esversion": 6,
"moz": false, //Allow Mozilla specific syntax
"evil": false, //Tolerate use of `eval` and `new Function()`
"expr": true, //Tolerate `ExpressionStatement` as Programs
"funcscope": false, //Tolerate defining variables inside control statements
"globalstrict": false, //Allow global "use strict" (also enables 'strict')
"iterator": false, //Tolerate using the `__iterator__` property
"lastsemic": false,
"laxbreak": true, //Tolerate possibly unsafe line breakings
"laxcomma": false, //Tolerate comma-first style coding
"loopfunc": true, //Tolerate functions being defined in loops
"multistr": false, //Tolerate multi-line strings
"noyield": false, //Tolerate generator functions with no yield statement
"notypeof": false, //Tolerate invalid typeof operator values
"proto": false, //Tolerate using the `__proto__` property
"scripturl": false, //Tolerate script-targeted URLs
"shadow": false, //Allows re-define variables later in code
"sub": false,
"supernew": false, //Tolerate `new function () { ... };` and `new Object;`
"validthis": false, //Tolerate using this in a non-constructor function
// Environments
"browser": true, // Web Browser (window, document, etc)
"browserify": false, // Browserify (node.js code in the browser)
"couch": false, // CouchDB
"devel": true, // Development/debugging (alert, confirm, etc)
"dojo": false, // Dojo Toolkit
"jasmine": false, // Jasmine
"jquery": true, // jQuery
"mocha": true, // Mocha
"mootools": false, // MooTools
"node": false, // Node.js
"nonstandard": false, // Widely adopted globals (escape, unescape, etc)
"phantom": false, // PhantomJS
"prototypejs": false, // Prototype and Scriptaculous
"qunit": false, // QUnit
"rhino": false, // Rhino
"shelljs": false, // ShellJS
"typed": false, // Globals for typed array constructions
"worker": false, // Web Workers
"wsh": false, // Windows Scripting Host
"yui": false, // Yahoo User Interface
// Custom Globals
"globals": {
"jQuery": true,
"console": true,
"module": true
},
ignores:['']
},
build: ['<%= frontend %>/js/bcs/**/*.js']
},
// js 将ES6代码转为ES5代码
// babel-plugin-transform-es3-member-expression-literals
// babel-plugin-transform-es3-property-literals
// @babel/preset-react
babel: {
options: {
sourceMap: false,
presets: ["es2015"],
plugins: [
["babel-plugin-transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": false,
"moduleName": "babel-runtime"
}],
["babel-plugin-transform-es3-property-literals"],
["babel-plugin-transform-es3-member-expression-literals"],
['babel-plugin-transform-es2015-modules-umd', { "loose": true }],
["babel-plugin-transform-remove-strict-mode"]
]
},
dist: {
files: {
// '<%= frontend %>/js/dist/BCS.js': ['<%= concat.BCSConcat.dest %>']
// '<%= jslib %>/FormData.es5.js': ['<%= frontend %>/js/lib/FormData.js'],
// '<%= jslib %>/sendbeacon.es5.js': ['<%= frontend %>/js/lib/sendbeacon.js'],
'<%= jslib %>/BCS.js': ['<%= concat.bcsjs.dest %>']
// '<%= frontend %>/js/lib/dialog-polyfill.es5.js': ['<%= frontend %>/js/lib/dialog-polyfill.js'],
}
}
},
/*压缩*/
uglify: {
options: {
stripBanners: true,
mangle: { reserved: ['require', 'exports', 'module'] },
ie8: true,
banner: '<%= banner %>'
},
bcsjs: {
files: [{
expand: true,
cwd: '<%= jslib %>',
src: ['BCS.js'],
dest: '<%= webapp %>/js'
}]
},
jspatch:{
files: [{
expand: true,
cwd: '<%= jslib %>',
src: ['**/IE*.js'],
dest: '<%= webapp %>/js'
}]
}
},
/***********************************************************************************************************************
* css
**********************************************************************************************************************/
/*https://github.com/CSSLint/csslint/wiki/Rules*/
csslint:{
options:{
"box-model": false,
"adjoining-classes": false,
"box-sizing": false,
"compatible-vendor-prefixes": false,
"gradients": false,
"text-indent": false,
"fallback-colors": false,
"star-property-hack": false,
"underscore-property-hack": false,
"bulletproof-font-face": false,
"font-faces": false,
"import": false,
"regex-selectors": false,
"universal-selector": false,
"unqualified-attributes": false,
"overqualified-elements": false,
"duplicate-background-images": false,
"floats": false,
"font-sizes": false,
"ids": false,
"important": false,
"outline-none": false,
"qualified-headings": false,
"unique-headings": false,
"order-alphabetical":false,
"known-properties":false,
"empty-rules":false,
"display-property-grouping":false
},
build:['<%= csslib %>/patch.css']
},
//压缩css
cssmin:{
options:{
stripBanners:true,
banner:'<%= banner %>'
},
patch:{
src:'<%= csslib %>/patch.css',
dest:'<%= webapp %>/css/patch.min.css'
},
media:{
src:'<%= csslib %>/media.css',
dest:'<%= webapp %>/css/media.min.css'
}
},
/***********************************************************************************************************************
* 复制swf
**********************************************************************************************************************/
copy: {
options:{
mode:true,
timestamp:true
},
cssMedia:{
src: '<%= frontend %>/css/mediaelementplayer.css',
dest: '<%= webapp %>/css/lib/media.css'
},
swf: {
files: [
// includes files within path
{expand: true,
cwd: '<%= frontend %>/swf/',
src: ['**/*.swf'],
dest: '<%= webapp %>/swf/',
filter: 'isFile'},
]
},
htc:{
files: [
// includes files within path
{expand: true,
cwd: '<%= frontend %>/js/lib/',
src: ['**/*.htc'],
dest: '<%= webapp %>/htc/',
filter: 'isFile'}
]
}
},
/***********************************************************************************************************************
* git
**********************************************************************************************************************/
gitadd: {
bcs: {
options: {
force: false
},
files: {
src: ['**.*']
}
}
},
gitcommit: {
bcs: {
options: {
message: 'Add'
},
files: {
src: ['**.*']
}
}
},
// gitremote: {
// bcs: {
// options: {
// add: { name: 'origin', url: 'https://github.com/Ken-W-P-Huang/BC-S.git' }
// }
// }
// },
gitpush: {
bcs: {
options: {
remote:'origin',
branch:'master'
}
}
},
/***********************************************************************************************************************
* watch
**********************************************************************************************************************/
watch: {
options: {
livereload: {
port: 35729,
// key: grunt.file.read('path/to/ssl.key'),
// cert: grunt.file.read('path/to/ssl.crt')
},
//如果gruntfile被监控,在这个文件被修改之后,会导致监控任务重新启动。
reload:true,
// 在监视器启动时触发每个指定任务的运行
atBegin:true,
event: ['added', 'deleted'],
debounceDelay: 250
},
Gruntfile:{
files:['Gruntfile.js']
},
js:{
files: ['<%= frontend %>/js/bcs/**/*.js'],
tasks: ['concat:bcsjs','jshint','babel','uglify:bcsjs'],
options: {
event: ['added', 'deleted','changed']
}
},
jspatch:{
files: ['<%= frontend %>/js/patch/**/*.js'],
tasks: ['includes:jspatch','uglify:jspatch']
},
cssPatch:{
files: ['<%= frontend %>/css/**/*.css'],
tasks: ['concat:css','csslint','cssmin:patch']
},
// @-ms-keyframes无法被csslint识别
// https://github.com/CSSLint/csslint/issues/295
cssMedia:{
files: ['<%= frontend %>/css/mediaelementplayer.css'],
tasks: ['copy:cssMedia','cssmin:media']
},
htc:{
files: ['<%= frontend %>/js/bcs/lib/**/*.htc'],
tasks: ['copy:htc']
},
swf:{
files:['<%= frontend %>/swf/**/*.swf'],
tasks: ['copy:swf']
}
}
})
grunt.loadNpmTasks('grunt-includes')
grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-babel')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-contrib-csslint')
grunt.loadNpmTasks('grunt-contrib-cssmin')
grunt.loadNpmTasks('grunt-git')
grunt.registerInitTask('default',
['includes','concat','babel','jshint','uglify','watch','copy'])
grunt.registerTask('push',['gitadd','gitcommit','gitpush'])
};