UNPKG

10.1 kBJavaScriptView Raw
1/*global module,require*/
2var pageBuilder = require('./tests/pages/_script/page-builder'),
3 open = require('open');
4
5module.exports = function (grunt) {
6 'use strict';
7
8 // configurable paths
9 var projectConfig = {
10 dist: 'dist',
11 src: ''
12 };
13
14 // load all grunt tasks
15 require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
16
17 try {
18 projectConfig.src = require('./bower.json').appPath || projectConfig.src;
19 } catch (e) {}
20
21 grunt.initConfig({
22 config: projectConfig,
23 connect: {
24 server: {
25 options: {
26 hostname: '0.0.0.0',
27 livereload: true,
28 base: [
29 projectConfig.src,
30 projectConfig.dist + '/tests'
31 ],
32 port: 9000
33 }
34 }
35 },
36 run: {
37 options: {
38 },
39 bundleInstall: {
40 cmd: 'bundle',
41 args: [
42 'install'
43 ]
44 }
45 },
46 clean: {
47 build: '<%= config.dist %>'
48 },
49 concat: {
50 js: {
51 files: {
52 'dist/js/patternfly-settings.js': [
53 'src/js/patternfly-settings-base.js',
54 'src/js/patternfly-settings-colors.js',
55 'src/js/patternfly-settings-charts.js'
56 ],
57 'dist/js/patternfly-functions.js': [
58 'src/js/patternfly-functions-base.js',
59 'src/js/patternfly-functions-list.js',
60 'src/js/patternfly-functions-sidebar.js',
61 'src/js/patternfly-functions-popovers.js',
62 'src/js/patternfly-functions-data-tables.js',
63 'src/js/patternfly-functions-navigation.js',
64 'src/js/patternfly-functions-count-chars.js',
65 'src/js/patternfly-functions-colors.js',
66 'src/js/patternfly-functions-charts.js',
67 'src/js/patternfly-functions-fixed-heights.js',
68 'src/js/patternfly-functions-tree-grid.js',
69 'src/js/patternfly-functions-vertical-nav.js'
70 ],
71 'dist/js/patternfly.js': [
72 'dist/js/patternfly-settings.js',
73 'dist/js/patternfly-functions.js'
74 ]
75 }
76 }
77 },
78 copy: {
79 main: {
80 files: [
81 // copy Bootstrap font files
82 {expand: true, cwd: 'node_modules/bootstrap/dist/fonts/', src: ['*'], dest: 'dist/fonts/'},
83 // copy Font Awesome font files
84 {expand: true, cwd: 'node_modules/font-awesome/fonts/', src: ['*'], dest: 'dist/fonts/'},
85 // copy Patternfly less files
86 {expand: true, cwd: 'src/less/', src: ['*'], dest: 'dist/less/'},
87 // copy Patternfly font files
88 {expand: true, cwd: 'src/fonts/', src: ['*'], dest: 'dist/fonts/'},
89 //copy images
90 {expand: true, cwd: 'src/img/', src: ['**'], dest: 'dist/img/'},
91 // Dependencies
92 // copy Bootstrap less files
93 {expand: true, cwd: 'node_modules/bootstrap/less/', src: ['**'], dest: 'dist/less/dependencies/bootstrap/'},
94 // copy Font Awesome less files
95 {expand: true, cwd: 'node_modules/font-awesome/less/', src: ['**'], dest: 'dist/less/dependencies/font-awesome/'},
96 // copy Bootstrap-Combobox less files
97 {expand: true, cwd: 'node_modules/patternfly-bootstrap-combobox/less/', src: ['**'], dest: 'dist/less/dependencies/bootstrap-combobox/'},
98 // copy Bootstrap-Datepicker less files
99 {expand: true, cwd: 'node_modules/bootstrap-datepicker/less/', src: ['**'], dest: 'dist/less/dependencies/bootstrap-datepicker/'},
100 // copy Bootstrap-Select less files
101 {expand: true, cwd: 'node_modules/bootstrap-select/less/', src: ['**'], dest: 'dist/less/dependencies/bootstrap-select/'},
102 // Bootstrap Switch less files must be manually copied because of edits made to source less for strict-math purposes
103 // manually copy 'node_modules/bootstrap-switch/src/less/bootstrap3/' and make sure any math is wrapped with parentheses
104 // copy Bootstrap Touchspin css file
105 {expand: true, cwd: 'node_modules/bootstrap-touchspin/dist/', src: ['jquery.bootstrap-touchspin.css'], dest: 'dist/less/dependencies/bootstrap-touchspin/'},
106 // copy C3 css file
107 {expand: true, cwd: 'node_modules/c3/', src: ['c3.css'], dest: 'dist/less/dependencies/c3/'}
108 ]
109 },
110 js: {
111 files: [
112 // copy js src file
113 {expand: true, cwd: 'src/js/', src: ['*.js'], dest: 'dist/js/'}
114 ]
115 }
116 },
117 csscount: {
118 production: {
119 src: [
120 'dist/css/patternfly*.min.css'
121 ],
122 options: {
123 maxSelectors: 4096
124 }
125 }
126 },
127 jekyll: {
128 options: {
129 src: 'tests/pages',
130 bundleExec: 'true'
131 },
132 tests: {
133 options: {
134 dest: 'dist/tests'
135 }
136 }
137 },
138 cssmin: {
139 production: {
140 files: [{
141 expand: true,
142 cwd: 'dist/css',
143 src: ['patternfly*.css', '!*.min.css'],
144 dest: 'dist/css',
145 ext: '.min.css',
146 }],
147 options: {
148 sourceMap: true
149 }
150 }
151 },
152 less: {
153 patternfly: {
154 files: {
155 'dist/css/patternfly.css': 'src/less/patternfly.less',
156 },
157 options: {
158 paths: [
159 'src/less/',
160 'node_modules/'
161 ],
162 strictMath: true,
163 sourceMap: true,
164 outputSourceFiles: true,
165 sourceMapFilename: 'dist/css/patternfly.css.map',
166 sourceMapURL: 'patternfly.css.map'
167 }
168 },
169 patternflyAdditions: {
170 files: {
171 'dist/css/patternfly-additions.css': 'src/less/patternfly-additions.less'
172 },
173 options: {
174 paths: [
175 'src/less/',
176 'node_modules/'
177 ],
178 strictMath: true,
179 sourceMap: true,
180 outputSourceFiles: true,
181 sourceMapFilename: 'dist/css/patternfly-additions.css.map',
182 sourceMapURL: 'patternfly-additions.css.map'
183 }
184 }
185 },
186 uglify: {
187 options: {
188 mangle: false
189 },
190 production: {
191 files: {
192 'dist/js/patternfly.min.js': ['dist/js/patternfly.js'],
193 'dist/js/patternfly-settings.min.js': ['dist/js/patternfly-settings.js'],
194 'dist/js/patternfly-functions.min.js': ['dist/js/patternfly-functions.js'],
195 'dist/js/patternfly.dataTables.pfEmpty.min.js': ['src/js/patternfly.dataTables.pfEmpty.js'],
196 'dist/js/patternfly.dataTables.pfFilter.min.js': ['src/js/patternfly.dataTables.pfFilter.js'],
197 'dist/js/patternfly.dataTables.pfPagination.min.js': ['src/js/patternfly.dataTables.pfPagination.js'],
198 'dist/js/patternfly.dataTables.pfResize.min.js': ['src/js/patternfly.dataTables.pfResize.js'],
199 'dist/js/patternfly.dataTables.pfSelect.min.js': ['src/js/patternfly.dataTables.pfSelect.js']
200 }
201 }
202 },
203 watch: {
204 copy: {
205 files: [
206 'node_modules/bootstrap/dist/fonts/**/*',
207 'node_modules/font-awesome/fonts/**/*',
208 'src/fonts/**/*',
209 'src/img/**/*'
210 ],
211 tasks: ['copy']
212 },
213 jekyll: {
214 files: 'tests/pages/**/*',
215 tasks: ['pages']
216 },
217 less: {
218 files: ['src/less/*.less'],
219 tasks: ['less']
220 },
221 css: {
222 files: ['dist/css/patternfly*.css', 'dist/css/!*.min.css'],
223 tasks: ['cssmin','csscount']
224 },
225 js: {
226 files: ['src/js/*.js'],
227 tasks: ['eslint', 'concat', 'copy:js', 'uglify']
228 },
229 livereload: {
230 files: ['dist/css/*.css', 'dist/js/*.js', 'dist/tests/*.html', '!tests/pages/*.html']
231 },
232 options: {
233 livereload: true
234 }
235 },
236 karma: {
237 unit: {
238 configFile: 'karma.conf.js'
239 }
240 },
241 htmlhint: {
242 html: {
243 src: ['dist/tests/**/*.html'],
244 options: {
245 htmlhintrc: '.htmlhintrc'
246 }
247 }
248 },
249 eslint: {
250 options: {
251 configFile: 'eslint.yaml'
252 },
253 target: [
254 'Gruntfile.js',
255 'src/js/**/*.js',
256 'tests/pages/_script/**/*.js'
257 ]
258 },
259 stylelint: {
260 src: ['src/less/*.less']
261 },
262 postcss: {
263 options: {
264 processors: [
265 require('pixrem')(), // add fallbacks for rem units
266 require('autoprefixer')({browsers: ['last 3 versions', 'ie 9']}) // add vendor prefixes,
267 ]
268 },
269 dist: {
270 files: [
271 {
272 expand: true, // Enable dynamic expansion.
273 cwd: 'dist/css/', // Src matches are relative to this path.
274 src: ['*.css'], // Actual pattern(s) to match.
275 dest: 'dist/css' // Destination path prefix.
276 }
277 ]
278 }
279
280 }
281 });
282
283 grunt.registerTask('pages', 'Builds the PatternFly test pages.', function (_target) {
284 var target = _target || process.env.PF_PAGE_BUILDER || 'script';
285 var done;
286 if (target === 'jekyll') { // eg: grunt build:jekyll || PF_PAGE_BUILDER=jekyll build
287 grunt.log.writeln('Builidng test pages with ruby jekyll');
288 grunt.task.run('run:bundleInstall', 'jekyll');
289 } else if (target === 'script') { // eg: grunt build:script
290 grunt.log.writeln('Builidng test pages with liquid.js');
291 done = this.async();
292 pageBuilder.build()
293 .then(function () {
294 done();
295 });
296 } else {
297 grunt.log.writeln('Invalid taget:', target);
298 }
299 });
300
301 grunt.registerTask('build', [
302 'clean',
303 'concat',
304 'copy',
305 'pages',
306 'less',
307 'cssmin',
308 'postcss',
309 'csscount',
310 'eslint',
311 'uglify',
312 'htmlhint',
313 'stylelint'
314 ]);
315
316 grunt.registerTask('serve', [
317 'connect:server',
318 'open',
319 'watch'
320 ]);
321
322 grunt.registerTask('open', function () {
323 open('http://localhost:9000');
324 });
325
326 grunt.registerTask('server', function () {
327 grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
328 grunt.task.run(['serve']);
329 });
330
331 grunt.registerTask('default', ['build']);
332};