1 /* jshint node: true */
3 module.exports = function(grunt) {
6 var btoa = require('btoa')
7 // Project configuration.
11 pkg: grunt.file.readJSON('package.json'),
13 ' * Bootstrap v<%= pkg.version %> by @fat and @mdo\n' +
14 ' * Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
15 ' * Licensed under <%= _.pluck(pkg.licenses, "url").join(", ") %>\n' +
17 ' * Designed and built with all the love in the world by @mdo and @fat.\n' +
19 jqueryCheck: 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery") }\n\n',
21 // Task configuration.
28 jshintrc: 'js/.jshintrc'
37 src: ['js/tests/unit/*.js']
43 banner: '<%= banner %><%= jqueryCheck %>',
61 dest: 'dist/js/<%= pkg.name %>.js'
67 banner: '<%= banner %>',
71 src: ['<%= concat.bootstrap.dest %>'],
72 dest: 'dist/js/<%= pkg.name %>.min.js'
79 banner: '<%= banner %>'
82 src: ['less/bootstrap.less'],
83 dest: 'dist/css/<%= pkg.name %>.css'
89 src: ['less/bootstrap.less'],
90 dest: 'dist/css/<%= pkg.name %>.min.css'
93 src: ['less/theme.less'],
94 dest: 'dist/css/<%= pkg.name %>-theme.css'
100 src: ['less/theme.less'],
101 dest: 'dist/css/<%= pkg.name %>-theme.min.css'
115 inject: 'js/tests/unit/phantom.js'
117 files: ['js/tests/*.html']
137 "Bad value X-UA-Compatible for attribute http-equiv on element meta.",
138 "Element img is missing required attribute src."
142 src: ["_gh_pages/**/*.html"]
148 files: '<%= jshint.src.src %>',
149 tasks: ['jshint:src', 'qunit']
152 files: '<%= jshint.test.src %>',
153 tasks: ['jshint:test', 'qunit']
156 files: 'less/*.less',
163 // These plugins provide necessary tasks.
164 grunt.loadNpmTasks('browserstack-runner');
165 grunt.loadNpmTasks('grunt-contrib-clean');
166 grunt.loadNpmTasks('grunt-contrib-concat');
167 grunt.loadNpmTasks('grunt-contrib-connect');
168 grunt.loadNpmTasks('grunt-contrib-copy');
169 grunt.loadNpmTasks('grunt-contrib-jshint');
170 grunt.loadNpmTasks('grunt-contrib-qunit');
171 grunt.loadNpmTasks('grunt-contrib-uglify');
172 grunt.loadNpmTasks('grunt-contrib-watch');
173 grunt.loadNpmTasks('grunt-html-validation');
174 grunt.loadNpmTasks('grunt-jekyll');
175 grunt.loadNpmTasks('grunt-recess');
177 // Docs HTML validation task
178 grunt.registerTask('validate-html', ['jekyll', 'validation']);
181 var testSubtasks = ['dist-css', 'jshint', 'qunit', 'validate-html'];
182 // Only run BrowserStack tests under Travis
183 if (process.env.TRAVIS) {
184 // Only run BrowserStack tests if this is a mainline commit in twbs/bootstrap, or you have your own BrowserStack key
185 if ((process.env.TRAVIS_REPO_SLUG === 'twbs/bootstrap' && process.env.TRAVIS_PULL_REQUEST === 'false') || process.env.TWBS_HAVE_OWN_BROWSERSTACK_KEY) {
186 testSubtasks.push('browserstack_runner');
189 grunt.registerTask('test', testSubtasks);
191 // JS distribution task.
192 grunt.registerTask('dist-js', ['concat', 'uglify']);
194 // CSS distribution task.
195 grunt.registerTask('dist-css', ['recess']);
197 // Fonts distribution task.
198 grunt.registerTask('dist-fonts', ['copy']);
200 // Full distribution task.
201 grunt.registerTask('dist', ['clean', 'dist-css', 'dist-fonts', 'dist-js']);
204 grunt.registerTask('default', ['test', 'dist', 'build-customizer']);
206 // task for building customizer
207 grunt.registerTask('build-customizer', 'Add scripts/less files to customizer.', function () {
208 var fs = require('fs')
210 function getFiles(type) {
213 .filter(function (path) {
214 return type == 'fonts' ? true : new RegExp('\\.' + type + '$').test(path)
216 .forEach(function (path) {
217 var fullPath = type + '/' + path
218 return files[path] = (type == 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'))
220 return 'var __' + type + ' = ' + JSON.stringify(files) + '\n'
223 var files = getFiles('js') + getFiles('less') + getFiles('fonts')
224 fs.writeFileSync('docs-assets/js/raw-files.js', files)