This repository was archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathGruntfile.js
143 lines (127 loc) · 2.91 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
server: {
options: {
port: 9001,
open : true,
livereload : true
}
}
},
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
ignores: 'public/js/lib/*.js'
},
files: 'public/js/src/*.js'
},
bump: {
options: {
files: 'package.json',
commit: false,
createTag: false,
push: false
}
},
sass: {
options: {
implementation: require('node-sass'),
outputStyle: 'compressed',
sourceMap: true
},
dist: {
files: {
'public/css/lib/app-<%= pkg.version %>.min.css': 'public/css/src/app.scss'
}
}
},
uglify: {
watch: {
options: {
mangle: true,
preserveComments: false,
compress: false
},
files: {
'public/js/lib/app-<%= pkg.version %>.min.js': [
'public/js/src/*.js'
]
}
}
},
watch: {
lint: {
files: 'public/js/src/app.js',
tasks: 'jshint'
},
js: {
files: 'public/js/src/*.js',
tasks: 'uglify'
},
css: {
files: 'public/css/**/*.scss',
tasks: 'sass'
},
html: {
files: ['src/**/*'],
tasks: 'templates'
}
}
});
/* a custom task to create static html files */
grunt.registerTask('templates', 'Compiles html templates for all implementations.', function() {
var implementation,
html,
done = this.async(),
Handlebars = require('handlebars'),
minifier = require('html-minifier').minify,
data = grunt.file.readJSON('src/data.json'),
source = grunt.file.read('src/template.html'),
template = Handlebars.compile(source),
getHtml = function(data, implementation, isHomepage) {
var html;
data._implementation = data.implementations[implementation];
data._isHomepage = isHomepage;
data._website = {
version: grunt.config.data.pkg.version
};
html = template(data);
/* try to minify */
try {
html = minifier(html, {
removeComments: true,
collapseWhitespace: true
});
} catch (err) {
grunt.warn('Could not minify "'+implementation+'"');
}
return html;
};
grunt.log.writeln('Compiling templates...');
/* for each implementation, create a folder with an index.html in it */
for (implementation in data.implementations) {
/* produce html for the implementation */
html = getHtml(data, implementation, false);
grunt.file.write(implementation+'/index.html', html);
/* also create the main `index.html` for the root directory (from javascript version) */
if (implementation === 'javascript') {
html = getHtml(data, implementation, true);
grunt.file.write('index.html', html);
}
}
return done();
});
/* auto-load all tasks that start with `grunt-` */
require('load-grunt-tasks')(grunt);
grunt.registerTask('default', [
'sass',
'uglify',
'templates',
'connect',
'watch'
]);
};