docgen-tool 3.3.0 → 3.4.0
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/package.json +72 -0
- package/dist/src/docgen/docgen.js +198 -0
- package/dist/src/docgen/execute/execute.js +63 -0
- package/dist/src/docgen/fs/markdown.js +115 -0
- package/dist/src/docgen/fs/meta.js +110 -0
- package/dist/src/docgen/fs/templates.js +100 -0
- package/dist/src/docgen/fs/write-pages.js +102 -0
- package/dist/src/docgen/html/process-pages.js +287 -0
- package/dist/src/docgen/html/redirect.js +83 -0
- package/dist/src/docgen/html/web-table-of-contents.js +51 -0
- package/dist/src/docgen/meta/sort-pages.js +15 -0
- package/dist/src/docgen/pdf/wkhtmltopdf/wkhtmltopdf.js +186 -0
- package/dist/src/docgen/scaffold/scaffold.js +60 -0
- package/dist/src/docgen/types.js +2 -0
- package/dist/src/docgen/validation/validation.js +151 -0
- package/package.json +7 -7
- package/dist/docgen/docgen.js +0 -969
- /package/dist/{docgen → src/docgen}/fs/fs.js +0 -0
- /package/dist/{docgen.js → src/docgen.js} +0 -0
package/dist/docgen/docgen.js
DELETED
|
@@ -1,969 +0,0 @@
|
|
|
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
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 rsvp_1 = __importDefault(require("rsvp"));
|
|
47
|
-
var moment_1 = __importDefault(require("moment"));
|
|
48
|
-
var z_schema_1 = __importDefault(require("z-schema"));
|
|
49
|
-
var child_process_1 = require("child_process");
|
|
50
|
-
var spawn_args_1 = __importDefault(require("spawn-args"));
|
|
51
|
-
var markdown_it_1 = __importDefault(require("markdown-it"));
|
|
52
|
-
var image_size_1 = __importDefault(require("image-size"));
|
|
53
|
-
var cli_spinner_1 = require("cli-spinner");
|
|
54
|
-
var fs_1 = require("./fs/fs");
|
|
55
|
-
var package_json_1 = require("../../package.json");
|
|
56
|
-
var markdown = new markdown_it_1.default('commonmark').enable('table');
|
|
57
|
-
//Allow CommonMark links that use other protocols, such as file:///
|
|
58
|
-
//The markdown-it implementation is more restrictive than the CommonMark spec
|
|
59
|
-
//See https://github.com/markdown-it/markdown-it/issues/108
|
|
60
|
-
markdown.validateLink = function () {
|
|
61
|
-
return true;
|
|
62
|
-
};
|
|
63
|
-
function DocGen(process) {
|
|
64
|
-
var _this = this;
|
|
65
|
-
var mainProcess = process;
|
|
66
|
-
var wkhtmltopdfVersion = 'wkhtmltopdf 0.12.6 (with patched qt)'; //output from wkhtmltopdf -V
|
|
67
|
-
var options;
|
|
68
|
-
var templates = {};
|
|
69
|
-
var meta = {};
|
|
70
|
-
var pages = {};
|
|
71
|
-
var sortedPages = {};
|
|
72
|
-
this.getVersion = function () {
|
|
73
|
-
return package_json_1.version;
|
|
74
|
-
};
|
|
75
|
-
this.setOptions = function (userOptions) {
|
|
76
|
-
options = userOptions;
|
|
77
|
-
//all user-specified paths must be normalized
|
|
78
|
-
if (options.input) {
|
|
79
|
-
options.input = path_1.default.normalize(options.input + '/');
|
|
80
|
-
}
|
|
81
|
-
if (options.output) {
|
|
82
|
-
options.output = path_1.default.normalize(options.output + '/');
|
|
83
|
-
}
|
|
84
|
-
//wkhtmltopdf path does not need a trailing slash
|
|
85
|
-
if (options.wkhtmltopdfPath && options.wkhtmltopdfPath !== '') {
|
|
86
|
-
options.wkhtmltopdfPath = path_1.default.normalize(options.wkhtmltopdfPath);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
/*
|
|
90
|
-
copy the example src files (template) to any directory, when scaffold command is invoked
|
|
91
|
-
*/
|
|
92
|
-
this.scaffold = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0:
|
|
96
|
-
console.log(chalk_1.default.green('Creating scaffold template directory'));
|
|
97
|
-
return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/example', options.output, options.verbose === true)];
|
|
98
|
-
case 1:
|
|
99
|
-
_a.sent();
|
|
100
|
-
return [2 /*return*/];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}); };
|
|
104
|
-
this.run = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
switch (_a.label) {
|
|
107
|
-
case 0:
|
|
108
|
-
console.log(chalk_1.default.green.bold('DocGen version ' + package_json_1.version));
|
|
109
|
-
//delete and recreate the output directory
|
|
110
|
-
return [4 /*yield*/, (0, fs_1.cleanDirectory)(options.output)];
|
|
111
|
-
case 1:
|
|
112
|
-
//delete and recreate the output directory
|
|
113
|
-
_a.sent();
|
|
114
|
-
loadTemplates();
|
|
115
|
-
return [2 /*return*/];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}); };
|
|
119
|
-
/*
|
|
120
|
-
load all HTML template files
|
|
121
|
-
*/
|
|
122
|
-
var loadTemplates = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
123
|
-
var files;
|
|
124
|
-
var _a;
|
|
125
|
-
return __generator(this, function (_b) {
|
|
126
|
-
switch (_b.label) {
|
|
127
|
-
case 0:
|
|
128
|
-
console.log(chalk_1.default.green('Loading templates'));
|
|
129
|
-
_a = {};
|
|
130
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/main.html')];
|
|
131
|
-
case 1:
|
|
132
|
-
_a.main = _b.sent();
|
|
133
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/redirect.html')];
|
|
134
|
-
case 2:
|
|
135
|
-
_a.redirect = _b.sent();
|
|
136
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/webCover.html')];
|
|
137
|
-
case 3:
|
|
138
|
-
_a.webCover = _b.sent();
|
|
139
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfCover.html')];
|
|
140
|
-
case 4:
|
|
141
|
-
_a.pdfCover = _b.sent();
|
|
142
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfHeader.html')];
|
|
143
|
-
case 5:
|
|
144
|
-
_a.pdfHeader = _b.sent();
|
|
145
|
-
return [4 /*yield*/, (0, fs_1.readFile)(__dirname + '/../include/templates/pdfFooter.html')];
|
|
146
|
-
case 6:
|
|
147
|
-
files = (_a.pdfFooter = _b.sent(),
|
|
148
|
-
_a);
|
|
149
|
-
rsvp_1.default
|
|
150
|
-
.hash(files)
|
|
151
|
-
.then(function (files) {
|
|
152
|
-
for (var key in files) {
|
|
153
|
-
if (files.hasOwnProperty(key)) {
|
|
154
|
-
var file = files[key];
|
|
155
|
-
var dom = cheerio_1.default.load(file);
|
|
156
|
-
templates[key] = dom;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
loadMeta();
|
|
160
|
-
})
|
|
161
|
-
.catch(function (error) {
|
|
162
|
-
console.log(chalk_1.default.red('Error loading templates'));
|
|
163
|
-
if (options.verbose === true) {
|
|
164
|
-
console.log(chalk_1.default.red(error));
|
|
165
|
-
}
|
|
166
|
-
mainProcess.exit(1);
|
|
167
|
-
});
|
|
168
|
-
return [2 /*return*/];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}); };
|
|
172
|
-
/*
|
|
173
|
-
JSON schema validation
|
|
174
|
-
*/
|
|
175
|
-
var schemas = {
|
|
176
|
-
parameters: {
|
|
177
|
-
title: 'DocGen Parameters Schema',
|
|
178
|
-
type: 'object',
|
|
179
|
-
required: [
|
|
180
|
-
'title',
|
|
181
|
-
'name',
|
|
182
|
-
'version',
|
|
183
|
-
'date',
|
|
184
|
-
'organization',
|
|
185
|
-
'author',
|
|
186
|
-
'owner',
|
|
187
|
-
'contributors',
|
|
188
|
-
'website',
|
|
189
|
-
'module',
|
|
190
|
-
'id',
|
|
191
|
-
'summary',
|
|
192
|
-
'marking',
|
|
193
|
-
'legalese',
|
|
194
|
-
],
|
|
195
|
-
properties: {
|
|
196
|
-
title: { type: 'string' },
|
|
197
|
-
name: { type: 'string' },
|
|
198
|
-
version: { type: 'string' },
|
|
199
|
-
date: { type: 'string' },
|
|
200
|
-
organization: {
|
|
201
|
-
type: 'object',
|
|
202
|
-
required: ['name', 'url'],
|
|
203
|
-
properties: {
|
|
204
|
-
name: { type: 'string' },
|
|
205
|
-
url: { type: 'string' },
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
author: {
|
|
209
|
-
type: 'object',
|
|
210
|
-
required: ['name', 'url'],
|
|
211
|
-
properties: {
|
|
212
|
-
name: { type: 'string' },
|
|
213
|
-
url: { type: 'string' },
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
owner: {
|
|
217
|
-
type: 'object',
|
|
218
|
-
required: ['name', 'url'],
|
|
219
|
-
properties: {
|
|
220
|
-
name: { type: 'string' },
|
|
221
|
-
url: { type: 'string' },
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
contributors: {
|
|
225
|
-
type: 'array',
|
|
226
|
-
items: {
|
|
227
|
-
oneOf: [
|
|
228
|
-
{
|
|
229
|
-
type: 'object',
|
|
230
|
-
required: ['name', 'url'],
|
|
231
|
-
properties: {
|
|
232
|
-
name: { type: 'string' },
|
|
233
|
-
url: { type: 'string' },
|
|
234
|
-
},
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
website: {
|
|
240
|
-
type: 'object',
|
|
241
|
-
required: ['name', 'url'],
|
|
242
|
-
properties: {
|
|
243
|
-
name: { type: 'string' },
|
|
244
|
-
url: { type: 'string' },
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
sponsorLink: {
|
|
248
|
-
type: 'object',
|
|
249
|
-
required: ['name', 'url', 'logo'],
|
|
250
|
-
properties: {
|
|
251
|
-
name: { type: 'string' },
|
|
252
|
-
url: { type: 'string' },
|
|
253
|
-
logo: { type: 'string' },
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
backlink: {
|
|
257
|
-
type: 'object',
|
|
258
|
-
required: ['name', 'url'],
|
|
259
|
-
properties: {
|
|
260
|
-
name: { type: 'string' },
|
|
261
|
-
url: { type: 'string' },
|
|
262
|
-
},
|
|
263
|
-
},
|
|
264
|
-
module: { type: 'string' },
|
|
265
|
-
id: { type: 'string' },
|
|
266
|
-
summary: { type: 'string' },
|
|
267
|
-
marking: { type: 'string' },
|
|
268
|
-
legalese: { type: 'string' },
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
contents: {
|
|
272
|
-
title: 'DocGen Table of Contents Schema',
|
|
273
|
-
type: 'array',
|
|
274
|
-
items: {
|
|
275
|
-
oneOf: [
|
|
276
|
-
{
|
|
277
|
-
type: 'object',
|
|
278
|
-
required: ['heading', 'column', 'pages'],
|
|
279
|
-
properties: {
|
|
280
|
-
name: { type: 'string' },
|
|
281
|
-
column: { type: 'integer', minimum: 1, maximum: 4 },
|
|
282
|
-
pages: {
|
|
283
|
-
type: 'array',
|
|
284
|
-
items: {
|
|
285
|
-
oneOf: [
|
|
286
|
-
{
|
|
287
|
-
type: 'object',
|
|
288
|
-
required: ['title', 'source'],
|
|
289
|
-
properties: {
|
|
290
|
-
title: { type: 'string' },
|
|
291
|
-
source: { type: 'string' },
|
|
292
|
-
html: { type: 'boolean' },
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
],
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
],
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
};
|
|
304
|
-
var validateJSON = function (key, data) {
|
|
305
|
-
var schema = schemas[key];
|
|
306
|
-
var validator = new z_schema_1.default();
|
|
307
|
-
var valid = validator.validate(data, schema);
|
|
308
|
-
if (!valid) {
|
|
309
|
-
console.log(chalk_1.default.red('Error parsing required file: ' +
|
|
310
|
-
key +
|
|
311
|
-
'.json (failed schema validation)'));
|
|
312
|
-
if (options.verbose === true) {
|
|
313
|
-
console.log(chalk_1.default.red(validator.getLastError()));
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return valid;
|
|
317
|
-
};
|
|
318
|
-
/*
|
|
319
|
-
load all metadata files (JSON)
|
|
320
|
-
*/
|
|
321
|
-
var loadMeta = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
322
|
-
var files;
|
|
323
|
-
var _a;
|
|
324
|
-
return __generator(this, function (_b) {
|
|
325
|
-
switch (_b.label) {
|
|
326
|
-
case 0:
|
|
327
|
-
console.log(chalk_1.default.green('Loading required JSON metadata files'));
|
|
328
|
-
_a = {};
|
|
329
|
-
return [4 /*yield*/, (0, fs_1.readFile)(options.input + '/parameters.json')];
|
|
330
|
-
case 1:
|
|
331
|
-
_a.parameters = _b.sent();
|
|
332
|
-
return [4 /*yield*/, (0, fs_1.readFile)(options.input + '/contents.json')];
|
|
333
|
-
case 2:
|
|
334
|
-
files = (_a.contents = _b.sent(),
|
|
335
|
-
_a);
|
|
336
|
-
rsvp_1.default
|
|
337
|
-
.hash(files)
|
|
338
|
-
.then(function (files) {
|
|
339
|
-
for (var key in files) {
|
|
340
|
-
if (files.hasOwnProperty(key)) {
|
|
341
|
-
//ignore prototype
|
|
342
|
-
try {
|
|
343
|
-
var file = JSON.parse(files[key]);
|
|
344
|
-
if (validateJSON(key, file)) {
|
|
345
|
-
meta[key] = file;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
mainProcess.exit(1);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
console.log(chalk_1.default.red('Error parsing required file: ' +
|
|
353
|
-
key +
|
|
354
|
-
'.json (invalid JSON)'));
|
|
355
|
-
if (options.verbose === true) {
|
|
356
|
-
console.log(chalk_1.default.red(error));
|
|
357
|
-
}
|
|
358
|
-
mainProcess.exit(1);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
//add the release notes to the contents list
|
|
363
|
-
var extra = {
|
|
364
|
-
heading: 'Extra',
|
|
365
|
-
column: 5,
|
|
366
|
-
pages: [{ title: 'Release notes', source: 'release-notes.md' }],
|
|
367
|
-
};
|
|
368
|
-
meta.contents.push(extra);
|
|
369
|
-
loadMarkdown();
|
|
370
|
-
})
|
|
371
|
-
.catch(function (error) {
|
|
372
|
-
console.log(chalk_1.default.red('Error loading required JSON metadata files'));
|
|
373
|
-
if (options.verbose === true) {
|
|
374
|
-
console.log(chalk_1.default.red(error));
|
|
375
|
-
}
|
|
376
|
-
mainProcess.exit(1);
|
|
377
|
-
});
|
|
378
|
-
return [2 /*return*/];
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
}); };
|
|
382
|
-
/*
|
|
383
|
-
load all markdown files (src)
|
|
384
|
-
*/
|
|
385
|
-
var loadMarkdown = function () {
|
|
386
|
-
console.log(chalk_1.default.green('Loading src files'));
|
|
387
|
-
var keys = [];
|
|
388
|
-
var files = [];
|
|
389
|
-
meta.contents.forEach(function (section) {
|
|
390
|
-
section.pages.forEach(function (page) {
|
|
391
|
-
keys.push(page);
|
|
392
|
-
files.push(options.input + '/' + page.source);
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
//add the release notes page
|
|
396
|
-
keys.push('ownership');
|
|
397
|
-
files.push(options.input + '/release-notes.md');
|
|
398
|
-
rsvp_1.default
|
|
399
|
-
.all(files.map(fs_1.readFile))
|
|
400
|
-
.then(function (files) {
|
|
401
|
-
files.forEach(function (page, index) {
|
|
402
|
-
try {
|
|
403
|
-
var key = keys[index];
|
|
404
|
-
if (key.html === true) {
|
|
405
|
-
//allow raw HTML input pages
|
|
406
|
-
pages[key.source] = page;
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
//otherwise parse input from Markdown into HTML
|
|
410
|
-
var html = markdown.render(page);
|
|
411
|
-
pages[key.source] = html;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
catch (error) {
|
|
415
|
-
console.log(chalk_1.default.red('Error parsing Markdown file: ' + file.source));
|
|
416
|
-
if (options.verbose === true) {
|
|
417
|
-
console.log(chalk_1.default.red(error));
|
|
418
|
-
}
|
|
419
|
-
mainProcess.exit(1);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
processContent();
|
|
423
|
-
})
|
|
424
|
-
.catch(function (error) {
|
|
425
|
-
console.log(error);
|
|
426
|
-
console.log(chalk_1.default.red('Error loading src files'));
|
|
427
|
-
if (options.verbose === true) {
|
|
428
|
-
console.log(chalk_1.default.red(error));
|
|
429
|
-
}
|
|
430
|
-
mainProcess.exit(1);
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
var sortPages = function () {
|
|
434
|
-
//sort the contents by heading
|
|
435
|
-
var headings = { 1: [], 2: [], 3: [], 4: [], 5: [] };
|
|
436
|
-
meta.contents.forEach(function (section) {
|
|
437
|
-
if (headings.hasOwnProperty(section.column)) {
|
|
438
|
-
headings[section.column].push(section);
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
sortedPages = headings;
|
|
442
|
-
};
|
|
443
|
-
/*
|
|
444
|
-
build the HTML for the table of contents
|
|
445
|
-
*/
|
|
446
|
-
var webToc = function () {
|
|
447
|
-
sortPages();
|
|
448
|
-
var pdfName = meta.parameters.name.toLowerCase() + '.pdf';
|
|
449
|
-
var $ = templates.main;
|
|
450
|
-
var html = [], i = -1;
|
|
451
|
-
html[++i] = '<div><table class="unstyled"><tr>';
|
|
452
|
-
//build the contents HTML
|
|
453
|
-
for (var key in sortedPages) {
|
|
454
|
-
if (sortedPages.hasOwnProperty(key)) {
|
|
455
|
-
if (key != 5) {
|
|
456
|
-
//skip the extra column
|
|
457
|
-
html[++i] = '<td class="dg-tocGroup">';
|
|
458
|
-
sortedPages[key].forEach(function (section) {
|
|
459
|
-
html[++i] =
|
|
460
|
-
'<ul><li class="dg-tocHeading">' + section.heading + '</li>';
|
|
461
|
-
section.pages.forEach(function (page) {
|
|
462
|
-
var name = page.source.substr(0, page.source.lastIndexOf('.'));
|
|
463
|
-
var path = name + '.html';
|
|
464
|
-
html[++i] =
|
|
465
|
-
'<li><a href="' + path + '">' + page.title + '</a></li>';
|
|
466
|
-
});
|
|
467
|
-
html[++i] = '</li></ul>';
|
|
468
|
-
});
|
|
469
|
-
html[++i] = '</td>';
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
//fixed-width column at end
|
|
474
|
-
html[++i] = '<td class="dg-tocGroup" id="dg-tocFixedColumn"><ul>';
|
|
475
|
-
html[++i] =
|
|
476
|
-
'<li><span class="w-icon dg-tocIcon" data-name="person_group" title="archive"></span><a href="ownership.html">Ownership</a></li>';
|
|
477
|
-
html[++i] =
|
|
478
|
-
'<li><span class="w-icon dg-tocIcon" data-name="refresh" title="archive"></span><a href="release-notes.html">Release Notes</a></li>';
|
|
479
|
-
html[++i] = '</ul><div>';
|
|
480
|
-
if (options.pdf) {
|
|
481
|
-
html[++i] =
|
|
482
|
-
'<button class="whiteInverted" onclick="window.location=\'' +
|
|
483
|
-
pdfName +
|
|
484
|
-
'\';">';
|
|
485
|
-
html[++i] = '<span>PDF</span>';
|
|
486
|
-
html[++i] = '</button>';
|
|
487
|
-
}
|
|
488
|
-
html[++i] = '</div></td>';
|
|
489
|
-
html[++i] = '</tr></table></div>';
|
|
490
|
-
$('#dg-toc').html(html.join(''));
|
|
491
|
-
templates.main = $;
|
|
492
|
-
};
|
|
493
|
-
/*
|
|
494
|
-
insert the parameters into all templates
|
|
495
|
-
*/
|
|
496
|
-
var insertParameters = function () {
|
|
497
|
-
//------------------------------------------------------------------------------------------------------
|
|
498
|
-
//logo dimensions
|
|
499
|
-
var hasLogo = false;
|
|
500
|
-
var logoWidth = 0;
|
|
501
|
-
var logoHeight = 0;
|
|
502
|
-
var logoPath;
|
|
503
|
-
try {
|
|
504
|
-
logoPath = 'files/images/logo.svg';
|
|
505
|
-
var logo = (0, image_size_1.default)("".concat(options.input, "/").concat(logoPath));
|
|
506
|
-
logoWidth = logo.width;
|
|
507
|
-
logoHeight = logo.height;
|
|
508
|
-
hasLogo = true;
|
|
509
|
-
}
|
|
510
|
-
catch (error) {
|
|
511
|
-
//do nothing. If logo file cannot be read, logo is simply not shown
|
|
512
|
-
}
|
|
513
|
-
if (!hasLogo) {
|
|
514
|
-
//PNG fallback
|
|
515
|
-
try {
|
|
516
|
-
logoPath = 'files/images/logo.png';
|
|
517
|
-
var logo = (0, image_size_1.default)("".concat(options.input, "/").concat(logoPath));
|
|
518
|
-
logoWidth = logo.width;
|
|
519
|
-
logoHeight = logo.height;
|
|
520
|
-
hasLogo = true;
|
|
521
|
-
}
|
|
522
|
-
catch (error) {
|
|
523
|
-
//do nothing. If logo file cannot be read, logo is simply not shown
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
//------------------------------------------------------------------------------------------------------
|
|
527
|
-
//the homepage is the first link in the first heading
|
|
528
|
-
var homelink = meta.contents[0].pages[0];
|
|
529
|
-
homelink =
|
|
530
|
-
homelink.source.substr(0, homelink.source.lastIndexOf('.')) + '.html';
|
|
531
|
-
var date = (0, moment_1.default)().format('DD/MM/YYYY');
|
|
532
|
-
var time = (0, moment_1.default)().format('HH:mm:ss');
|
|
533
|
-
var year = (0, moment_1.default)().format('YYYY');
|
|
534
|
-
var attribution = 'Created by DocGen ' + package_json_1.version + ' on ' + date + ' at ' + time + '.';
|
|
535
|
-
var releaseVersion = meta.parameters.version;
|
|
536
|
-
if (options.setVersion !== false) {
|
|
537
|
-
releaseVersion = options.setVersion;
|
|
538
|
-
}
|
|
539
|
-
var releaseDate = meta.parameters.date;
|
|
540
|
-
if (options.setReleaseDate !== false) {
|
|
541
|
-
releaseDate = options.setReleaseDate;
|
|
542
|
-
}
|
|
543
|
-
var author = '';
|
|
544
|
-
if (meta.parameters.author.url !== '') {
|
|
545
|
-
author +=
|
|
546
|
-
'<a href="' +
|
|
547
|
-
meta.parameters.author.url +
|
|
548
|
-
'">' +
|
|
549
|
-
meta.parameters.author.name +
|
|
550
|
-
'</a>';
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
author += meta.parameters.author.name;
|
|
554
|
-
}
|
|
555
|
-
var owner = '';
|
|
556
|
-
if (meta.parameters.owner.url !== '') {
|
|
557
|
-
owner +=
|
|
558
|
-
'<a href="' +
|
|
559
|
-
meta.parameters.owner.url +
|
|
560
|
-
'">' +
|
|
561
|
-
meta.parameters.owner.name +
|
|
562
|
-
'</a>';
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
owner += meta.parameters.owner.name;
|
|
566
|
-
}
|
|
567
|
-
var organization = '';
|
|
568
|
-
if (meta.parameters.organization.url !== '') {
|
|
569
|
-
organization +=
|
|
570
|
-
'<a href="' +
|
|
571
|
-
meta.parameters.organization.url +
|
|
572
|
-
'">' +
|
|
573
|
-
meta.parameters.organization.name +
|
|
574
|
-
'</a>';
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
organization += meta.parameters.organization.name;
|
|
578
|
-
}
|
|
579
|
-
var website = '';
|
|
580
|
-
if (meta.parameters.website.url !== '') {
|
|
581
|
-
website +=
|
|
582
|
-
'<a href="' +
|
|
583
|
-
meta.parameters.website.url +
|
|
584
|
-
'">' +
|
|
585
|
-
meta.parameters.website.name +
|
|
586
|
-
'</a>';
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
website += meta.parameters.website.name;
|
|
590
|
-
}
|
|
591
|
-
var backlink = '';
|
|
592
|
-
if (meta.parameters.backlink.url !== '') {
|
|
593
|
-
backlink +=
|
|
594
|
-
'<a class="button inverted" href="' +
|
|
595
|
-
meta.parameters.backlink.url +
|
|
596
|
-
'">' +
|
|
597
|
-
meta.parameters.backlink.name +
|
|
598
|
-
'</a>';
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
backlink += meta.parameters.backlink.name;
|
|
602
|
-
}
|
|
603
|
-
var sponsorLink = '';
|
|
604
|
-
if (meta.parameters.sponsorLink) {
|
|
605
|
-
sponsorLink = "\n <div id=\"headerSponsor\">\n <span>".concat(meta.parameters.sponsorLink.name, "</span>\n <a href=\"").concat(meta.parameters.sponsorLink.url, "\">\n <img id=\"sponsorLogo\" src=\"").concat(meta.parameters.sponsorLink.logo, "\" alt=\"sponsor logo\">\n </a>\n </div>\n ");
|
|
606
|
-
}
|
|
607
|
-
var contributors = '';
|
|
608
|
-
meta.parameters.contributors.forEach(function (contributor) {
|
|
609
|
-
if (contributor.url !== '') {
|
|
610
|
-
contributors +=
|
|
611
|
-
'<a href="' + contributor.url + '">' + contributor.name + '</a>, ';
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
contributors += contributor.name + ', ';
|
|
615
|
-
}
|
|
616
|
-
});
|
|
617
|
-
contributors = contributors.replace(/,\s*$/, ''); //remove trailing commas
|
|
618
|
-
var copyright = '© ' + year + ' ' + organization;
|
|
619
|
-
var webTitle = meta.parameters.title;
|
|
620
|
-
var webFooter = 'Version ' + releaseVersion + ' released on ' + releaseDate + '.';
|
|
621
|
-
for (var key in templates) {
|
|
622
|
-
if (templates.hasOwnProperty(key)) {
|
|
623
|
-
var $ = templates[key];
|
|
624
|
-
//logo
|
|
625
|
-
if (hasLogo === true) {
|
|
626
|
-
var logoUrl = logoPath;
|
|
627
|
-
$('#dg-logo').css('background-image', 'url(' + logoUrl + ')');
|
|
628
|
-
$('#dg-logo').css('height', logoHeight + 'px');
|
|
629
|
-
$('#dg-logo').css('padding-left', logoWidth + 25 + 'px');
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
$('#dg-logo').css('padding-left', '0');
|
|
633
|
-
}
|
|
634
|
-
//parameters
|
|
635
|
-
$('title').text(meta.parameters.title);
|
|
636
|
-
$('.dg-homelink').attr('href', homelink);
|
|
637
|
-
$('#dg-title').text(meta.parameters.title);
|
|
638
|
-
$('#dg-owner').html(owner);
|
|
639
|
-
$('#dg-version').text(releaseVersion);
|
|
640
|
-
$('#dg-web-title-version').text('(' + releaseVersion + ')');
|
|
641
|
-
$('#dg-release-date').text(releaseDate);
|
|
642
|
-
$('#dg-web-footer').text(webFooter);
|
|
643
|
-
$('#dg-author').html(author);
|
|
644
|
-
$('#dg-contributors').html(contributors);
|
|
645
|
-
$('#dg-module').text(meta.parameters.module);
|
|
646
|
-
$('#dg-id').html(meta.parameters.id);
|
|
647
|
-
$('#dg-website').html(website);
|
|
648
|
-
$('#dg-backlink').html(backlink);
|
|
649
|
-
$('#headerLeftText').append(sponsorLink);
|
|
650
|
-
$('#dg-summary').text(meta.parameters.summary);
|
|
651
|
-
$('#dg-copyright').html(copyright);
|
|
652
|
-
$('#dg-marking').text(meta.parameters.marking);
|
|
653
|
-
$('#dg-legalese').text(meta.parameters.legalese);
|
|
654
|
-
$('#dg-attribution').text(attribution);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
if (options.mathKatex === true) {
|
|
658
|
-
var $ = templates.main;
|
|
659
|
-
//support for KaTeX (bundled with DocGen)
|
|
660
|
-
$('head').append('<link rel="stylesheet" href="require/katex/katex.min.css" type="text/css">');
|
|
661
|
-
$('head').append('<script type="text/javascript" src="require/katex/katex.min.js"></script>');
|
|
662
|
-
$('head').append('<script type="text/javascript" src="require/katexInjector.js"></script>');
|
|
663
|
-
}
|
|
664
|
-
if (options.mathMathjax === true) {
|
|
665
|
-
//support for MathJax (only supported via CDN due to very large size)
|
|
666
|
-
//MathJax configuration is the same as used by math.stackexchange.com
|
|
667
|
-
//Note - wkhtmlpdf //cdn urls - see https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1634
|
|
668
|
-
//Note - later than version 2 doesn't work with wkhtmltodpf
|
|
669
|
-
$('head').append("<script type=\"text/javascript\" id=\"MathJax-script\" async\n src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML\">\n </script>");
|
|
670
|
-
}
|
|
671
|
-
};
|
|
672
|
-
/*
|
|
673
|
-
process each input into an output
|
|
674
|
-
*/
|
|
675
|
-
var processContent = function () {
|
|
676
|
-
console.log(chalk_1.default.green('Generating the static web content'));
|
|
677
|
-
webToc();
|
|
678
|
-
insertParameters();
|
|
679
|
-
meta.contents.forEach(function (section) {
|
|
680
|
-
section.pages.forEach(function (page) {
|
|
681
|
-
var $ = cheerio_1.default.load(templates.main.html()); //clone
|
|
682
|
-
var key = page.source;
|
|
683
|
-
var content = pages[key];
|
|
684
|
-
//add relevant container
|
|
685
|
-
if (page.html === true) {
|
|
686
|
-
//raw HTML pages should not be confined to the fixed width
|
|
687
|
-
$('#dg-content').html('<div id="dg-innerContent"></div>');
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
//Markdown pages should be confined to the fixed width
|
|
691
|
-
$('#dg-content').html('<div class="w-fixed-width"><div id="dg-innerContent"></div></div>');
|
|
692
|
-
}
|
|
693
|
-
$('#dg-innerContent').html(content);
|
|
694
|
-
//------------------------------------------------------------------------------------------------------
|
|
695
|
-
//insert permalinks for every page heading
|
|
696
|
-
//when pageToc is enabled, also insert a page-level table of contents
|
|
697
|
-
var html = [], i = -1;
|
|
698
|
-
var headings = $('h1, h2, h3, h4, h5, h6');
|
|
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
|
-
});
|
|
726
|
-
});
|
|
727
|
-
//add web ownership page
|
|
728
|
-
var $ = cheerio_1.default.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
|
-
};
|
|
734
|
-
/*
|
|
735
|
-
write each html page
|
|
736
|
-
*/
|
|
737
|
-
var writePages = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
738
|
-
var promises, pdfTempDir;
|
|
739
|
-
var _this = this;
|
|
740
|
-
return __generator(this, function (_a) {
|
|
741
|
-
switch (_a.label) {
|
|
742
|
-
case 0:
|
|
743
|
-
console.log(chalk_1.default.green('Writing the web page files'));
|
|
744
|
-
promises = {};
|
|
745
|
-
meta.contents.forEach(function (section) {
|
|
746
|
-
section.pages.forEach(function (page) {
|
|
747
|
-
var key = page.source;
|
|
748
|
-
var name = key.substr(0, page.source.lastIndexOf('.'));
|
|
749
|
-
var path = options.output + name + '.html';
|
|
750
|
-
var html = pages[key].html();
|
|
751
|
-
promises[key] = (0, fs_1.writeFile)(path, html);
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
//add extra files
|
|
755
|
-
promises['ownership'] = (0, fs_1.writeFile)(options.output + 'ownership.html', templates.webCover.html());
|
|
756
|
-
if (!(options.pdf === true)) return [3 /*break*/, 2];
|
|
757
|
-
pdfTempDir = options.output + 'temp/';
|
|
758
|
-
return [4 /*yield*/, (0, fs_1.makeDirectory)(pdfTempDir)];
|
|
759
|
-
case 1:
|
|
760
|
-
_a.sent();
|
|
761
|
-
promises['docgenPdfCover'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfCover.html', templates.pdfCover.html());
|
|
762
|
-
promises['docgenPdfHeader'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfHeader.html', templates.pdfHeader.html());
|
|
763
|
-
promises['docgenPdfFooter'] = (0, fs_1.writeFile)(pdfTempDir + 'pdfFooter.html', templates.pdfFooter.html());
|
|
764
|
-
_a.label = 2;
|
|
765
|
-
case 2:
|
|
766
|
-
rsvp_1.default
|
|
767
|
-
.hash(promises)
|
|
768
|
-
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
769
|
-
return __generator(this, function (_a) {
|
|
770
|
-
switch (_a.label) {
|
|
771
|
-
case 0: return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/require', options.output + 'require', options.verbose === true)];
|
|
772
|
-
case 1:
|
|
773
|
-
_a.sent(); //CSS, JavaScript
|
|
774
|
-
return [4 /*yield*/, (0, fs_1.copyDirectory)(options.input + '/files', options.output + 'files', options.verbose === true)];
|
|
775
|
-
case 2:
|
|
776
|
-
_a.sent(); //user-attached files and images
|
|
777
|
-
if (!(options.mathKatex === true)) return [3 /*break*/, 4];
|
|
778
|
-
return [4 /*yield*/, (0, fs_1.copyDirectory)(__dirname + '/../include/optional/katex', options.output + 'require/katex', options.verbose === true)];
|
|
779
|
-
case 3:
|
|
780
|
-
_a.sent();
|
|
781
|
-
_a.label = 4;
|
|
782
|
-
case 4:
|
|
783
|
-
checkPdfVersion();
|
|
784
|
-
return [2 /*return*/];
|
|
785
|
-
}
|
|
786
|
-
});
|
|
787
|
-
}); })
|
|
788
|
-
.catch(function (error) {
|
|
789
|
-
console.log(chalk_1.default.red('Error writing the web page files'));
|
|
790
|
-
if (options.verbose === true) {
|
|
791
|
-
console.log(chalk_1.default.red(error));
|
|
792
|
-
}
|
|
793
|
-
mainProcess.exit(1);
|
|
794
|
-
});
|
|
795
|
-
return [2 /*return*/];
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
}); };
|
|
799
|
-
/*
|
|
800
|
-
wkthmltopdf options
|
|
801
|
-
*/
|
|
802
|
-
var pdfOptions = [
|
|
803
|
-
' --zoom 1.0',
|
|
804
|
-
' --image-quality 100',
|
|
805
|
-
' --print-media-type',
|
|
806
|
-
' --orientation portrait',
|
|
807
|
-
' --page-size A4',
|
|
808
|
-
' --margin-top 25',
|
|
809
|
-
' --margin-right 15',
|
|
810
|
-
' --margin-bottom 16',
|
|
811
|
-
' --margin-left 15',
|
|
812
|
-
' --header-spacing 5',
|
|
813
|
-
' --footer-spacing 5',
|
|
814
|
-
' --no-stop-slow-scripts',
|
|
815
|
-
];
|
|
816
|
-
var getPdfArguments = function () {
|
|
817
|
-
var pdfName = meta.parameters.name.toLowerCase() + '.pdf';
|
|
818
|
-
pdfOptions.push(' --enable-local-file-access');
|
|
819
|
-
pdfOptions.push(' --javascript-delay ' + options.pdfDelay); //code syntax highlight in wkhtmltopdf 0.12.2.1 fails without a delay (but why doesn't --no-stop-slow-scripts work?)
|
|
820
|
-
pdfOptions.push(' --user-style-sheet ' + __dirname + '/../include/pdf-stylesheet.css');
|
|
821
|
-
pdfOptions.push(' --header-html ' + options.output + 'temp/pdfHeader.html');
|
|
822
|
-
pdfOptions.push(' --footer-html ' + options.output + 'temp/pdfFooter.html');
|
|
823
|
-
pdfOptions.push(' cover ' + options.output + 'temp/pdfCover.html');
|
|
824
|
-
pdfOptions.push(' toc --xsl-style-sheet ' + __dirname + '/../include/pdf-contents.xsl');
|
|
825
|
-
var allPages = '';
|
|
826
|
-
for (var key in sortedPages) {
|
|
827
|
-
if (sortedPages.hasOwnProperty(key)) {
|
|
828
|
-
sortedPages[key].forEach(function (section) {
|
|
829
|
-
section.pages.forEach(function (page) {
|
|
830
|
-
var key = page.source;
|
|
831
|
-
var name = key.substr(0, page.source.lastIndexOf('.'));
|
|
832
|
-
var path = options.output + name + '.html';
|
|
833
|
-
allPages += ' ' + path;
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
var args = pdfOptions.join('');
|
|
839
|
-
args += allPages;
|
|
840
|
-
args += ' ' + options.output + pdfName;
|
|
841
|
-
return (0, spawn_args_1.default)(args);
|
|
842
|
-
};
|
|
843
|
-
var checkPdfVersion = function () {
|
|
844
|
-
if (options.pdf === true) {
|
|
845
|
-
//first check that wkhtmltopdf is installed
|
|
846
|
-
(0, child_process_1.exec)(options.wkhtmltopdfPath + ' -V', function (error, stdout, stderr) {
|
|
847
|
-
if (error) {
|
|
848
|
-
console.log(chalk_1.default.red('Unable to call wkhtmltopdf. Is it installed and in path? See http://wkhtmltopdf.org'));
|
|
849
|
-
if (options.verbose === true) {
|
|
850
|
-
console.log(chalk_1.default.red(error));
|
|
851
|
-
}
|
|
852
|
-
mainProcess.exit(1);
|
|
853
|
-
}
|
|
854
|
-
else {
|
|
855
|
-
//warn if the version of wkhtmltopdf is not an expected version
|
|
856
|
-
var actualWkhtmltopdfVersion = stdout.trim();
|
|
857
|
-
if (actualWkhtmltopdfVersion !== wkhtmltopdfVersion) {
|
|
858
|
-
var warning = 'Warning: unexpected version of wkhtmltopdf, which may work but is not tested or supported';
|
|
859
|
-
var expectedVersion = ' expected version: ' + wkhtmltopdfVersion;
|
|
860
|
-
var detectedVersion = ' detected version: ' + actualWkhtmltopdfVersion;
|
|
861
|
-
console.log(chalk_1.default.yellow(warning));
|
|
862
|
-
console.log(chalk_1.default.yellow(expectedVersion));
|
|
863
|
-
console.log(chalk_1.default.yellow(detectedVersion));
|
|
864
|
-
}
|
|
865
|
-
generatePdf();
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
cleanUp();
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
/*
|
|
874
|
-
call wkhtmltopdf as an external executable
|
|
875
|
-
*/
|
|
876
|
-
var generatePdf = function () {
|
|
877
|
-
console.log(chalk_1.default.green('Creating the PDF copy (may take some time)'));
|
|
878
|
-
var args = getPdfArguments();
|
|
879
|
-
var wkhtmltopdf = (0, child_process_1.spawn)(options.wkhtmltopdfPath, args);
|
|
880
|
-
var spinner = new cli_spinner_1.Spinner(chalk_1.default.green(' Processing... %s'));
|
|
881
|
-
spinner.setSpinnerString('|/-\\');
|
|
882
|
-
wkhtmltopdf.on('error', function (error) {
|
|
883
|
-
console.log(chalk_1.default.red('Error calling wkhtmltopdf to generate the PDF'));
|
|
884
|
-
if (options.verbose === true) {
|
|
885
|
-
console.log(chalk_1.default.red(error));
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
if (options.verbose !== true) {
|
|
889
|
-
spinner.start(); //only show spinner when verbose is off (otherwise show raw wkhtmltopdf output)
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
//pipe the output from wkhtmltopdf back to stdout
|
|
893
|
-
//however, wkhtmltpdf outputs to stderr, not stdout. See:
|
|
894
|
-
//https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1980
|
|
895
|
-
wkhtmltopdf.stderr.pipe(mainProcess.stdout);
|
|
896
|
-
}
|
|
897
|
-
wkhtmltopdf.stdout.on('data', function (data) {
|
|
898
|
-
//do nothing
|
|
899
|
-
});
|
|
900
|
-
wkhtmltopdf.stderr.on('data', function (data) {
|
|
901
|
-
//do nothing
|
|
902
|
-
});
|
|
903
|
-
wkhtmltopdf.on('close', function (code) {
|
|
904
|
-
if (options.verbose !== true) {
|
|
905
|
-
spinner.stop();
|
|
906
|
-
console.log(''); //newline after spinner stops
|
|
907
|
-
}
|
|
908
|
-
if (code !== 0) {
|
|
909
|
-
var warning = 'wkhtmltopdf exited with a warning or error: try the -v option for details';
|
|
910
|
-
console.log(chalk_1.default.yellow(warning));
|
|
911
|
-
}
|
|
912
|
-
cleanUp();
|
|
913
|
-
});
|
|
914
|
-
};
|
|
915
|
-
var createRedirect = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
916
|
-
var parent_1, homepage, redirectLink, $, file, error_1;
|
|
917
|
-
return __generator(this, function (_a) {
|
|
918
|
-
switch (_a.label) {
|
|
919
|
-
case 0:
|
|
920
|
-
if (!options.redirect) return [3 /*break*/, 4];
|
|
921
|
-
parent_1 = options.output.replace(/\/$/, '');
|
|
922
|
-
parent_1 = parent_1.split(path_1.default.sep).slice(-1).pop(); //get name of final directory in the path
|
|
923
|
-
homepage = meta.contents[0].pages[0];
|
|
924
|
-
homepage =
|
|
925
|
-
homepage.source.substr(0, homepage.source.lastIndexOf('.')) + '.html';
|
|
926
|
-
redirectLink = parent_1 + '/' + homepage;
|
|
927
|
-
$ = templates.redirect;
|
|
928
|
-
$('a').attr('href', redirectLink);
|
|
929
|
-
$('meta[http-equiv=REFRESH]').attr('content', '0;url=' + redirectLink);
|
|
930
|
-
file = options.output + '../' + 'index.html';
|
|
931
|
-
_a.label = 1;
|
|
932
|
-
case 1:
|
|
933
|
-
_a.trys.push([1, 3, , 4]);
|
|
934
|
-
return [4 /*yield*/, (0, fs_1.writeFile)(file, $.html())];
|
|
935
|
-
case 2:
|
|
936
|
-
_a.sent();
|
|
937
|
-
return [3 /*break*/, 4];
|
|
938
|
-
case 3:
|
|
939
|
-
error_1 = _a.sent();
|
|
940
|
-
console.log(chalk_1.default.red('Error writing redirect file: ' + file));
|
|
941
|
-
if (options.verbose === true) {
|
|
942
|
-
console.log(chalk_1.default.red(error_1));
|
|
943
|
-
}
|
|
944
|
-
return [3 /*break*/, 4];
|
|
945
|
-
case 4: return [2 /*return*/];
|
|
946
|
-
}
|
|
947
|
-
});
|
|
948
|
-
}); };
|
|
949
|
-
/*
|
|
950
|
-
cleanup
|
|
951
|
-
*/
|
|
952
|
-
var cleanUp = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
953
|
-
return __generator(this, function (_a) {
|
|
954
|
-
switch (_a.label) {
|
|
955
|
-
case 0:
|
|
956
|
-
createRedirect();
|
|
957
|
-
if (!(options.pdf === true)) return [3 /*break*/, 2];
|
|
958
|
-
return [4 /*yield*/, (0, fs_1.removeDirectory)(options.output + 'temp')];
|
|
959
|
-
case 1:
|
|
960
|
-
_a.sent();
|
|
961
|
-
_a.label = 2;
|
|
962
|
-
case 2:
|
|
963
|
-
console.log(chalk_1.default.green.bold('Done!'));
|
|
964
|
-
return [2 /*return*/];
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
}); };
|
|
968
|
-
}
|
|
969
|
-
exports.DocGen = DocGen;
|