3.0.0 -> 3.0.1
[bootswatch] / bower_components / bootstrap / Gruntfile.js
1 /* jshint node: true */
2
3 module.exports = function(grunt) {
4   "use strict";
5
6   var btoa = require('btoa')
7   // Project configuration.
8   grunt.initConfig({
9
10     // Metadata.
11     pkg: grunt.file.readJSON('package.json'),
12     banner: '/*!\n' +
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' +
16               ' *\n' +
17               ' * Designed and built with all the love in the world by @mdo and @fat.\n' +
18               ' */\n\n',
19     jqueryCheck: 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap requires jQuery") }\n\n',
20
21     // Task configuration.
22     clean: {
23       dist: ['dist']
24     },
25
26     jshint: {
27       options: {
28         jshintrc: 'js/.jshintrc'
29       },
30       gruntfile: {
31         src: 'Gruntfile.js'
32       },
33       src: {
34         src: ['js/*.js']
35       },
36       test: {
37         src: ['js/tests/unit/*.js']
38       }
39     },
40
41     concat: {
42       options: {
43         banner: '<%= banner %><%= jqueryCheck %>',
44         stripBanners: false
45       },
46       bootstrap: {
47         src: [
48           'js/transition.js',
49           'js/alert.js',
50           'js/button.js',
51           'js/carousel.js',
52           'js/collapse.js',
53           'js/dropdown.js',
54           'js/modal.js',
55           'js/tooltip.js',
56           'js/popover.js',
57           'js/scrollspy.js',
58           'js/tab.js',
59           'js/affix.js'
60         ],
61         dest: 'dist/js/<%= pkg.name %>.js'
62       }
63     },
64
65     uglify: {
66       options: {
67         banner: '<%= banner %>',
68         report: 'min'
69       },
70       bootstrap: {
71         src: ['<%= concat.bootstrap.dest %>'],
72         dest: 'dist/js/<%= pkg.name %>.min.js'
73       }
74     },
75
76     recess: {
77       options: {
78         compile: true,
79         banner: '<%= banner %>'
80       },
81       bootstrap: {
82         src: ['less/bootstrap.less'],
83         dest: 'dist/css/<%= pkg.name %>.css'
84       },
85       min: {
86         options: {
87           compress: true
88         },
89         src: ['less/bootstrap.less'],
90         dest: 'dist/css/<%= pkg.name %>.min.css'
91       },
92       theme: {
93         src: ['less/theme.less'],
94         dest: 'dist/css/<%= pkg.name %>-theme.css'
95       },
96       theme_min: {
97         options: {
98           compress: true
99         },
100         src: ['less/theme.less'],
101         dest: 'dist/css/<%= pkg.name %>-theme.min.css'
102       }
103     },
104
105     copy: {
106       fonts: {
107         expand: true,
108         src: ["fonts/*"],
109         dest: 'dist/'
110       }
111     },
112
113     qunit: {
114       options: {
115         inject: 'js/tests/unit/phantom.js'
116       },
117       files: ['js/tests/*.html']
118     },
119
120     connect: {
121       server: {
122         options: {
123           port: 3000,
124           base: '.'
125         }
126       }
127     },
128
129     jekyll: {
130       docs: {}
131     },
132
133     validation: {
134       options: {
135         reset: true,
136         relaxerror: [
137             "Bad value X-UA-Compatible for attribute http-equiv on element meta.",
138             "Element img is missing required attribute src."
139         ]
140       },
141       files: {
142         src: ["_gh_pages/**/*.html"]
143       }
144     },
145
146     watch: {
147       src: {
148         files: '<%= jshint.src.src %>',
149         tasks: ['jshint:src', 'qunit']
150       },
151       test: {
152         files: '<%= jshint.test.src %>',
153         tasks: ['jshint:test', 'qunit']
154       },
155       recess: {
156         files: 'less/*.less',
157         tasks: ['recess']
158       }
159     }
160   });
161
162
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');
176
177   // Docs HTML validation task
178   grunt.registerTask('validate-html', ['jekyll', 'validation']);
179
180   // Test task.
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');
187     }
188   }
189   grunt.registerTask('test', testSubtasks);
190
191   // JS distribution task.
192   grunt.registerTask('dist-js', ['concat', 'uglify']);
193
194   // CSS distribution task.
195   grunt.registerTask('dist-css', ['recess']);
196
197   // Fonts distribution task.
198   grunt.registerTask('dist-fonts', ['copy']);
199
200   // Full distribution task.
201   grunt.registerTask('dist', ['clean', 'dist-css', 'dist-fonts', 'dist-js']);
202
203   // Default task.
204   grunt.registerTask('default', ['test', 'dist', 'build-customizer']);
205
206   // task for building customizer
207   grunt.registerTask('build-customizer', 'Add scripts/less files to customizer.', function () {
208     var fs = require('fs')
209
210     function getFiles(type) {
211       var files = {}
212       fs.readdirSync(type)
213         .filter(function (path) {
214           return type == 'fonts' ? true : new RegExp('\\.' + type + '$').test(path)
215         })
216         .forEach(function (path) {
217           var fullPath = type + '/' + path
218           return files[path] = (type == 'fonts' ? btoa(fs.readFileSync(fullPath)) : fs.readFileSync(fullPath, 'utf8'))
219         })
220       return 'var __' + type + ' = ' + JSON.stringify(files) + '\n'
221     }
222
223     var files = getFiles('js') + getFiles('less') + getFiles('fonts')
224     fs.writeFileSync('docs-assets/js/raw-files.js', files)
225   });
226 };