-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSakefile.js
127 lines (115 loc) · 4.13 KB
/
Sakefile.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*globals desc, task, taskSync, file, directory, fileSync, FileList, CLOBBER, CLEAN, spit, slurp, log, sh */
var Path = require("path"),
FS = require("fs"),
authorInfo = read("AUTHORS", "utf8").split("\n")[0],
buildStart = new Date(),
readMeFiles = new FileList(),
buildComplete
;
//---------------------------------------------------------------------------
// Defines the CLEAN file-list and the 'clean' task
//---------------------------------------------------------------------------
require("sake/clean");
//---------------------------------------------------------------------------
// Overall build tasks
//---------------------------------------------------------------------------
taskSync("pre-build", function (t) {
log.info("Starting build at " + buildStart);
});
taskSync("build", ["pre-build"], function (t) {
var delta;
buildComplete = new Date();
delta = buildComplete.getTime() - buildStart.getTime();
log.info("Build complete at " + buildComplete);
log.info(delta + " ms");
});
//---------------------------------------------------------------------------
// LICENSE
//---------------------------------------------------------------------------
if (((new Date()).getFullYear() < FS.statSync("LICENSE").mtime.getFullYear()) ||
(FS.statSync("AUTHORS").mtime.getTime() > FS.statSync("LICENSE").mtime.getTime())
) {
desc("Keep the LICENSE file up-to-date.");
fileSync("LICENSE", function (t) {
var year = new Date().getFullYear(),
license = read(t.name, "utf8").split("\n")
;
license[0] = "Copyright (c) " + year + " " + authorInfo;
write(t.name, license.join("\n"), "utf8");
log.info(t.name + " updated");
});
}
//---------------------------------------------------------------------------
// README file
//---------------------------------------------------------------------------
readMeFiles.include(
"README.tmpl", "package.json", "node_modules/sake/options.js",
"LICENSE", "AUTHORS", "Sakefile.*"
);
desc("Generate the README.md documentation");
file("README.md", readMeFiles, function (t) {
var ejs = require("ejs"),
pkgInfo = JSON.parse(slurp("package.json", "utf8")),
tmpl = ejs.compile(slurp(t.prerequisites[0], "utf8")),
tmplParams = {
pkg: pkgInfo,
license: slurp("./LICENSE", "utf8"),
usage: ""
}
;
sh("./bin/sake -h", function (err, txt) {
tmplParams.usage = txt.split("\n").slice(1, -2).join("\n");
spit(t.name, tmpl(tmplParams), "utf8");
log.info("Update " + t.name);
t.done();
});
});
CLEAN.include("README.md");
//---------------------------------------------------------------------------
// Tests
//---------------------------------------------------------------------------
namespace("test", function () {
desc("Run the mocha test suites and display the results.");
task("default", function (t) {
sh("npm test", function (err, result) {
log(result);
t.done();
});
});
task("sh-chain", function (t) {
sh(
[
"ls -a",
"curl 'http://hamletink.com/'",
"cat README.md"
],
function (err, result) {
// log(result.join("\n"));
t.done();
}
);
});
task("sh-chain-fail", function (t) {
sh(
[
"ls -a",
"cat lib/**/*.js", // should fail here
"curl 'http://hamletink.com/'",
"cat README.md"
],
function (err, result) {
if (err) {
log.error(result.replace(/\n$/, ""));
}
t.done();
}
);
});
task("sh", ["sh-chain", "sh-chain-fail"]);
});
task("test", ["test:default"]);
//---------------------------------------------------------------------------
// link up
//---------------------------------------------------------------------------
task("build", ["LICENSE", "README.md"]);
task("default", ["build"]);