-
Notifications
You must be signed in to change notification settings - Fork 0
/
duster.js
executable file
·32 lines (24 loc) · 1.13 KB
/
duster.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
// duster.js
// Watch directory of dust.js templates and automatically compile them
// by Dan McGrady http://dmix.ca
var src_path = "./static/dustTemplates"; // directory of dust templates are stored with .dust file extension
var public_path = "./static/jsTemplates/"; // directory where the compiled .js files should be saved to
var fs = require('fs');
var dust = require('dustjs-linkedin');
// var watcher = require('watch-tree').watchTree(src_path, {'sample-rate': 30}); // polls folder every 30ms
//console.log('got here');
//watcher.on('fileModified', function(path, stats) {
//console.log('and here');
path = "./static/dustTemplates/notebooklist.dust";
fs.readFile(path, 'ascii', function (err, data) {
if (err) throw err;
console.log('read ' + path);
var filename = path.split("/").reverse()[0].replace(".dust","");
var filepath = public_path + filename + ".js";
var compiled = dust.compile(data, filename);
fs.writeFile(filepath, compiled, function (err) {
if (err) throw err;
console.log('Saved ' + filepath);
});
});
// });