-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
46 lines (42 loc) · 1.12 KB
/
main.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
"use strict";
var path = require("path"),
util = require("util"),
async = require("async"),
fs = require("fs-extra"),
formatter = require("./formatter"),
reader = require("./reader.js"),
reporter = require("./reporter"),
initialiser = require("./initialiser.js"),
outputter = require("./outputter"),
phantomWrapper = require("./wrappers/phantom-wrapper.js"),
pathToTmp,
modulesToCleanup = [
phantomWrapper
];
function cleanup(callback) {
phantomWrapper.cleanup(callback);
}
function fail(msg) {
cleanup(function () {
throw new Error(msg);
});
}
exports.compile = function (filename, optionsFromCli, callback) {
async.waterfall([
async.apply(reporter.log, "Setting up..."),
async.apply(initialiser.run, filename, optionsFromCli),
async.apply(reporter.log, "Reading markdown files..."),
async.apply(reader.read),
formatter.run,
outputter.run
], function (err) {
if (callback) {
callback(err);
} else if (err) {
fail(err);
} else {
reporter.log("Book generated successfully!");
phantomWrapper.cleanup(function () { return; });
}
});
};