-
Notifications
You must be signed in to change notification settings - Fork 7
/
Gruntfile.js
503 lines (459 loc) · 13.5 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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
module.exports = function (grunt) {
'use strict';
// Force use of Unix newlines
grunt.util.linefeed = '\n';
RegExp.quote = function (string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
};
var fs = require('fs');
var path = require('path');
var BsLessdocParser = require('./grunt/bs-lessdoc-parser.js');
var getLessVarsData = function () {
var filePath = path.join(__dirname, 'less/variables.less');
var fileContent = fs.readFileSync(filePath, { encoding: 'utf8' });
var parser = new BsLessdocParser(fileContent);
return { sections: parser.parseFile() };
};
var configBridge = grunt.file.readJSON('./grunt/configBridge.json', { encoding: 'utf8' });
Object.keys(configBridge.paths).forEach(function (key) {
configBridge.paths[key].forEach(function (val, i, arr) {
arr[i] = path.join('./docs/assets', val);
});
});
var jsList = [
'js/template.js',
'js/transition.js',
'js/alert.js',
'js/button.js',
'js/carousel.js',
'js/collapse.js',
'js/dropdown.js',
'js/modal.js',
'js/tooltip.js',
// SUI不需要bootstrap里的popover
// 'js/popover.js',
// 'js/scrollspy.js',
'js/tab.js',
'js/addoncount.js',
// 'js/autocomplete.js',
// 'js/affix.js',
'js/pagination.js',
'js/datepicker.js',
'js/validate.js',
'js/datepicker.js',
// 'js/intro.js',
'js/toast.js',
'js/tag.js',
'js/pic-uploader.js'
// 'js/tagsinput.js'
];
var buildTo = grunt.option('buildTo');
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
dist: buildTo || 'dist',
// jqueryVersionCheck: configBridge.config.jqueryVersionCheck.join('\n'),
// Task configuration.
clean: {
dist: '<%= dist %>',
docs: 'docs/dist'
},
prefix: {
options: {
// 均有默认配置
keyClass : ['alert', 'badge', 'breadcrumb', 'btn', 'btn-group', 'btn-toolbar', 'dropdown', 'dropdown-menu', 'dropup', 'select', 'icon', 'carousel', 'close', 'form', 'tag', 'label', 'container', 'container-fluid', 'row', 'row-fluid', 'modal', 'navbar', 'nav', 'pagination', 'progress', 'steps', 'steps-round', 'table', 'tooltip', 'lead', 'page-header', 'well', 'input-group', 'list-group', 'jumbotron', 'media', 'panel', 'thumbnail'],
prefix: 'sui-'
},
css: {
expand: true,
cwd: './',
src: ['<%=dist%>/css/**/*.css'],
dest: './',
ext: '-prefixed.css'
}
},
jshint: {
options: {
jshintrc: 'js/.jshintrc'
},
grunt: {
options: {
jshintrc: 'grunt/.jshintrc'
},
src: ['Gruntfile.js', 'grunt/*.js']
},
core: {
src: ['js/*.js', '!js/template.js']
},
test: {
options: {
jshintrc: 'js/tests/unit/.jshintrc'
},
src: 'js/tests/unit/*.js'
},
assets: {
src: ['docs/assets/js/src/*.js', 'docs/assets/js/*.js', '!docs/assets/js/*.min.js']
}
},
jscs: {
options: {
config: 'js/.jscsrc'
},
grunt: {
src: '<%= jshint.grunt.src %>'
},
core: {
src: '<%= jshint.core.src %>'
},
test: {
src: '<%= jshint.test.src %>'
},
assets: {
options: {
requireCamelCaseOrUpperCaseIdentifiers: null
},
src: '<%= jshint.assets.src %>'
}
},
concat: {
options: {
},
sui: {
src: ['js/classmap.js'].concat(jsList),
dest: '<%=dist%>/js/<%= pkg.name %>.js'
},
suiPrefixed: {
src: ['js/classmap-sui.js'].concat(jsList),
dest: '<%=dist%>/js/<%= pkg.name %>-prefixed.js'
}
},
uglify: {
options: {
preserveComments: 'some'
},
core: {
src: '<%= concat.sui.dest %>',
dest: '<%=dist%>/js/<%= pkg.name %>.min.js'
},
corePrefixed: {
src: '<%= concat.suiPrefixed.dest %>',
dest: '<%=dist%>/js/<%= pkg.name %>-prefixed.min.js'
},
customize: {
src: configBridge.paths.customizerJs,
dest: 'docs/assets/js/customize.min.js'
},
docsJs: {
src: configBridge.paths.docsJs,
dest: 'docs/assets/js/docs.min.js'
}
},
qunit: {
options: {
inject: 'js/tests/unit/phantom.js'
},
files: 'js/tests/index.html'
},
less: {
compileCore: {
options: {
strictMath: true,
sourceMap: true,
outputSourceFiles: true,
sourceMapURL: '<%= pkg.name %>.css.map',
sourceMapFilename: '<%=dist%>/css/<%= pkg.name %>.css.map'
},
src: 'less/sui.less',
dest: '<%=dist%>/css/<%= pkg.name %>.css'
},
compileMTXCore: {
options: {
strictMath: true
},
src: 'less/sui-mtx.less',
dest: '<%=dist%>/css/sui-mtx.css'
},
compileTheme: {
options: {
strictMath: true,
sourceMap: true,
outputSourceFiles: true,
sourceMapURL: '<%= pkg.name %>-theme.css.map',
sourceMapFilename: '<%=dist%>/css/<%= pkg.name %>-theme.css.map'
},
src: 'less/theme.less',
dest: '<%=dist%>/css/<%= pkg.name %>-theme.css'
}
},
// autoprefixer: {
// options: {
// browsers: configBridge.config.autoprefixerBrowsers
// },
// core: {
// options: {
// map: true
// },
// src: 'dist/css/<%= pkg.name %>.css'
// },
// theme: {
// options: {
// map: true
// },
// src: 'dist/css/<%= pkg.name %>-theme.css'
// },
// docs: {
// src: 'docs/assets/css/src/docs.css'
// },
// examples: {
// expand: true,
// cwd: 'docs/examples/',
// src: ['**/*.css'],
// dest: 'docs/examples/'
// }
// },
csslint: {
options: {
csslintrc: 'less/.csslintrc'
},
dist: [
'<%=dist%>/css/sui.css',
'<%=dist%>/css/sui-theme.css'
],
examples: [
'docs/examples/**/*.css'
],
docs: {
options: {
ids: false,
'overqualified-elements': false
},
src: 'docs/assets/css/src/docs.css'
}
},
cssmin: {
options: {
compatibility: 'ie8',
keepSpecialComments: '*',
advanced: false
},
minifyCore: {
src: '<%=dist%>/css/<%= pkg.name %>.css',
dest: '<%=dist%>/css/<%= pkg.name %>.min.css'
},
minifyMTXCore: {
src: '<%=dist%>/css/sui-mtx.css',
dest: '<%=dist%>/css/sui-mtx.min.css'
},
minifyTheme: {
src: '<%=dist%>/css/<%= pkg.name %>-theme.css',
dest: '<%=dist%>/css/<%= pkg.name %>-theme.min.css'
},
minifyCorePrefixed: {
src: '<%=dist%>/css/<%= pkg.name %>-prefixed.css',
dest: '<%=dist%>/css/<%= pkg.name %>-prefixed.min.css'
},
minifyThemePrefixed: {
src: '<%=dist%>/css/<%= pkg.name %>-theme-prefixed.css',
dest: '<%=dist%>/css/<%= pkg.name %>-theme-prefixed.min.css'
},
docs: {
src: [
'docs/assets/css/src/docs.css',
'docs/assets/css/src/pygments-manni.css'
],
dest: 'docs/assets/css/docs.min.css'
}
},
csscomb: {
options: {
config: 'less/.csscomb.json'
},
dist: {
expand: true,
cwd: '<%=dist%>/css/',
src: ['*.css', '!*.min.css'],
dest: '<%=dist%>/css/'
},
examples: {
expand: true,
cwd: 'docs/examples/',
src: '**/*.css',
dest: 'docs/examples/'
},
docs: {
src: 'docs/assets/css/src/docs.css',
dest: 'docs/assets/css/src/docs.css'
}
},
copy: {
fonts: {
src: 'fonts/*',
dest: '<%=dist%>/'
},
lib: {
src: ['js/lib/*.js'],
dest: '<%=dist%>/'
},
docs: {
src: ['<%=dist%>/**/*', 'download/**/*'],
dest: 'docs/'
},
old: {
src: ['old/*/*'],
dest: '<%=dist%>/'
}
},
connect: {
server: {
options: {
port: 3000,
base: '.'
}
}
},
jekyll: {
options: {
config: '_config.yml'
},
docs: {},
github: {
options: {
raw: 'github: true'
}
}
},
jade: {
options: {
pretty: true,
data: getLessVarsData
},
customizerVars: {
src: 'docs/_jade/customizer-variables.jade',
dest: 'docs/_includes/customizer-variables.html'
},
customizerNav: {
src: 'docs/_jade/customizer-nav.jade',
dest: 'docs/_includes/nav/customize.html'
}
},
watch: {
src: {
files: '<%= jshint.core.src %>',
tasks: ['newer:jshint:core', 'concat', 'newer:copy:docs']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'qunit']
},
less: {
files: 'less/**/*.less',
tasks: ['less', 'newer:copy:docs']
},
docs: {
files: 'docs/assets/css/src/*.css',
tasks: ['cssmin:docs']
},
docsJS: {
files: 'docs/assets/js/src/*.js',
tasks: ['uglify:docs']
}
},
'saucelabs-qunit': {
all: {
options: {
build: process.env.TRAVIS_JOB_ID,
throttled: 10,
maxRetries: 3,
maxPollRetries: 4,
urls: ['http://127.0.0.1:3000/js/tests/index.html'],
browsers: grunt.file.readYAML('grunt/sauce_browsers.yml')
}
}
},
compress: {
main: {
options: {
archive: 'sui-<%= pkg.version %>-dist.zip',
mode: 'zip',
level: 9,
pretty: true
},
files: [
{
expand: true,
cwd: '<%=dist%>/',
src: ['**'],
dest: 'sui-<%= pkg.version %>-dist'
}
]
}
}
});
// These plugins provide necessary tasks.
if (buildTo) {
require('load-grunt-tasks')(grunt, { scope: ['dependencies'] });
} else {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
}
// Docs HTML validation task
// grunt.registerTask('validate-html', ['jekyll:docs', 'validation']);
// grunt.registerTask('validate-html', ['jekyll:docs']);
var runSubset = function (subset) {
return !process.env.TWBS_TEST || process.env.TWBS_TEST === subset;
};
var isUndefOrNonZero = function (val) {
return val === undefined || val !== '0';
};
// Test task.
var testSubtasks = [];
// Skip core tests if running a different subset of the test suite
if (runSubset('core') &&
// Skip core tests if this is a Savage build
process.env.TRAVIS_REPO_SLUG !== 'twbs-savage/bootstrap') {
testSubtasks = testSubtasks.concat(['dist-css', 'dist-js', 'csslint:dist', 'test-js']);
}
// Only run Sauce Labs tests if there's a Sauce access key
if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined' &&
// Skip Sauce if running a different subset of the test suite
runSubset('sauce-js-unit') &&
// Skip Sauce on Travis when [skip sauce] is in the commit message
isUndefOrNonZero(process.env.TWBS_DO_SAUCE)) {
testSubtasks.push('connect');
testSubtasks.push('saucelabs-qunit');
}
grunt.registerTask('test', testSubtasks);
grunt.registerTask('test-js', ['jshint:core', 'jshint:test', 'jshint:grunt', 'jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']);
// JS distribution task.
grunt.registerTask('dist-js', ['concat', 'uglify:core', 'uglify:corePrefixed', 'copy:lib']);
// CSS distribution task.
grunt.registerTask('less-compile', ['less:compileCore','less:compileMTXCore', 'less:compileTheme', 'prefix:css']);
grunt.registerTask('dist-css', ['less-compile', 'csscomb:dist', 'cssmin:minifyCore', 'cssmin:minifyMTXCore','cssmin:minifyTheme', 'cssmin:minifyCorePrefixed', 'cssmin:minifyThemePrefixed']);
// Full distribution task.
grunt.registerTask('dist', ['clean:dist', 'dist-css', 'copy:fonts', 'copy:old', 'dist-js', 'copy:docs']);
// Default task.
if (buildTo) {
grunt.registerTask('default', ['clean:dist', 'copy:fonts', 'copy:old', 'dist-css', 'dist-js']);
} else {
grunt.registerTask('default', ['clean:dist', 'copy:fonts', 'copy:old', 'test', 'docs']);
}
// 自动为产出文件和文档补全sui-前缀
grunt.loadNpmTasks('prefix-cssclass');
// Version numbering task.
// grunt change-version-number --oldver=A.B.C --newver=X.Y.Z
// This can be overzealous, so its changes should always be manually reviewed!
// task for building customizer
grunt.registerTask('build-customizer', ['build-customizer-html', 'build-raw-files']);
grunt.registerTask('build-customizer-html', 'jade');
// Docs task.
grunt.registerTask('docs-css', ['csscomb:docs', 'csscomb:examples', 'cssmin:docs']);
grunt.registerTask('lint-docs-css', ['csslint:docs', 'csslint:examples']);
// 关闭自定义下载相关的任务执行
// grunt.registerTask('docs-js', ['uglify:docsJs', 'uglify:customize']);
grunt.registerTask('docs-js', ['uglify:docsJs']);
grunt.registerTask('lint-docs-js', ['jshint:assets', 'jscs:assets']);
// grunt.registerTask('docs', ['docs-css', 'lint-docs-css', 'docs-js', 'lint-docs-js', 'clean:docs', 'copy:docs', 'build-glyphicons-data', 'build-customizer']);
grunt.registerTask('docs', ['docs-css', 'lint-docs-css', 'docs-js', 'lint-docs-js', 'clean:docs', 'copy:lib', 'copy:docs']);
grunt.registerTask('prep-release', ['jekyll:github', 'compress']);
};