/
generate.js
61 lines (53 loc) · 1.69 KB
/
generate.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
var smith = require("../blacksmith"),
winston = require("winston"),
fs = require("fs"),
colors = require("colors"),
path = require("path");
module.exports = function () {
winston.info("Executing command "+"generate".yellow);
// Check to see if the required directories exist.
var exists = {};
[ "./pages", "./authors", "./theme" ].forEach(function(dir) {
exists[dir] = path.existsSync(dir)
&& fs.statSync(dir).isDirectory();
});
if (Object.keys(exists).every(function(k) {
return exists[k];
})) {
// TODO: One folder, not two.
smith.generate("./pages", "./public", function (status) {
// Guard against non-number exit status
if (typeof status !== 'number') {
status = 1;
}
// So, instead, let's just print "blacksmith ok" for now,
// and figure out how to do it the "right way" later.
if (status) {
winston.info("Blacksmith".yellow + " not ok".red.bold);
process.exit(status);
} else {
// Because writes are fire-and-forget, we CAN NOT process.exit until they
// are all done.
winston.info("Blacksmith".yellow + " ok".green.bold);
}
});
} else {
winston.error([
"Missing blacksmith site folders: "
+ Object.keys(exists).filter(function(f) {
return !exists[f];
}).join(", ").bold.yellow,
].join("\n"));
[
"",
"The easiest way to start a " + "blacksmith".yellow
+ " site is to use " + "jitsu".cyan + ":",
"",
" jitsu install blog".yellow,
"",
"You can learn more about jitsu at "
+ "http://github.com/nodejitsu/jitsu".yellow,
""
].forEach(winston.info);
}
};