cfefae2cddd4dd8a7d0f238f0d2ac01a524d1c2d
[bootswatch] / bower_components / bootstrap / Gruntfile.js
1 /* jshint node: true */
2
3 module.exports = function(grunt) {
4   "use strict";
5
6   // Project configuration.
7   grunt.initConfig({
8
9     // Metadata.
10     pkg: grunt.file.readJSON('package.json'),
11     banner: '/**\n' +
12               '* <%= pkg.name %>.js v<%= pkg.version %> by @fat and @mdo\n' +
13               '* Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
14               '* <%= _.pluck(pkg.licenses, "url").join(", ") %>\n' +
15               '*/\n',
16     jqueryCheck: 'if (!jQuery) { throw new Error(\"Bootstrap requires jQuery\") }\n\n',
17
18     // Task configuration.
19     clean: {
20       dist: ['dist']
21     },
22
23     jshint: {
24       options: {
25         jshintrc: 'js/.jshintrc'
26       },
27       gruntfile: {
28         src: 'Gruntfile.js'
29       },
30       src: {
31         src: ['js/*.js']
32       },
33       test: {
34         src: ['js/tests/unit/*.js']
35       }
36     },
37
38     concat: {
39       options: {
40         banner: '<%= banner %><%= jqueryCheck %>',
41         stripBanners: false
42       },
43       bootstrap: {
44         src: [
45           'js/transition.js',
46           'js/alert.js',
47           'js/button.js',
48           'js/carousel.js',
49           'js/collapse.js',
50           'js/dropdown.js',
51           'js/modal.js',
52           'js/tooltip.js',
53           'js/popover.js',
54           'js/scrollspy.js',
55           'js/tab.js',
56           'js/affix.js'
57         ],
58         dest: 'dist/js/<%= pkg.name %>.js'
59       }
60     },
61
62     uglify: {
63       options: {
64         banner: '<%= banner %>'
65       },
66       bootstrap: {
67         src: ['<%= concat.bootstrap.dest %>'],
68         dest: 'dist/js/<%= pkg.name %>.min.js'
69       }
70     },
71
72     recess: {
73       options: {
74         compile: true
75       },
76       bootstrap: {
77         src: ['less/bootstrap.less'],
78         dest: 'dist/css/<%= pkg.name %>.css'
79       },
80       min: {
81         options: {
82           compress: true
83         },
84         src: ['less/bootstrap.less'],
85         dest: 'dist/css/<%= pkg.name %>.min.css'
86       },
87       theme: {
88         src: ['less/theme.less'],
89         dest: 'dist/css/<%= pkg.name %>-theme.css'
90       },
91       theme_min: {
92         options: {
93           compress: true
94         },
95         src: ['less/theme.less'],
96         dest: 'dist/css/<%= pkg.name %>-theme.min.css'
97       }
98     },
99
100     copy: {
101       fonts: {
102         expand: true,
103         src: ["fonts/*"],
104         dest: 'dist/'
105       }
106     },
107
108     qunit: {
109       options: {
110         inject: 'js/tests/unit/phantom.js'
111       },
112       files: ['js/tests/*.html']
113     },
114
115     connect: {
116       server: {
117         options: {
118           port: 3000,
119           base: '.'
120         }
121       }
122     },
123
124     jekyll: {
125       docs: {}
126     },
127
128     validation: {
129       options: {
130         reset: true
131       },
132       files: {
133         src: ["_gh_pages/**/*.html"]
134       }
135     },
136
137     watch: {
138       src: {
139         files: '<%= jshint.src.src %>',
140         tasks: ['jshint:src', 'qunit']
141       },
142       test: {
143         files: '<%= jshint.test.src %>',
144         tasks: ['jshint:test', 'qunit']
145       },
146       recess: {
147         files: 'less/*.less',
148         tasks: ['recess']
149       }
150     }
151   });
152
153
154   // These plugins provide necessary tasks.
155   grunt.loadNpmTasks('grunt-contrib-clean');
156   grunt.loadNpmTasks('grunt-contrib-concat');
157   grunt.loadNpmTasks('grunt-contrib-connect');
158   grunt.loadNpmTasks('grunt-contrib-copy');
159   grunt.loadNpmTasks('grunt-contrib-jshint');
160   grunt.loadNpmTasks('grunt-contrib-qunit');
161   grunt.loadNpmTasks('grunt-contrib-uglify');
162   grunt.loadNpmTasks('grunt-contrib-watch');
163   grunt.loadNpmTasks('grunt-html-validation');
164   grunt.loadNpmTasks('grunt-jekyll');
165   grunt.loadNpmTasks('grunt-recess');
166   grunt.loadNpmTasks('browserstack-runner');
167
168   // Docs HTML validation task
169   grunt.registerTask('validate-html', ['jekyll', 'validation']);
170
171   // Test task.
172   var testSubtasks = ['dist-css', 'jshint', 'qunit', 'validate-html'];
173   // Only run BrowserStack tests under Travis
174   if (process.env.TRAVIS) {
175     // Only run BrowserStack tests if this is a mainline commit in twbs/bootstrap, or you have your own BrowserStack key
176     if ((process.env.TRAVIS_REPO_SLUG === 'twbs/bootstrap' && process.env.TRAVIS_PULL_REQUEST === 'false') || process.env.TWBS_HAVE_OWN_BROWSERSTACK_KEY) {
177       testSubtasks.push('browserstack_runner');
178     }
179   }
180   grunt.registerTask('test', testSubtasks);
181
182   // JS distribution task.
183   grunt.registerTask('dist-js', ['concat', 'uglify']);
184
185   // CSS distribution task.
186   grunt.registerTask('dist-css', ['recess']);
187
188   // Fonts distribution task.
189   grunt.registerTask('dist-fonts', ['copy']);
190
191   // Full distribution task.
192   grunt.registerTask('dist', ['clean', 'dist-css', 'dist-fonts', 'dist-js']);
193
194   // Default task.
195   grunt.registerTask('default', ['test', 'dist', 'build-customizer']);
196
197   // task for building customizer
198   grunt.registerTask('build-customizer', 'Add scripts/less files to customizer.', function () {
199     var fs = require('fs')
200
201     function getFiles(type) {
202       var files = {}
203       fs.readdirSync(type)
204         .filter(function (path) {
205           return type == 'fonts' ? true : new RegExp('\\.' + type + '$').test(path)
206         })
207         .forEach(function (path) {
208           return files[path] = fs.readFileSync(type + '/' + path, 'utf8')
209         })
210       return 'var __' + type + ' = ' + JSON.stringify(files) + '\n'
211     }
212
213     var customize = fs.readFileSync('customize.html', 'utf-8')
214     var files = getFiles('js') + getFiles('less') + getFiles('fonts')
215     fs.writeFileSync('assets/js/raw-files.js', files)
216   });
217 };