-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntFile.js
72 lines (56 loc) · 1.94 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
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
dist: ['<%=pkg.distDir%>']
},
less: {
styles: {
expand: true,
cwd: '<%=pkg.srcDir%>',
src: '*.less',
dest: '<%=pkg.distDir%>',
ext: '.css'
}
},
applyTemplate: {
templateFile: '<%=pkg.srcDir%>/resume-template.hbs',
dataFile: '<%=pkg.srcDir%>/resume-data.json',
outputFile: '<%=pkg.distDir%>/resume.html'
},
watch: {
css: {
files: '<%=pkg.srcDir%>/*.less',
tasks: ['less:styles'],
},
template: {
files: ['<%=pkg.srcDir%>/*.hbs', '<%=pkg.srcDir%>/*.json'],
tasks: ['applyTemplate'],
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.registerTask('applyTemplate', 'Applies the handlebars template and produces the resulting HTML file', function() {
// require config options
this.requiresConfig('applyTemplate.templateFile');
this.requiresConfig('applyTemplate.dataFile');
this.requiresConfig('applyTemplate.outputFile');
// get files from config
var templateFile = grunt.config.get('applyTemplate.templateFile');
var dataFile = grunt.option('dataFile') || grunt.config.get('applyTemplate.dataFile');
var outputFile = grunt.config.get('applyTemplate.outputFile');
// require dependencies
var fs = require('fs');
Handlebars = require('handlebars');
// compile the template
var template = Handlebars.compile( grunt.file.read(templateFile) );
// apply the template
grunt.file.write( outputFile, template( grunt.file.readJSON(dataFile) ) );
});
grunt.registerTask('build', ['less:styles', 'applyTemplate'])
// Default task(s).
grunt.registerTask('default', ['clean:dist', 'build', 'watch']);
};