forked from cheeaun/hackerweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-templates.js
36 lines (30 loc) · 907 Bytes
/
make-templates.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
#!/usr/bin/env node
var fs = require('fs');
var hogan = require('hogan.js');
var uglifyjs = require('uglify-js');
fs.readdir('templates', function(e, files){
if (e) throw e;
var code = '(function(t){'
+ 'TEMPLATES={';
files.forEach(function(file){
if (/\.mustache$/i.test(file)){
var mustache = fs.readFileSync('templates/' + file, 'ascii');
var key = file.match(/^([^.]+)\./i)[1];
// Clean up some spaces
mustache = mustache.replace(/[\r\n\t]+/g, '');
code += "'" + key + "':new t(" + hogan.compile(mustache, {asString: true}) + "),";
}
});
code += '}'
+ '})(Hogan.Template);';
// Uglify to further shrink the file size
var finalCode = uglifyjs.minify(code, {
fromString: true,
compress: {
sequences: false
}
}).code;
fs.writeFile('js/templates.js', finalCode, function(){
console.log('js/templates.js created.');
});
});