forked from aozora/bootmetro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
441 lines (344 loc) · 15.8 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
module.exports = function(grunt) {
// Nodejs libs.
var fs = require('fs')
,path = require('path')
,hogan = require('hogan.js');
// load tasks
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-recess');
// grunt.loadNpmTasks('grunt-express-server');
// shared partial templates
var partial_loggeduser, partial_charms, partial_headermenu;
// retrieve partials
partial_loggeduser = getCompiledFile(__dirname + '/templates/partials/logged-user.mustache');
partial_charms = getCompiledFile(__dirname + '/templates/partials/charms.mustache');
partial_headermenu = getCompiledFile(__dirname + '/templates/partials/header-menu.mustache');
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['dist', 'docs', '_gh_pages'],
jshint: {
files: ['Gruntfile.js','src/assets/js/bootmetro-*.js'],
options: {
validthis: true,
laxcomma : true,
laxbreak : true,
browser : true,
eqnull : true,
debug : true,
devel : true,
boss : true,
expr : true,
asi : true
}
},
recess: {
dist: {
options: {
compile: true,
compress: false
},
files: {
'dist/assets/css/bootmetro.css': ['less/bootmetro/bootmetro.less'],
'dist/assets/css/bootmetro-responsive.css': ['less/bootmetro/responsive.less'],
'dist/assets/css/bootmetro-icons.css': ['less/bootmetro/bootmetro-icons.less'],
'dist/assets/css/bootmetro-ui-light.css': ['less/bootmetro/bootmetro-ui-light.less']
}
},
min: {
options: {
compile: true,
compress: true
},
files: {
'dist/assets/css/min/bootmetro.min.css': ['less/bootmetro/bootmetro.less'],
'dist/assets/css/min/bootmetro-responsive.min.css': ['less/bootmetro/responsive.less'],
'dist/assets/css/min/bootmetro-icons.min.css': ['less/bootmetro/bootmetro-icons.less'],
'dist/assets/css/min/bootmetro-ui-light.min.css': ['less/bootmetro/bootmetro-ui-light.less']
}
}
},
uglify: {
dist: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
files: {
'dist/assets/js/min/bootmetro-charms.min.js': ['src/assets/js/bootmetro-charms.js'],
'dist/assets/js/min/bootmetro-icons-ie7.min.js': ['src/assets/js/bootmetro-icons-ie7.js'],
'dist/assets/js/min/bootmetro-panorama.min.js': ['src/assets/js/bootmetro-panorama.js'],
'dist/assets/js/min/bootmetro-pivot.min.js': ['src/assets/js/bootmetro-pivot.js']
}
},
min: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'src/assets/js/<%= pkg.name %>-*.js',
dest: 'dist/assets/js/min/<%= pkg.name %>.min.js'
}
}
},
// merge all bootmetro-*.js in bootmetro.js
concat: {
dist: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
src: 'src/assets/js/<%= pkg.name %>-*.js',
dest: 'dist/assets/js/<%= pkg.name %>.js'
},
min: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
src: 'src/assets/js/min/<%= pkg.name %>-*.js',
dest: 'dist/assets/js/min/<%= pkg.name %>.min.js'
}
},
copy: {
js: {
files: [
{expand: true, cwd: 'src/assets/js/', src: ['<%= pkg.name %>-*.js'], dest: 'dist/assets/js/', filter: 'isFile'} // includes bootstrap js
]
},
vendor: {
files: [
{expand: true, cwd: 'src/assets/js/', src: ['bootstrap.js'], dest: 'dist/assets/js/', filter: 'isFile'}, // includes bootstrap js
{expand: true, cwd: 'src/assets/js/', src: ['bootstrap.min.js'], dest: 'dist/assets/js/min/', filter: 'isFile'}, // includes bootstrap js
{expand: true, cwd: 'src/assets/js/', src: ['bootstrap-datepicker.js'], dest: 'dist/assets/js/', filter: 'isFile'}, // includes bootstrap js
{expand: true, cwd: 'src/assets/css/',src: ['datepicker.css'], dest: 'dist/assets/css/', filter: 'isFile'}, // includes bootstrap js
{expand: true, cwd: 'src/assets/js/', src: ['jquery.touchSwipe.*'], dest: 'dist/assets/js/', filter: 'isFile'}, // includes touchSwipe js
{expand: true, cwd: 'src/assets/js/', src: ['jquery-1.10.0.*'], dest: 'dist/assets/js/', filter: 'isFile'}, // includes jquery js
{expand: true, cwd: 'src/assets/js/', src: ['modernizr-2.6.2.min.js'], dest: 'dist/assets/js/', filter: 'isFile'}, // includes modernizr js
{expand: true, cwd: 'src/assets/js/', src: ['jquery.mousewheel.*'], dest: 'dist/assets/js/', filter: 'isFile'} // includes mousewheel js
]
},
font: {
files: [
{expand: true, cwd: 'src/assets/font/', src: '**/*', dest: 'dist/assets/font/', filter: 'isFile'}
]
},
ghpages_assets: {
files: [
{expand: true, cwd: 'dist/', src: 'assets/**/*', dest: '_gh_pages/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/', src: 'img/**/*', dest: '_gh_pages/assets/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/css', src: 'demo.css', dest: '_gh_pages/assets/css/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/css', src: 'docs.css', dest: '_gh_pages/assets/css/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/css', src: 'site.css', dest: '_gh_pages/assets/css/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/js/', src: 'google-code-prettify/**/*', dest: '_gh_pages/assets/js/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/js', src: 'Chart.min.js', dest: '_gh_pages/assets/js/min/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/js', src: 'holder.js', dest: '_gh_pages/assets/js/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/js', src: 'docs.js', dest: '_gh_pages/assets/js/', filter: 'isFile'},
{expand: true, cwd: 'src/assets/js', src: 'demo.js', dest: '_gh_pages/assets/js/', filter: 'isFile'}
]
},
docs2dist: {
files: [
{expand: true, cwd: '_gh_pages/', src: 'docs/**/*', dest: 'dist/'}
]
}
},
buildtemplates: {
ghpages: {
src: 'templates/pages/',
dest: '_gh_pages/'
},
demo4ghpages: {
options: {
assetsPath: '../'
},
src: 'templates/demo/',
dest: '_gh_pages/demo/'
},
demo4dist: {
options: {
assetsPath: './'
},
src: 'templates/demo/',
dest: 'dist/demo/'
}
},
builddocs: {
options: {
assetsPath: '../'
},
dist: {
src: 'templates/docs/',
dest: '_gh_pages/docs/'
}
} //,
});
// Default task(s).
grunt.registerTask('default',
[
'clean', // clean folders _gh_pages & dist
'jshint', // run jshint on bootmetro js files
'recess:dist', // generate css from less (not minimized)
'recess:min', // generate css from less (minimized)
'uglify:dist', // minimize js files
'uglify:min', // minimize js files
'copy:js', // copy bootmetro js to dist
'copy:vendor', // copy vendor js to dist
'copy:font', // copy fonts to dist
'concat:dist',
'concat:min',
'buildtemplates:ghpages', // build main site html to _gh_pages
'copy:ghpages_assets', // copy all assets to _gh_pages
'buildtemplates:demo4ghpages', // build demo pages to _gh_pages
'buildtemplates:demo4dist', // build demo pages to dist
'builddocs' //, // build docs pages to _gh_pages
//'copy:docs2dist'
]
);
grunt.registerMultiTask('buildtemplates', 'Build hogan templates into html pages', function(/*templateDirs, destPath*/) {
try {
grunt.log.writeln('\nBuilding ' + this.target + '...');
// merge options with defaults
var options = this.options({
assetsPath: './'
});
this.files.forEach(function(f) {
// grunt.log.writeln(' src = ' + f.src)
// grunt.log.writeln(' dest = ' + f.dest)
var destinationPath = __dirname + '/' + f.dest;
// cycle for each template dir (pages / demo)
f.src.forEach(function(src){
var templatedir = __dirname + '/' + src
grunt.log.writeln(' templatedir = ' + templatedir)
// compile layout template
var layout = getCompiledFile(templatedir + '/_layout.mustache')
// retrieve pages
var pages = fs.readdirSync(templatedir)
// iterate over pages
pages.forEach(function (name) {
// exclude non mustache files
if (!name.match(/\.mustache$/))
return
// exclude files that start with "_"
if (name.substring(0, 1) == '_')
return
var context = {}
context[name.replace(/\.mustache$/, '')] = 'active'
context._i = true
context.production = 'production'
context.appname = 'BootMetro'
context.title = name.replace(/\.mustache/, '')
.replace(/\-.*/, '')
.replace(/(.)/, function ($1) {
return $1.toUpperCase()
})
var assetsPath = options.assetsPath
//grunt.log.writeln(' assetsPath = ' + assetsPath)
context.assetspath = assetsPath
var page = getCompiledFile(templatedir + '/' + name)
page = layout.render(context, {
body: page,
charms: partial_charms,
loggeduser: partial_loggeduser,
headermenu: partial_headermenu
})
// if ( templatedir.match(/pages$/) ){
// destinationPath = __dirname + dest;
// } else {
// // demo & docs
// destinationPath = __dirname + dest + 'demo-'
// }
var fullDestinationPath = destinationPath + name.replace(/mustache$/, 'html');
grunt.log.writeln('building ' + fullDestinationPath)
//fs.writeFileSync(fullDestinationPath, page, 'utf-8')
grunt.file.write(fullDestinationPath, page, 'utf-8')
})
})
});
grunt.log.write('OK\n');
return grunt.log.ok();
} catch (e) {
grunt.log.error();
grunt.verbose.error(e);
return grunt.fail.warn('operation failed.');
}
});
grunt.registerMultiTask('builddocs', 'Build documentation html pages', function() {
try {
grunt.log.write('\nBuilding docs...');
// merge options with defaults
var options = this.options({
assetsPath: './'
});
this.files.forEach(function(f) {
var destinationPath = __dirname + '/' + f.dest;
// cycle for each template dir (pages / demo)
f.src.forEach(function(src){
// retrieve pages
var docTemplateDir = __dirname + '/' + f.src
,docTemplatePartialDir = __dirname + '/' + f.src + 'partials'
,docTemplateSidebarPartialDir = __dirname + '/' + f.src + 'sidebar_partials'
,partial_sidebar
,docPages = fs.readdirSync(docTemplateDir)
// compile layout template
var doc_layout = getCompiledFile(__dirname + '/' + f.src + '/_layout.mustache')
// iterate over pages
docPages.forEach(function (name) {
// exclude non mustache files
if (!name.match(/\.mustache$/))
return
// exclude _layout & index
if (name.match(/^_layout/) || name.match(/^index/))
return
// check if the current page has scripts definex in partial pages
var hasSidebarPartial = fs.existsSync(docTemplateSidebarPartialDir + '/sidebar-' + name)
if (hasSidebarPartial){
partial_sidebar = getCompiledFile(docTemplateSidebarPartialDir + '/sidebar-' + name)
}
// put partials into context
var docContext = {}
,partialsContext = {}
,files = fs.readdirSync(docTemplatePartialDir)
files.forEach(function(name){
var partial = getCompiledFile(docTemplatePartialDir + '/' + name)
Object.defineProperty(partialsContext, name.replace(/\.mustache$/, ''), {value : partial});
})
docContext[name.replace(/\.mustache$/, '')] = 'active'
docContext._i = true
docContext.production = 'production'
docContext.appname = 'BootMetro'
docContext.title = name.replace(/\.mustache/, '')
.replace(/\-.*/, '')
.replace(/(.)/, function ($1) {
return $1.toUpperCase()
})
var assetsPath = options.assetsPath
//grunt.log.writeln(' assetsPath = ' + assetsPath)
docContext.assetspath = assetsPath
var docPage = getCompiledFile(docTemplateDir + '/' + name)
partialsContext.body = docPage
partialsContext.sidebar = partial_sidebar
docPage = doc_layout.render(docContext, partialsContext)
var fullDestinationPath = destinationPath + name.replace(/mustache$/, 'html');
grunt.log.writeln('building ' + fullDestinationPath)
grunt.file.write(fullDestinationPath, docPage, 'utf-8')
})
});
});
grunt.log.write('OK\n');
return grunt.log.ok();
} catch (e) {
grunt.log.error();
grunt.verbose.error(e);
return grunt.fail.warn('operation failed.');
}
});
function getCompiledFile(path){
//console.log('getCompiledFile(\'' + path + '\')')
var layout = fs.readFileSync(path, 'utf-8')
layout = hogan.compile(layout, { sectionTags:[ {o:'_i', c:'i'} ] })
return layout;
}
};