-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
203 lines (176 loc) · 5.55 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
/*!
* Bootstrap's Gruntfile
* http://getbootstrap.com
* Copyright 2013-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
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 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 generateCommonJSModule = require('./bootstrap/grunt/bs-commonjs-generator.js');
var configBridge = grunt.file.readJSON('./bootstrap/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);
});
});
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * Bootstrap v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright 2011-<%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n' +
' */\n',
jqueryCheck: configBridge.config.jqueryCheck.join('\n'),
jqueryVersionCheck: configBridge.config.jqueryVersionCheck.join('\n'),
// Task configuration.
clean: {
dist: 'css',
},
concat: {
bootstrap: {
src: [
'bootstrap/js/transition.bootstrap/js',
'bootstrap/js/alert.bootstrap/js',
'bootstrap/js/button.bootstrap/js',
'bootstrap/js/carousel.bootstrap/js',
'bootstrap/js/collapse.bootstrap/js',
'bootstrap/js/dropdown.bootstrap/js',
'bootstrap/js/modal.bootstrap/js',
'bootstrap/js/tooltip.bootstrap/js',
'bootstrap/js/popover.bootstrap/js',
'bootstrap/js/scrollspy.bootstrap/js',
'bootstrap/js/tab.bootstrap/js',
'bootstrap/js/affix.bootstrap/js'
],
dest: 'js/<%= pkg.name %>.js'
}
},
uglify: {
options: {
preserveComments: 'some'
},
core: {
src: '<%= concat.bootstrap.dest %>',
dest: 'js/<%= pkg.name %>.min.js'
},
},
less: {
compileCore: {
options: {
strictMath: true,
sourceMap: true,
outputSourceFiles: true,
sourceMapURL: '<%= pkg.name %>.css.map',
sourceMapFilename: 'css/<%= pkg.name %>.css.map'
},
src: 'less/bootstrap.less',
dest: 'css/<%= pkg.name %>.css'
},
compileTheme: {
options: {
strictMath: true,
sourceMap: true,
outputSourceFiles: true,
sourceMapURL: '<%= pkg.name %>-theme.css.map',
sourceMapFilename: 'css/<%= pkg.name %>-theme.css.map'
},
src: 'less/theme.less',
dest: 'css/<%= pkg.name %>-theme.css'
},
compileModif: {
options: {
strictMath: true,
sourceMap: false,
outputSourceFiles: true,
},
src: 'less/modifications.less',
dest: 'css/modifications.css'
}
},
autoprefixer: {
options: {
browsers: configBridge.config.autoprefixerBrowsers
},
core: {
options: {
map: true
},
src: 'css/<%= pkg.name %>.css'
},
theme: {
options: {
map: true
},
src: 'css/<%= pkg.name %>-theme.css'
},
},
cssmin: {
options: {
compatibility: 'ie8',
keepSpecialComments: '*',
advanced: false
},
minifyCore: {
src: 'css/<%= pkg.name %>.css',
dest: 'css/<%= pkg.name %>.min.css'
},
minifyTheme: {
src: 'css/modifications.css',
dest: 'css/modifications.min.css'
},
},
copy: {
fonts: {
src: 'bootstrap/fonts/*',
dest: 'fonts/'
},
},
watch: {
less: {
files: 'less/**/*.less',
tasks: 'less'
}
},
exec: {
npmUpdate: {
command: 'npm update'
}
},
});
// These plugins provide necessary tasks.
require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });
require('time-grunt')(grunt);
// Docs HTML validation task
grunt.registerTask('validate-html', ['jekyll:docs', 'validation']);
var runSubset = function (subset) {
return !process.env.TWBS_TEST || process.env.TWBS_TEST === subset;
};
var isUndefOrNonZero = function (val) {
return val === undefined || val !== '0';
};
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', 'commonjs']);
// CSS distribution task.
grunt.registerTask('less-compile', ['less:compileCore', 'less:compileTheme', 'less:compileModif']);
grunt.registerTask('dist-css', ['less-compile', 'autoprefixer:core', 'autoprefixer:theme', 'usebanner', 'csscomb:dist', 'cssmin:minifyCore', 'cssmin:minifyTheme']);
// Full distribution task.
grunt.registerTask('dist', ['clean:dist', 'dist-css', 'copy:fonts', 'dist-js']);
// Default task.
grunt.registerTask('default', ['clean:dist', 'copy:fonts', 'test']);
};