-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathduster.js
32 lines (26 loc) · 1.02 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 input_path = "./dusts"; // directory of dust templates are stored with .dust file extension
var output_path = "./compiled/"; // directory where the compiled .js files should be saved to
var fs = require('fs');
var dust = require('dustjs-linkedin');
var watch = require('watch');
function compile_dust(path, curr, prev) {
fs.readFile(path, function(err, data) {
if (err) throw err;
var filename = path.split("/").reverse()[0].replace(".dust", "");
var filepath = output_path + filename + ".js";
var compiled = dust.compile(new String(data), filename);
fs.writeFile(filepath, compiled, function(err) {
if (err) throw err;
console.log('Saved ' + filepath);
});
});
}
watch.createMonitor(input_path, function (monitor) {
console.log("Watching " + input_path);
monitor.files['*.dust', '*/*'];
monitor.on("created", compile_dust);
monitor.on("changed", compile_dust);
})