forked from feedhenry/fhc-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jakefile.js
66 lines (60 loc) · 1.97 KB
/
jakefile.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
/**
* Build file
**/
var /*nodeunit = require("nodeunit"),*/
sys = require("util"),
fs = require("fs"),
dust = require("dust"),
UNITDIR = "./test",
DUSTDIR = "./client/studio/views/dust",
DUSTWRITE = "./client/js/templates/compiledTemplates.js";
console.log("starting build tasks");
desc("compiling dust templates");
task('ct', [], function () {
//find any .dust files
var compiled = "";
var data = "";
var indentBy = function(times, str) {
var arr = new Array(times + 1);
arr[times] = str;
return arr.join(" ");
};
var handleFile = function(relativePath) {
var absPath = [DUSTDIR].concat(relativePath).join('/'),
stats = fs.statSync(absPath),
fname = relativePath[relativePath.length - 1];
if (stats.isDirectory()) {
relativePath.length && console.log(indentBy(relativePath.length * 2, fname));
fs.readdirSync(absPath).forEach(function(n) { handleFile(relativePath.concat([n])); });
} else if (/.+\.dust$/i.test(fname)) {
console.log(indentBy(relativePath.length * 2, fname));
content = fs.readFileSync(absPath, "UTF-8");
compiled += dust.compile(content, relativePath.join('/').replace(/\.dust$/i, '').toLowerCase());
}
};
console.log(">>> Compiling templates");
handleFile([]);
if (compiled !== "") {
fs.writeFile(DUSTWRITE, compiled, function (err) {
if (err)throw err;
else console.log(">>> Templates compiled");
})
} else {
console.log("no files compiled");
}
});
/*desc("running tests");
task('test', [], function () {
//load tests into array
console.log("testing");
fs.readdir(UNITDIR, function (err, data) {
data.forEach(function (f, i) {
if (f.substr(f.length - 7) === "Test.js") {
nodeunit.reporters.
default.
run(["./test/" + f]);
}
});
});
});
*/