2 * Bootstrap's Gruntfile
3 * http://getbootstrap.com
4 * Copyright 2013-2016 Twitter, Inc.
5 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8 module.exports = function (grunt) {
11 // Force use of Unix newlines
12 grunt.util.linefeed = '\n';
14 RegExp.quote = function (string) {
15 return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
18 var fs = require('fs');
19 var path = require('path');
20 var generateGlyphiconsData = require('./grunt/bs-glyphicons-data-generator.js');
21 var BsLessdocParser = require('./grunt/bs-lessdoc-parser.js');
22 var getLessVarsData = function () {
23 var filePath = path.join(__dirname, 'less/variables.less');
24 var fileContent = fs.readFileSync(filePath, { encoding: 'utf8' });
25 var parser = new BsLessdocParser(fileContent);
26 return { sections: parser.parseFile() };
28 var generateRawFiles = require('./grunt/bs-raw-files-generator.js');
29 var generateCommonJSModule = require('./grunt/bs-commonjs-generator.js');
30 var configBridge = grunt.file.readJSON('./grunt/configBridge.json', { encoding: 'utf8' });
32 Object.keys(configBridge.paths).forEach(function (key) {
33 configBridge.paths[key].forEach(function (val, i, arr) {
34 arr[i] = path.join('./docs/assets', val);
38 // Project configuration.
42 pkg: grunt.file.readJSON('package.json'),
44 ' * Bootstrap v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
45 ' * Copyright 2011-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
46 ' * Licensed under the <%= pkg.license %> license\n' +
48 jqueryCheck: configBridge.config.jqueryCheck.join('\n'),
49 jqueryVersionCheck: configBridge.config.jqueryVersionCheck.join('\n'),
51 // Task configuration.
59 jshintrc: 'js/.jshintrc'
63 jshintrc: 'grunt/.jshintrc'
65 src: ['Gruntfile.js', 'package.js', 'grunt/*.js']
72 jshintrc: 'js/tests/unit/.jshintrc'
74 src: 'js/tests/unit/*.js'
77 src: ['docs/assets/js/src/*.js', 'docs/assets/js/*.js', '!docs/assets/js/*.min.js']
86 src: '<%= jshint.grunt.src %>'
89 src: '<%= jshint.core.src %>'
92 src: '<%= jshint.test.src %>'
96 requireCamelCaseOrUpperCaseIdentifiers: null
98 src: '<%= jshint.assets.src %>'
104 banner: '<%= banner %>\n<%= jqueryCheck %>\n<%= jqueryVersionCheck %>',
122 dest: 'dist/js/<%= pkg.name %>.js'
132 preserveComments: /^!|@preserve|@license|@cc_on/i
135 src: '<%= concat.bootstrap.dest %>',
136 dest: 'dist/js/<%= pkg.name %>.min.js'
139 src: configBridge.paths.customizerJs,
140 dest: 'docs/assets/js/customize.min.js'
143 src: configBridge.paths.docsJs,
144 dest: 'docs/assets/js/docs.min.js'
150 inject: 'js/tests/unit/phantom.js'
152 files: 'js/tests/index.html'
160 outputSourceFiles: true,
161 sourceMapURL: '<%= pkg.name %>.css.map',
162 sourceMapFilename: 'dist/css/<%= pkg.name %>.css.map'
164 src: 'less/bootstrap.less',
165 dest: 'dist/css/<%= pkg.name %>.css'
171 outputSourceFiles: true,
172 sourceMapURL: '<%= pkg.name %>-theme.css.map',
173 sourceMapFilename: 'dist/css/<%= pkg.name %>-theme.css.map'
175 src: 'less/theme.less',
176 dest: 'dist/css/<%= pkg.name %>-theme.css'
182 browsers: configBridge.config.autoprefixerBrowsers
188 src: 'dist/css/<%= pkg.name %>.css'
194 src: 'dist/css/<%= pkg.name %>-theme.css'
197 src: ['docs/assets/css/src/docs.css']
201 cwd: 'docs/examples/',
203 dest: 'docs/examples/'
209 csslintrc: 'less/.csslintrc'
212 'dist/css/bootstrap.css',
213 'dist/css/bootstrap-theme.css'
216 'docs/examples/**/*.css'
221 'overqualified-elements': false
223 src: 'docs/assets/css/src/docs.css'
229 // TODO: disable `zeroUnits` optimization once clean-css 3.2 is released
230 // and then simplify the fix for https://github.com/twbs/bootstrap/issues/14837 accordingly
231 compatibility: 'ie8',
232 keepSpecialComments: '*',
234 sourceMapInlineSources: true,
238 src: 'dist/css/<%= pkg.name %>.css',
239 dest: 'dist/css/<%= pkg.name %>.min.css'
242 src: 'dist/css/<%= pkg.name %>-theme.css',
243 dest: 'dist/css/<%= pkg.name %>-theme.min.css'
247 'docs/assets/css/ie10-viewport-bug-workaround.css',
248 'docs/assets/css/src/pygments-manni.css',
249 'docs/assets/css/src/docs.css'
251 dest: 'docs/assets/css/docs.min.css'
257 config: 'less/.csscomb.json'
262 src: ['*.css', '!*.min.css'],
267 cwd: 'docs/examples/',
269 dest: 'docs/examples/'
272 src: 'docs/assets/css/src/docs.css',
273 dest: 'docs/assets/css/src/docs.css'
305 config: '_config.yml',
319 collapseBooleanAttributes: true,
320 collapseWhitespace: true,
321 conservativeCollapse: true,
322 decodeEntities: false,
324 compatibility: 'ie8',
325 keepSpecialComments: 0
329 processConditionalComments: true,
330 removeAttributeQuotes: true,
331 removeComments: true,
332 removeOptionalAttributes: true,
333 removeOptionalTags: true,
334 removeRedundantAttributes: true,
335 removeScriptTypeAttributes: true,
336 removeStyleLinkTypeAttributes: true,
337 removeTagWhitespace: false,
338 sortAttributes: true,
346 '!examples/**/*.html'
354 data: getLessVarsData
357 src: 'docs/_pug/customizer-variables.pug',
358 dest: 'docs/_includes/customizer-variables.html'
361 src: 'docs/_pug/customizer-nav.pug',
362 dest: 'docs/_includes/nav/customize.html'
369 'Attribute "autocomplete" not allowed on element "button" at this point.',
370 'Attribute "autocomplete" is only allowed when the input type is "color", "date", "datetime", "datetime-local", "email", "hidden", "month", "number", "password", "range", "search", "tel", "text", "time", "url", or "week".',
371 'Element "img" is missing required attribute "src".'
374 src: '_gh_pages/**/*.html'
379 files: '<%= jshint.core.src %>',
380 tasks: ['jshint:core', 'qunit', 'concat']
383 files: '<%= jshint.test.src %>',
384 tasks: ['jshint:test', 'qunit']
387 files: 'less/**/*.less',
395 build: process.env.TRAVIS_JOB_ID,
399 urls: ['http://127.0.0.1:3000/js/tests/index.html?hidepassed'],
400 browsers: grunt.file.readYAML('grunt/sauce_browsers.yml')
407 command: 'npm update'
414 archive: 'bootstrap-<%= pkg.version %>-dist.zip',
424 dest: 'bootstrap-<%= pkg.version %>-dist'
433 // These plugins provide necessary tasks.
434 require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
435 require('time-grunt')(grunt);
437 // Docs HTML validation task
438 grunt.registerTask('validate-html', ['jekyll:docs', 'htmllint']);
440 var runSubset = function (subset) {
441 return !process.env.TWBS_TEST || process.env.TWBS_TEST === subset;
443 var isUndefOrNonZero = function (val) {
444 return val === undefined || val !== '0';
448 var testSubtasks = [];
449 // Skip core tests if running a different subset of the test suite
450 if (runSubset('core') &&
451 // Skip core tests if this is a Savage build
452 process.env.TRAVIS_REPO_SLUG !== 'twbs-savage/bootstrap') {
453 testSubtasks = testSubtasks.concat(['dist-css', 'dist-js', 'csslint:dist', 'test-js', 'docs']);
455 // Skip HTML validation if running a different subset of the test suite
456 if (runSubset('validate-html') &&
457 // Skip HTML5 validator on Travis when [skip validator] is in the commit message
458 isUndefOrNonZero(process.env.TWBS_DO_VALIDATOR)) {
459 testSubtasks.push('validate-html');
461 // Only run Sauce Labs tests if there's a Sauce access key
462 if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined' &&
463 // Skip Sauce if running a different subset of the test suite
464 runSubset('sauce-js-unit') &&
465 // Skip Sauce on Travis when [skip sauce] is in the commit message
466 isUndefOrNonZero(process.env.TWBS_DO_SAUCE)) {
467 testSubtasks.push('connect');
468 testSubtasks.push('saucelabs-qunit');
470 grunt.registerTask('test', testSubtasks);
471 grunt.registerTask('test-js', ['jshint:core', 'jshint:test', 'jshint:grunt', 'jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']);
473 // JS distribution task.
474 grunt.registerTask('dist-js', ['concat', 'uglify:core', 'commonjs']);
476 // CSS distribution task.
477 grunt.registerTask('less-compile', ['less:compileCore', 'less:compileTheme']);
478 grunt.registerTask('dist-css', ['less-compile', 'autoprefixer:core', 'autoprefixer:theme', 'csscomb:dist', 'cssmin:minifyCore', 'cssmin:minifyTheme']);
480 // Full distribution task.
481 grunt.registerTask('dist', ['clean:dist', 'dist-css', 'copy:fonts', 'dist-js']);
484 grunt.registerTask('default', ['clean:dist', 'copy:fonts', 'test']);
486 grunt.registerTask('build-glyphicons-data', function () { generateGlyphiconsData.call(this, grunt); });
488 // task for building customizer
489 grunt.registerTask('build-customizer', ['build-customizer-html', 'build-raw-files']);
490 grunt.registerTask('build-customizer-html', 'pug');
491 grunt.registerTask('build-raw-files', 'Add scripts/less files to customizer.', function () {
492 var banner = grunt.template.process('<%= banner %>');
493 generateRawFiles(grunt, banner);
496 grunt.registerTask('commonjs', 'Generate CommonJS entrypoint module in dist dir.', function () {
497 var srcFiles = grunt.config.get('concat.bootstrap.src');
498 var destFilepath = 'dist/js/npm.js';
499 generateCommonJSModule(grunt, srcFiles, destFilepath);
503 grunt.registerTask('docs-css', ['autoprefixer:docs', 'autoprefixer:examples', 'csscomb:docs', 'csscomb:examples', 'cssmin:docs']);
504 grunt.registerTask('lint-docs-css', ['csslint:docs', 'csslint:examples']);
505 grunt.registerTask('docs-js', ['uglify:docsJs', 'uglify:customize']);
506 grunt.registerTask('lint-docs-js', ['jshint:assets', 'jscs:assets']);
507 grunt.registerTask('docs', ['docs-css', 'lint-docs-css', 'docs-js', 'lint-docs-js', 'clean:docs', 'copy:docs', 'build-glyphicons-data', 'build-customizer']);
508 grunt.registerTask('docs-github', ['jekyll:github', 'htmlmin']);
510 grunt.registerTask('prep-release', ['dist', 'docs', 'docs-github', 'compress']);