docgen-tool 3.2.14 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docgen/docgen.js +509 -428
- package/dist/docgen/fs/fs.js +178 -0
- package/dist/docgen.js +10 -8
- package/package.json +10 -11
package/dist/docgen/docgen.js
CHANGED
|
@@ -1,28 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
2
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
42
|
+
exports.DocGen = void 0;
|
|
43
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
var path_1 = __importDefault(require("path"));
|
|
45
|
+
var cheerio_1 = __importDefault(require("cheerio"));
|
|
46
|
+
var moment_1 = __importDefault(require("moment"));
|
|
47
|
+
var z_schema_1 = __importDefault(require("z-schema"));
|
|
9
48
|
var child_process_1 = require("child_process");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
49
|
+
var spawn_args_1 = __importDefault(require("spawn-args"));
|
|
50
|
+
var markdown_it_1 = __importDefault(require("markdown-it"));
|
|
51
|
+
var image_size_1 = __importDefault(require("image-size"));
|
|
52
|
+
var cli_spinner_1 = require("cli-spinner");
|
|
53
|
+
var fs_1 = require("./fs/fs");
|
|
15
54
|
var package_json_1 = require("../../package.json");
|
|
55
|
+
var markdown = new markdown_it_1.default('commonmark').enable('table');
|
|
16
56
|
//Allow CommonMark links that use other protocols, such as file:///
|
|
17
57
|
//The markdown-it implementation is more restrictive than the CommonMark spec
|
|
18
58
|
//See https://github.com/markdown-it/markdown-it/issues/108
|
|
19
59
|
markdown.validateLink = function () {
|
|
20
60
|
return true;
|
|
21
61
|
};
|
|
22
|
-
/**
|
|
23
|
-
* DocGen class
|
|
24
|
-
*/
|
|
25
62
|
function DocGen(process) {
|
|
63
|
+
var _this = this;
|
|
26
64
|
var mainProcess = process;
|
|
27
65
|
var wkhtmltopdfVersion = 'wkhtmltopdf 0.12.6 (with patched qt)'; //output from wkhtmltopdf -V
|
|
28
66
|
var options;
|
|
@@ -37,150 +75,102 @@ function DocGen(process) {
|
|
|
37
75
|
options = userOptions;
|
|
38
76
|
//all user-specified paths must be normalized
|
|
39
77
|
if (options.input) {
|
|
40
|
-
options.input =
|
|
78
|
+
options.input = path_1.default.normalize(options.input + '/');
|
|
41
79
|
}
|
|
42
80
|
if (options.output) {
|
|
43
|
-
options.output =
|
|
81
|
+
options.output = path_1.default.normalize(options.output + '/');
|
|
44
82
|
}
|
|
45
83
|
//wkhtmltopdf path does not need a trailing slash
|
|
46
84
|
if (options.wkhtmltopdfPath && options.wkhtmltopdfPath !== '') {
|
|
47
|
-
options.wkhtmltopdfPath =
|
|
85
|
+
options.wkhtmltopdfPath = path_1.default.normalize(options.wkhtmltopdfPath);
|
|
48
86
|
}
|
|
49
87
|
};
|
|
50
88
|
/*
|
|
51
89
|
copy the example src files (template) to any directory, when scaffold command is invoked
|
|
52
90
|
*/
|
|
53
|
-
this.scaffold = function () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
/*
|
|
64
|
-
read any file (async)
|
|
65
|
-
*/
|
|
66
|
-
var readFile = function (filePath) {
|
|
67
|
-
var normalized = path.normalize(filePath);
|
|
68
|
-
return new rsvp.Promise(function (resolve, reject) {
|
|
69
|
-
fs.readFile(normalized, 'utf8', function (error, data) {
|
|
70
|
-
if (error) {
|
|
71
|
-
console.log(chalk.red('Error reading file: ' + normalized));
|
|
72
|
-
reject(error);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
data = data.replace(/^\uFEFF/, ''); //remove the BOM (byte-order-mark) from UTF-8 files, if present
|
|
76
|
-
resolve(data);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
/*
|
|
82
|
-
write any file (async)
|
|
83
|
-
*/
|
|
84
|
-
var writeFile = function (filePath, data) {
|
|
85
|
-
var normalized = path.normalize(filePath);
|
|
86
|
-
return new rsvp.Promise(function (resolve, reject) {
|
|
87
|
-
fs.writeFile(normalized, data, function (error) {
|
|
88
|
-
if (error) {
|
|
89
|
-
console.log(chalk.red('Error writing file: ' + normalized));
|
|
90
|
-
reject(error);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
resolve(true);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
/*
|
|
99
|
-
copy any directory (sync)
|
|
100
|
-
*/
|
|
101
|
-
var copyDirSync = function (source, destination) {
|
|
102
|
-
var normalizedSource = path.normalize(source);
|
|
103
|
-
var normalizedDestination = path.normalize(destination);
|
|
104
|
-
try {
|
|
105
|
-
fs.copySync(normalizedSource, normalizedDestination);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
console.log(chalk.red('Error copying directory: ' +
|
|
109
|
-
normalizedSource +
|
|
110
|
-
' to ' +
|
|
111
|
-
normalizedDestination));
|
|
112
|
-
if (options.verbose === true) {
|
|
113
|
-
console.log(chalk.red(error));
|
|
114
|
-
mainProcess.exit(1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
/*
|
|
119
|
-
remake a directory (sync) ... remove and then mkdir in one operation
|
|
120
|
-
*/
|
|
121
|
-
var remakeDirSync = function (directoryPath) {
|
|
122
|
-
var normalized = path.normalize(directoryPath);
|
|
123
|
-
try {
|
|
124
|
-
fs.removeSync(normalized);
|
|
125
|
-
fs.mkdirpSync(normalized);
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.log(chalk.red('Error recreating directory: ' + normalized));
|
|
129
|
-
if (options.verbose === true) {
|
|
130
|
-
console.log(chalk.red(error));
|
|
131
|
-
mainProcess.exit(1);
|
|
91
|
+
this.scaffold = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
+
return __generator(this, function (_a) {
|
|
93
|
+
switch (_a.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
console.log(chalk_1.default.green('Creating scaffold template directory'));
|
|
96
|
+
return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/example', options.output, options.verbose === true)];
|
|
97
|
+
case 1:
|
|
98
|
+
_a.sent();
|
|
99
|
+
return [2 /*return*/];
|
|
132
100
|
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
mainProcess.exit(1);
|
|
101
|
+
});
|
|
102
|
+
}); };
|
|
103
|
+
this.run = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
104
|
+
return __generator(this, function (_a) {
|
|
105
|
+
switch (_a.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
console.log(chalk_1.default.green.bold('DocGen version ' + package_json_1.version));
|
|
108
|
+
//delete and recreate the output directory
|
|
109
|
+
return [4 /*yield*/, (0, fs_1.cleanDirectory)(options.output)];
|
|
110
|
+
case 1:
|
|
111
|
+
//delete and recreate the output directory
|
|
112
|
+
_a.sent();
|
|
113
|
+
loadTemplates();
|
|
114
|
+
return [2 /*return*/];
|
|
148
115
|
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
116
|
+
});
|
|
117
|
+
}); };
|
|
151
118
|
/*
|
|
152
119
|
load all HTML template files
|
|
153
120
|
*/
|
|
154
|
-
var loadTemplates = function () {
|
|
155
|
-
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
121
|
+
var loadTemplates = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
122
|
+
var files, key, file, dom, error_1;
|
|
123
|
+
var _a;
|
|
124
|
+
return __generator(this, function (_b) {
|
|
125
|
+
switch (_b.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
console.log(chalk_1.default.green('Loading templates'));
|
|
128
|
+
_b.label = 1;
|
|
129
|
+
case 1:
|
|
130
|
+
_b.trys.push([1, 8, , 9]);
|
|
131
|
+
_a = {};
|
|
132
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/main.html')];
|
|
133
|
+
case 2:
|
|
134
|
+
_a.main = _b.sent();
|
|
135
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/redirect.html')];
|
|
136
|
+
case 3:
|
|
137
|
+
_a.redirect = _b.sent();
|
|
138
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/webCover.html')];
|
|
139
|
+
case 4:
|
|
140
|
+
_a.webCover = _b.sent();
|
|
141
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfCover.html')];
|
|
142
|
+
case 5:
|
|
143
|
+
_a.pdfCover = _b.sent();
|
|
144
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfHeader.html')];
|
|
145
|
+
case 6:
|
|
146
|
+
_a.pdfHeader = _b.sent();
|
|
147
|
+
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfFooter.html')];
|
|
148
|
+
case 7:
|
|
149
|
+
files = (_a.pdfFooter = _b.sent(),
|
|
150
|
+
_a);
|
|
151
|
+
for (key in files) {
|
|
152
|
+
if (files.hasOwnProperty(key)) {
|
|
153
|
+
file = files[key];
|
|
154
|
+
dom = cheerio_1.default.load(file);
|
|
155
|
+
templates[key] = dom;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return [3 /*break*/, 9];
|
|
159
|
+
case 8:
|
|
160
|
+
error_1 = _b.sent();
|
|
161
|
+
console.log(chalk_1.default.red('Error loading templates'));
|
|
162
|
+
if (options.verbose === true) {
|
|
163
|
+
console.log(chalk_1.default.red(error_1));
|
|
164
|
+
}
|
|
165
|
+
mainProcess.exit(1);
|
|
166
|
+
return [3 /*break*/, 9];
|
|
167
|
+
case 9: return [4 /*yield*/, loadMeta()];
|
|
168
|
+
case 10:
|
|
169
|
+
_b.sent();
|
|
170
|
+
return [2 /*return*/];
|
|
180
171
|
}
|
|
181
|
-
mainProcess.exit(1);
|
|
182
172
|
});
|
|
183
|
-
};
|
|
173
|
+
}); };
|
|
184
174
|
/*
|
|
185
175
|
JSON schema validation
|
|
186
176
|
*/
|
|
@@ -315,14 +305,14 @@ function DocGen(process) {
|
|
|
315
305
|
};
|
|
316
306
|
var validateJSON = function (key, data) {
|
|
317
307
|
var schema = schemas[key];
|
|
318
|
-
var validator = new
|
|
308
|
+
var validator = new z_schema_1.default();
|
|
319
309
|
var valid = validator.validate(data, schema);
|
|
320
310
|
if (!valid) {
|
|
321
|
-
console.log(
|
|
311
|
+
console.log(chalk_1.default.red('Error parsing required file: ' +
|
|
322
312
|
key +
|
|
323
313
|
'.json (failed schema validation)'));
|
|
324
314
|
if (options.verbose === true) {
|
|
325
|
-
console.log(
|
|
315
|
+
console.log(chalk_1.default.red(validator.getLastError()));
|
|
326
316
|
}
|
|
327
317
|
}
|
|
328
318
|
return valid;
|
|
@@ -330,106 +320,131 @@ function DocGen(process) {
|
|
|
330
320
|
/*
|
|
331
321
|
load all metadata files (JSON)
|
|
332
322
|
*/
|
|
333
|
-
var loadMeta = function () {
|
|
334
|
-
|
|
335
|
-
var
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
323
|
+
var loadMeta = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
324
|
+
var files, key, file, extra, error_2;
|
|
325
|
+
var _a;
|
|
326
|
+
return __generator(this, function (_b) {
|
|
327
|
+
switch (_b.label) {
|
|
328
|
+
case 0:
|
|
329
|
+
console.log(chalk_1.default.green('Loading required JSON metadata files'));
|
|
330
|
+
_b.label = 1;
|
|
331
|
+
case 1:
|
|
332
|
+
_b.trys.push([1, 4, , 5]);
|
|
333
|
+
_a = {};
|
|
334
|
+
return [4 /*yield*/, (0, fs_1.readFile)(options.input + '/parameters.json')];
|
|
335
|
+
case 2:
|
|
336
|
+
_a.parameters = _b.sent();
|
|
337
|
+
return [4 /*yield*/, (0, fs_1.readFile)(options.input + '/contents.json')];
|
|
338
|
+
case 3:
|
|
339
|
+
files = (_a.contents = _b.sent(),
|
|
340
|
+
_a);
|
|
341
|
+
for (key in files) {
|
|
342
|
+
if (files.hasOwnProperty(key)) {
|
|
343
|
+
//ignore prototype
|
|
344
|
+
try {
|
|
345
|
+
file = JSON.parse(files[key]);
|
|
346
|
+
if (validateJSON(key, file)) {
|
|
347
|
+
meta[key] = file;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
mainProcess.exit(1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
console.log(chalk_1.default.red('Error parsing required file: ' + key + '.json (invalid JSON)'));
|
|
355
|
+
if (options.verbose === true) {
|
|
356
|
+
console.log(chalk_1.default.red(error));
|
|
357
|
+
}
|
|
358
|
+
mainProcess.exit(1);
|
|
359
|
+
}
|
|
352
360
|
}
|
|
353
361
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
+
extra = {
|
|
363
|
+
heading: 'Extra',
|
|
364
|
+
column: 5,
|
|
365
|
+
pages: [{ title: 'Release notes', source: 'release-notes.md' }],
|
|
366
|
+
};
|
|
367
|
+
meta.contents.push(extra);
|
|
368
|
+
return [3 /*break*/, 5];
|
|
369
|
+
case 4:
|
|
370
|
+
error_2 = _b.sent();
|
|
371
|
+
console.log(chalk_1.default.red('Error loading required JSON metadata files'));
|
|
372
|
+
if (options.verbose === true) {
|
|
373
|
+
console.log(chalk_1.default.red(error_2));
|
|
362
374
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
pages: [{ title: 'Release notes', source: 'release-notes.md' }],
|
|
370
|
-
};
|
|
371
|
-
meta.contents.push(extra);
|
|
372
|
-
loadMarkdown();
|
|
373
|
-
})
|
|
374
|
-
.catch(function (error) {
|
|
375
|
-
console.log(chalk.red('Error loading required JSON metadata files'));
|
|
376
|
-
if (options.verbose === true) {
|
|
377
|
-
console.log(chalk.red(error));
|
|
375
|
+
mainProcess.exit(1);
|
|
376
|
+
return [3 /*break*/, 5];
|
|
377
|
+
case 5: return [4 /*yield*/, loadMarkdown()];
|
|
378
|
+
case 6:
|
|
379
|
+
_b.sent();
|
|
380
|
+
return [2 /*return*/];
|
|
378
381
|
}
|
|
379
|
-
mainProcess.exit(1);
|
|
380
382
|
});
|
|
381
|
-
};
|
|
383
|
+
}); };
|
|
382
384
|
/*
|
|
383
385
|
load all markdown files (src)
|
|
384
386
|
*/
|
|
385
|
-
var loadMarkdown = function () {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
387
|
+
var loadMarkdown = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
388
|
+
var keys_1, files_1, error_3;
|
|
389
|
+
return __generator(this, function (_a) {
|
|
390
|
+
switch (_a.label) {
|
|
391
|
+
case 0:
|
|
392
|
+
console.log(chalk_1.default.green('Loading src files'));
|
|
393
|
+
_a.label = 1;
|
|
394
|
+
case 1:
|
|
395
|
+
_a.trys.push([1, 3, , 4]);
|
|
396
|
+
keys_1 = [];
|
|
397
|
+
files_1 = [];
|
|
398
|
+
meta.contents.forEach(function (section) {
|
|
399
|
+
section.pages.forEach(function (page) {
|
|
400
|
+
keys_1.push(page);
|
|
401
|
+
files_1.push(options.input + '/' + page.source);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
//add the release notes page
|
|
405
|
+
keys_1.push('ownership');
|
|
406
|
+
files_1.push(options.input + '/release-notes.md');
|
|
407
|
+
return [4 /*yield*/, Promise.all(files_1.map(function (f) { return (0, fs_1.readFile)(f); }))];
|
|
408
|
+
case 2:
|
|
409
|
+
files_1 = _a.sent();
|
|
410
|
+
files_1.forEach(function (page, index) {
|
|
411
|
+
try {
|
|
412
|
+
var key = keys_1[index];
|
|
413
|
+
if (key.html === true) {
|
|
414
|
+
//allow raw HTML input pages
|
|
415
|
+
pages[key.source] = page;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
//otherwise parse input from Markdown into HTML
|
|
419
|
+
var html = markdown.render(page);
|
|
420
|
+
pages[key.source] = html;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
console.log(chalk_1.default.red('Error parsing Markdown file: ' + file.source));
|
|
425
|
+
if (options.verbose === true) {
|
|
426
|
+
console.log(chalk_1.default.red(error));
|
|
427
|
+
}
|
|
428
|
+
mainProcess.exit(1);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return [3 /*break*/, 4];
|
|
432
|
+
case 3:
|
|
433
|
+
error_3 = _a.sent();
|
|
434
|
+
console.log(error_3);
|
|
435
|
+
console.log(chalk_1.default.red('Error loading src files'));
|
|
416
436
|
if (options.verbose === true) {
|
|
417
|
-
console.log(
|
|
437
|
+
console.log(chalk_1.default.red(error_3));
|
|
418
438
|
}
|
|
419
439
|
mainProcess.exit(1);
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
console.log(error);
|
|
426
|
-
console.log(chalk.red('Error loading src files'));
|
|
427
|
-
if (options.verbose === true) {
|
|
428
|
-
console.log(chalk.red(error));
|
|
440
|
+
return [3 /*break*/, 4];
|
|
441
|
+
case 4: return [4 /*yield*/, processContent()];
|
|
442
|
+
case 5:
|
|
443
|
+
_a.sent();
|
|
444
|
+
return [2 /*return*/];
|
|
429
445
|
}
|
|
430
|
-
mainProcess.exit(1);
|
|
431
446
|
});
|
|
432
|
-
};
|
|
447
|
+
}); };
|
|
433
448
|
var sortPages = function () {
|
|
434
449
|
//sort the contents by heading
|
|
435
450
|
var headings = { 1: [], 2: [], 3: [], 4: [], 5: [] };
|
|
@@ -502,7 +517,7 @@ function DocGen(process) {
|
|
|
502
517
|
var logoPath;
|
|
503
518
|
try {
|
|
504
519
|
logoPath = 'files/images/logo.svg';
|
|
505
|
-
var logo =
|
|
520
|
+
var logo = (0, image_size_1.default)("".concat(options.input, "/").concat(logoPath));
|
|
506
521
|
logoWidth = logo.width;
|
|
507
522
|
logoHeight = logo.height;
|
|
508
523
|
hasLogo = true;
|
|
@@ -514,7 +529,7 @@ function DocGen(process) {
|
|
|
514
529
|
//PNG fallback
|
|
515
530
|
try {
|
|
516
531
|
logoPath = 'files/images/logo.png';
|
|
517
|
-
var logo =
|
|
532
|
+
var logo = (0, image_size_1.default)("".concat(options.input, "/").concat(logoPath));
|
|
518
533
|
logoWidth = logo.width;
|
|
519
534
|
logoHeight = logo.height;
|
|
520
535
|
hasLogo = true;
|
|
@@ -528,9 +543,9 @@ function DocGen(process) {
|
|
|
528
543
|
var homelink = meta.contents[0].pages[0];
|
|
529
544
|
homelink =
|
|
530
545
|
homelink.source.substr(0, homelink.source.lastIndexOf('.')) + '.html';
|
|
531
|
-
var date =
|
|
532
|
-
var time =
|
|
533
|
-
var year =
|
|
546
|
+
var date = (0, moment_1.default)().format('DD/MM/YYYY');
|
|
547
|
+
var time = (0, moment_1.default)().format('HH:mm:ss');
|
|
548
|
+
var year = (0, moment_1.default)().format('YYYY');
|
|
534
549
|
var attribution = 'Created by DocGen ' + package_json_1.version + ' on ' + date + ' at ' + time + '.';
|
|
535
550
|
var releaseVersion = meta.parameters.version;
|
|
536
551
|
if (options.setVersion !== false) {
|
|
@@ -672,107 +687,133 @@ function DocGen(process) {
|
|
|
672
687
|
/*
|
|
673
688
|
process each input into an output
|
|
674
689
|
*/
|
|
675
|
-
var processContent = function () {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
690
|
+
var processContent = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
691
|
+
var $;
|
|
692
|
+
return __generator(this, function (_a) {
|
|
693
|
+
switch (_a.label) {
|
|
694
|
+
case 0:
|
|
695
|
+
console.log(chalk_1.default.green('Generating the static web content'));
|
|
696
|
+
webToc();
|
|
697
|
+
insertParameters();
|
|
698
|
+
meta.contents.forEach(function (section) {
|
|
699
|
+
section.pages.forEach(function (page) {
|
|
700
|
+
var $ = cheerio_1.default.load(templates.main.html()); //clone
|
|
701
|
+
var key = page.source;
|
|
702
|
+
var content = pages[key];
|
|
703
|
+
//add relevant container
|
|
704
|
+
if (page.html === true) {
|
|
705
|
+
//raw HTML pages should not be confined to the fixed width
|
|
706
|
+
$('#dg-content').html('<div id="dg-innerContent"></div>');
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
//Markdown pages should be confined to the fixed width
|
|
710
|
+
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
711
|
+
}
|
|
712
|
+
$('#dg-innerContent').html(content);
|
|
713
|
+
//------------------------------------------------------------------------------------------------------
|
|
714
|
+
//insert permalinks for every page heading
|
|
715
|
+
//when pageToc is enabled, also insert a page-level table of contents
|
|
716
|
+
var html = [], i = -1;
|
|
717
|
+
var headings = $('h1, h2, h3, h4, h5, h6');
|
|
718
|
+
if (headings.length > 0) {
|
|
719
|
+
html[++i] = '<ul class="dg-pageToc">';
|
|
720
|
+
}
|
|
721
|
+
headings.each(function () {
|
|
722
|
+
var label = $(this).text();
|
|
723
|
+
var anchor = label.toLowerCase().replace(/\s+/g, '-');
|
|
724
|
+
$(this).attr('id', anchor);
|
|
725
|
+
html[++i] = '<li><a href="#' + anchor + '">' + label + '</a></li>';
|
|
726
|
+
});
|
|
727
|
+
if (headings.length > 0) {
|
|
728
|
+
html[++i] = '</ul>';
|
|
729
|
+
}
|
|
730
|
+
if (options.pageToc === true && page.html !== true) {
|
|
731
|
+
$('#dg-innerContent').prepend(html.join(''));
|
|
732
|
+
}
|
|
733
|
+
//------------------------------------------------------------------------------------------------------
|
|
734
|
+
//prepend the auto heading (which makes the PDF table of contents match the web TOC)
|
|
735
|
+
$('#dg-innerContent').prepend('<h1 id="dg-autoTitle">' + page.title + '</h1>');
|
|
736
|
+
if (page.html === true) {
|
|
737
|
+
$('#dg-autoTitle').addClass('dg-hiddenTitle');
|
|
738
|
+
}
|
|
739
|
+
//------------------------------------------------------------------------------------------------------
|
|
740
|
+
//apply the w-table class
|
|
741
|
+
$('table:not(.unstyled)').addClass('w-table w-fixed w-stripe');
|
|
742
|
+
//------------------------------------------------------------------------------------------------------
|
|
743
|
+
pages[key] = $;
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
$ = cheerio_1.default.load(templates.main.html());
|
|
691
747
|
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (headings.length > 0) {
|
|
700
|
-
html[++i] = '<ul class="dg-pageToc">';
|
|
701
|
-
}
|
|
702
|
-
headings.each(function () {
|
|
703
|
-
var label = $(this).text();
|
|
704
|
-
var anchor = label.toLowerCase().replace(/\s+/g, '-');
|
|
705
|
-
$(this).attr('id', anchor);
|
|
706
|
-
html[++i] = '<li><a href="#' + anchor + '">' + label + '</a></li>';
|
|
707
|
-
});
|
|
708
|
-
if (headings.length > 0) {
|
|
709
|
-
html[++i] = '</ul>';
|
|
710
|
-
}
|
|
711
|
-
if (options.pageToc === true && page.html !== true) {
|
|
712
|
-
$('#dg-innerContent').prepend(html.join(''));
|
|
713
|
-
}
|
|
714
|
-
//------------------------------------------------------------------------------------------------------
|
|
715
|
-
//prepend the auto heading (which makes the PDF table of contents match the web TOC)
|
|
716
|
-
$('#dg-innerContent').prepend('<h1 id="dg-autoTitle">' + page.title + '</h1>');
|
|
717
|
-
if (page.html === true) {
|
|
718
|
-
$('#dg-autoTitle').addClass('dg-hiddenTitle');
|
|
719
|
-
}
|
|
720
|
-
//------------------------------------------------------------------------------------------------------
|
|
721
|
-
//apply the w-table class
|
|
722
|
-
$('table:not(.unstyled)').addClass('w-table w-fixed w-stripe');
|
|
723
|
-
//------------------------------------------------------------------------------------------------------
|
|
724
|
-
pages[key] = $;
|
|
725
|
-
});
|
|
748
|
+
$('#dg-innerContent').html(templates.webCover.html());
|
|
749
|
+
templates.webCover = $;
|
|
750
|
+
return [4 /*yield*/, writePages()];
|
|
751
|
+
case 1:
|
|
752
|
+
_a.sent();
|
|
753
|
+
return [2 /*return*/];
|
|
754
|
+
}
|
|
726
755
|
});
|
|
727
|
-
|
|
728
|
-
var $ = cheerio.load(templates.main.html()); //clone
|
|
729
|
-
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
730
|
-
$('#dg-innerContent').html(templates.webCover.html());
|
|
731
|
-
templates.webCover = $;
|
|
732
|
-
writePages();
|
|
733
|
-
};
|
|
756
|
+
}); };
|
|
734
757
|
/*
|
|
735
758
|
write each html page
|
|
736
759
|
*/
|
|
737
|
-
var writePages = function () {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
760
|
+
var writePages = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
761
|
+
var promises_1, pdfTempDir, error_4;
|
|
762
|
+
return __generator(this, function (_a) {
|
|
763
|
+
switch (_a.label) {
|
|
764
|
+
case 0:
|
|
765
|
+
console.log(chalk_1.default.green('Writing the web page files'));
|
|
766
|
+
_a.label = 1;
|
|
767
|
+
case 1:
|
|
768
|
+
_a.trys.push([1, 8, , 9]);
|
|
769
|
+
promises_1 = {};
|
|
770
|
+
meta.contents.forEach(function (section) {
|
|
771
|
+
section.pages.forEach(function (page) {
|
|
772
|
+
var key = page.source;
|
|
773
|
+
var name = key.substr(0, page.source.lastIndexOf('.'));
|
|
774
|
+
var path = options.output + name + '.html';
|
|
775
|
+
var html = pages[key].html();
|
|
776
|
+
promises_1[key] = (0, fs_1.writeFile)(path, html);
|
|
777
|
+
});
|
|
778
|
+
});
|
|
779
|
+
//add extra files
|
|
780
|
+
promises_1['ownership'] = (0, fs_1.writeFile)(options.output + 'ownership.html', templates.webCover.html());
|
|
781
|
+
if (!(options.pdf === true)) return [3 /*break*/, 3];
|
|
782
|
+
pdfTempDir = options.output + 'temp/';
|
|
783
|
+
return [4 /*yield*/, (0, fs_1.makeDirectory)(pdfTempDir)];
|
|
784
|
+
case 2:
|
|
785
|
+
_a.sent();
|
|
786
|
+
promises_1['docgenPdfCover'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfCover.html', templates.pdfCover.html());
|
|
787
|
+
promises_1['docgenPdfHeader'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfHeader.html', templates.pdfHeader.html());
|
|
788
|
+
promises_1['docgenPdfFooter'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfFooter.html', templates.pdfFooter.html());
|
|
789
|
+
_a.label = 3;
|
|
790
|
+
case 3: return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/require', options.output + 'require', options.verbose === true)];
|
|
791
|
+
case 4:
|
|
792
|
+
_a.sent(); //CSS, JavaScript
|
|
793
|
+
return [4 /*yield*/, (0, fs_1.copyDirectory)(options.input + '/files', options.output + 'files', options.verbose === true)];
|
|
794
|
+
case 5:
|
|
795
|
+
_a.sent(); //user-attached files and images
|
|
796
|
+
if (!(options.mathKatex === true)) return [3 /*break*/, 7];
|
|
797
|
+
return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/optional/katex', options.output + 'require/katex', options.verbose === true)];
|
|
798
|
+
case 6:
|
|
799
|
+
_a.sent();
|
|
800
|
+
_a.label = 7;
|
|
801
|
+
case 7: return [3 /*break*/, 9];
|
|
802
|
+
case 8:
|
|
803
|
+
error_4 = _a.sent();
|
|
804
|
+
console.log(chalk_1.default.red('Error writing the web page files'));
|
|
805
|
+
if (options.verbose === true) {
|
|
806
|
+
console.log(chalk_1.default.red(error_4));
|
|
807
|
+
}
|
|
808
|
+
mainProcess.exit(1);
|
|
809
|
+
return [3 /*break*/, 9];
|
|
810
|
+
case 9: return [4 /*yield*/, checkPdfVersion()];
|
|
811
|
+
case 10:
|
|
812
|
+
_a.sent();
|
|
813
|
+
return [2 /*return*/];
|
|
772
814
|
}
|
|
773
|
-
mainProcess.exit(1);
|
|
774
815
|
});
|
|
775
|
-
};
|
|
816
|
+
}); };
|
|
776
817
|
/*
|
|
777
818
|
wkthmltopdf options
|
|
778
819
|
*/
|
|
@@ -815,114 +856,154 @@ function DocGen(process) {
|
|
|
815
856
|
var args = pdfOptions.join('');
|
|
816
857
|
args += allPages;
|
|
817
858
|
args += ' ' + options.output + pdfName;
|
|
818
|
-
return
|
|
819
|
-
};
|
|
820
|
-
var checkPdfVersion = function () {
|
|
821
|
-
if (options.pdf === true) {
|
|
822
|
-
//first check that wkhtmltopdf is installed
|
|
823
|
-
(0, child_process_1.exec)(options.wkhtmltopdfPath + ' -V', function (error, stdout, stderr) {
|
|
824
|
-
if (error) {
|
|
825
|
-
console.log(chalk.red('Unable to call wkhtmltopdf. Is it installed and in path? See http://wkhtmltopdf.org'));
|
|
826
|
-
if (options.verbose === true) {
|
|
827
|
-
console.log(chalk.red(error));
|
|
828
|
-
}
|
|
829
|
-
mainProcess.exit(1);
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
//warn if the version of wkhtmltopdf is not an expected version
|
|
833
|
-
var actualWkhtmltopdfVersion = stdout.trim();
|
|
834
|
-
if (actualWkhtmltopdfVersion !== wkhtmltopdfVersion) {
|
|
835
|
-
var warning = 'Warning: unexpected version of wkhtmltopdf, which may work but is not tested or supported';
|
|
836
|
-
var expectedVersion = ' expected version: ' + wkhtmltopdfVersion;
|
|
837
|
-
var detectedVersion = ' detected version: ' + actualWkhtmltopdfVersion;
|
|
838
|
-
console.log(chalk.yellow(warning));
|
|
839
|
-
console.log(chalk.yellow(expectedVersion));
|
|
840
|
-
console.log(chalk.yellow(detectedVersion));
|
|
841
|
-
}
|
|
842
|
-
generatePdf();
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
cleanUp();
|
|
848
|
-
}
|
|
859
|
+
return (0, spawn_args_1.default)(args);
|
|
849
860
|
};
|
|
861
|
+
var checkPdfVersion = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
862
|
+
return __generator(this, function (_a) {
|
|
863
|
+
switch (_a.label) {
|
|
864
|
+
case 0:
|
|
865
|
+
if (!(options.pdf === true)) return [3 /*break*/, 1];
|
|
866
|
+
//first check that wkhtmltopdf is installed
|
|
867
|
+
(0, child_process_1.exec)(options.wkhtmltopdfPath + ' -V', function (error, stdout, stderr) {
|
|
868
|
+
if (error) {
|
|
869
|
+
console.log(chalk_1.default.red('Unable to call wkhtmltopdf. Is it installed and in path? See http://wkhtmltopdf.org'));
|
|
870
|
+
if (options.verbose === true) {
|
|
871
|
+
console.log(chalk_1.default.red(error));
|
|
872
|
+
}
|
|
873
|
+
mainProcess.exit(1);
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
//warn if the version of wkhtmltopdf is not an expected version
|
|
877
|
+
var actualWkhtmltopdfVersion = stdout.trim();
|
|
878
|
+
if (actualWkhtmltopdfVersion !== wkhtmltopdfVersion) {
|
|
879
|
+
var warning = 'Warning: unexpected version of wkhtmltopdf, which may work but is not tested or supported';
|
|
880
|
+
var expectedVersion = ' expected version: ' + wkhtmltopdfVersion;
|
|
881
|
+
var detectedVersion = ' detected version: ' + actualWkhtmltopdfVersion;
|
|
882
|
+
console.log(chalk_1.default.yellow(warning));
|
|
883
|
+
console.log(chalk_1.default.yellow(expectedVersion));
|
|
884
|
+
console.log(chalk_1.default.yellow(detectedVersion));
|
|
885
|
+
}
|
|
886
|
+
generatePdf();
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
return [3 /*break*/, 3];
|
|
890
|
+
case 1: return [4 /*yield*/, cleanUp()];
|
|
891
|
+
case 2:
|
|
892
|
+
_a.sent();
|
|
893
|
+
_a.label = 3;
|
|
894
|
+
case 3: return [2 /*return*/];
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
}); };
|
|
850
898
|
/*
|
|
851
899
|
call wkhtmltopdf as an external executable
|
|
852
900
|
*/
|
|
853
|
-
var generatePdf = function () {
|
|
854
|
-
|
|
855
|
-
var
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
else {
|
|
869
|
-
//pipe the output from wkhtmltopdf back to stdout
|
|
870
|
-
//however, wkhtmltpdf outputs to stderr, not stdout. See:
|
|
871
|
-
//https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1980
|
|
872
|
-
wkhtmltopdf.stderr.pipe(mainProcess.stdout);
|
|
873
|
-
}
|
|
874
|
-
wkhtmltopdf.stdout.on('data', function (data) {
|
|
875
|
-
//do nothing
|
|
876
|
-
});
|
|
877
|
-
wkhtmltopdf.stderr.on('data', function (data) {
|
|
878
|
-
//do nothing
|
|
879
|
-
});
|
|
880
|
-
wkhtmltopdf.on('close', function (code) {
|
|
901
|
+
var generatePdf = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
902
|
+
var args, wkhtmltopdf, spinner;
|
|
903
|
+
var _this = this;
|
|
904
|
+
return __generator(this, function (_a) {
|
|
905
|
+
console.log(chalk_1.default.green('Creating the PDF copy (may take some time)'));
|
|
906
|
+
args = getPdfArguments();
|
|
907
|
+
wkhtmltopdf = (0, child_process_1.spawn)(options.wkhtmltopdfPath, args);
|
|
908
|
+
spinner = new cli_spinner_1.Spinner(chalk_1.default.green(' Processing... %s'));
|
|
909
|
+
spinner.setSpinnerString('|/-\\');
|
|
910
|
+
wkhtmltopdf.on('error', function (error) {
|
|
911
|
+
console.log(chalk_1.default.red('Error calling wkhtmltopdf to generate the PDF'));
|
|
912
|
+
if (options.verbose === true) {
|
|
913
|
+
console.log(chalk_1.default.red(error));
|
|
914
|
+
}
|
|
915
|
+
});
|
|
881
916
|
if (options.verbose !== true) {
|
|
882
|
-
spinner.
|
|
883
|
-
console.log(''); //newline after spinner stops
|
|
917
|
+
spinner.start(); //only show spinner when verbose is off (otherwise show raw wkhtmltopdf output)
|
|
884
918
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
919
|
+
else {
|
|
920
|
+
//pipe the output from wkhtmltopdf back to stdout
|
|
921
|
+
//however, wkhtmltpdf outputs to stderr, not stdout. See:
|
|
922
|
+
//https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1980
|
|
923
|
+
wkhtmltopdf.stderr.pipe(mainProcess.stdout);
|
|
888
924
|
}
|
|
889
|
-
|
|
925
|
+
wkhtmltopdf.stdout.on('data', function (data) {
|
|
926
|
+
//do nothing
|
|
927
|
+
});
|
|
928
|
+
wkhtmltopdf.stderr.on('data', function (data) {
|
|
929
|
+
//do nothing
|
|
930
|
+
});
|
|
931
|
+
wkhtmltopdf.on('close', function (code) { return __awaiter(_this, void 0, void 0, function () {
|
|
932
|
+
var warning;
|
|
933
|
+
return __generator(this, function (_a) {
|
|
934
|
+
switch (_a.label) {
|
|
935
|
+
case 0:
|
|
936
|
+
if (options.verbose !== true) {
|
|
937
|
+
spinner.stop();
|
|
938
|
+
console.log(''); //newline after spinner stops
|
|
939
|
+
}
|
|
940
|
+
if (code !== 0) {
|
|
941
|
+
warning = 'wkhtmltopdf exited with a warning or error: try the -v option for details';
|
|
942
|
+
console.log(chalk_1.default.yellow(warning));
|
|
943
|
+
}
|
|
944
|
+
return [4 /*yield*/, cleanUp()];
|
|
945
|
+
case 1:
|
|
946
|
+
_a.sent();
|
|
947
|
+
return [2 /*return*/];
|
|
948
|
+
}
|
|
949
|
+
});
|
|
950
|
+
}); });
|
|
951
|
+
return [2 /*return*/];
|
|
890
952
|
});
|
|
891
|
-
};
|
|
892
|
-
var createRedirect = function () {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
953
|
+
}); };
|
|
954
|
+
var createRedirect = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
955
|
+
var parent_1, homepage, redirectLink, $, file, error_5;
|
|
956
|
+
return __generator(this, function (_a) {
|
|
957
|
+
switch (_a.label) {
|
|
958
|
+
case 0:
|
|
959
|
+
if (!options.redirect) return [3 /*break*/, 4];
|
|
960
|
+
parent_1 = options.output.replace(/\/$/, '');
|
|
961
|
+
parent_1 = parent_1.split(path_1.default.sep).slice(-1).pop(); //get name of final directory in the path
|
|
962
|
+
homepage = meta.contents[0].pages[0];
|
|
963
|
+
homepage =
|
|
964
|
+
homepage.source.substr(0, homepage.source.lastIndexOf('.')) + '.html';
|
|
965
|
+
redirectLink = parent_1 + '/' + homepage;
|
|
966
|
+
$ = templates.redirect;
|
|
967
|
+
$('a').attr('href', redirectLink);
|
|
968
|
+
$('meta[http-equiv=REFRESH]').attr('content', '0;url=' + redirectLink);
|
|
969
|
+
file = options.output + '../' + 'index.html';
|
|
970
|
+
_a.label = 1;
|
|
971
|
+
case 1:
|
|
972
|
+
_a.trys.push([1, 3, , 4]);
|
|
973
|
+
return [4 /*yield*/, (0, fs_1.writeFile)(file, $.html())];
|
|
974
|
+
case 2:
|
|
975
|
+
_a.sent();
|
|
976
|
+
return [3 /*break*/, 4];
|
|
977
|
+
case 3:
|
|
978
|
+
error_5 = _a.sent();
|
|
979
|
+
console.log(chalk_1.default.red('Error writing redirect file: ' + file));
|
|
980
|
+
if (options.verbose === true) {
|
|
981
|
+
console.log(chalk_1.default.red(error_5));
|
|
982
|
+
}
|
|
983
|
+
return [3 /*break*/, 4];
|
|
984
|
+
case 4: return [2 /*return*/];
|
|
913
985
|
}
|
|
914
|
-
}
|
|
915
|
-
};
|
|
986
|
+
});
|
|
987
|
+
}); };
|
|
916
988
|
/*
|
|
917
989
|
cleanup
|
|
918
990
|
*/
|
|
919
|
-
var cleanUp = function () {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
991
|
+
var cleanUp = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
992
|
+
return __generator(this, function (_a) {
|
|
993
|
+
switch (_a.label) {
|
|
994
|
+
case 0: return [4 /*yield*/, createRedirect()];
|
|
995
|
+
case 1:
|
|
996
|
+
_a.sent();
|
|
997
|
+
if (!(options.pdf === true)) return [3 /*break*/, 3];
|
|
998
|
+
return [4 /*yield*/, (0, fs_1.removeDirectory)(options.output + 'temp')];
|
|
999
|
+
case 2:
|
|
1000
|
+
_a.sent();
|
|
1001
|
+
_a.label = 3;
|
|
1002
|
+
case 3:
|
|
1003
|
+
console.log(chalk_1.default.green.bold('Done!'));
|
|
1004
|
+
return [2 /*return*/];
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}); };
|
|
927
1008
|
}
|
|
928
|
-
|
|
1009
|
+
exports.DocGen = DocGen;
|