-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSakefile
95 lines (77 loc) · 3.14 KB
/
Sakefile
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
/*globals FileList, CLEAN, CLOBBER, desc, task, directory, write, file, sh, read */
var infuse = require("infuse"),
FS = require("fs"),
Path = require("path"),
infuse = require("infuse"),
examplesDir = "examples"
;
sake.options.synchronous = true;
require("sake/clobber");
desc("Generate the example files.");
task("examples");
FS.readdirSync(examplesDir).forEach(function (name) {
var dirName = Path.join(examplesDir, name),
inputPath = Path.join(dirName, "my-script.js"),
// --define-module argument(s) that are relative to the current
// working directory need to be prefixed with "./" so node can find
// them when required.
modulePath = "./" + Path.join(dirName, "my-defines.js"),
prereqs = new FileList(inputPath, modulePath)
;
if (!Path.existsSync(inputPath)) {
return;
}
// We dump any infusion paths the input file may pull in, so we can add
// them to the list of prerequisites for the file task (if they change,
// rebuild the outputPath)
prereqs.include(
infuse(
inputPath,
{dumpPaths: true}
).split("\n").filter(Boolean)
);
// Generate the four variations of the files: minified, embedded and
// un-minified, and embedded and un-minified.
[ [], ["-E"], ["-N"], ["-E", "-N"] ].forEach(function (args) {
var extMap = {"-E": "embed", "-N": "nomin"},
outputPath = Path.join(dirName, args.reduce(function (t, c) {
return t + "." + extMap[c];
}, "script") + ".js"),
cmd = ["infuse", inputPath, outputPath, "-d", modulePath]
;
CLEAN.include(outputPath);
cmd = cmd.concat.apply(cmd, args);
file(outputPath, prereqs, function (t) { sh(cmd.join(" ")); });
task("examples", [outputPath]);
});
});
directory("examples/directories/output");
task("directories-example", ["examples/directories/output"], function (t) {
sh("infuse examples/directories/ examples/directories/output/ -N -L ~/Sources/node/lib");
});
task("directories-example", function (t) {
sh("infuse examples/directories/ examples/directories/output/directories.js -N -L ~/Sources/node/lib");
});
CLEAN.include("examples/directories/output/*");
CLOBBER.include("examples/directories/output");
task("dir-examples", ["directories-example"]);
desc("Generate the README.md documentation");
file("README.md", ["README.tmpl", "package.json", "Sakefile", "lib/options.js"], function (t) {
var _ = require("underscore"),
pkgInfo = JSON.parse(read("package.json", "utf8")),
tmpl = _.template(read(t.prerequisites[0], "utf8")),
tmplParams = {
pkg: pkgInfo,
license: FS.readFileSync("./LICENSE", "utf8"),
usage: ""
}
;
sh("./bin/infuse -h", function (err, txt) {
tmplParams.usage = txt.split("\n").slice(1, -2).join("\n");
write(t.name, tmpl(tmplParams), "utf8");
log.info(t.name + " generated.");
});
});
CLEAN.include("README.md");
task("build", ["README.md"]);
task("default", ["build"]);