hdoc-tools 0.6.2 → 0.6.3
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/README.md +42 -0
- package/hdoc-serve.js +97 -97
- package/hdoc-stats.js +45 -24
- package/hdoc.js +36 -17
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# hdoc-tools
|
|
2
|
+
|
|
3
|
+
Hornbill HDocBook Development Support Tool.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
<code>hdoc argument switches</code>
|
|
8
|
+
|
|
9
|
+
## Arguments
|
|
10
|
+
|
|
11
|
+
The arguments available to this command-line tool are as follows.
|
|
12
|
+
|
|
13
|
+
### help
|
|
14
|
+
|
|
15
|
+
Outputs available arguments and switches.
|
|
16
|
+
|
|
17
|
+
### init
|
|
18
|
+
|
|
19
|
+
Initializes a new HDocBook project from a template, using runtime input variables.
|
|
20
|
+
|
|
21
|
+
### stats
|
|
22
|
+
|
|
23
|
+
Returns statistics regarding the book you are working on:
|
|
24
|
+
|
|
25
|
+
- Document ID
|
|
26
|
+
- Version
|
|
27
|
+
- Title
|
|
28
|
+
- Description
|
|
29
|
+
- Public Source
|
|
30
|
+
- Total Book Word Count
|
|
31
|
+
- Number of Markdown Files in the Book
|
|
32
|
+
- Number of Static HTML Files in the Book
|
|
33
|
+
|
|
34
|
+
If the -v switch is provided, then a more verbose output is output, which includes a list of each MD and HTML file found, the file sizes, and file-specific word count.
|
|
35
|
+
|
|
36
|
+
### build
|
|
37
|
+
|
|
38
|
+
Performs a local build of the book, and outputs as a ZIP file.
|
|
39
|
+
|
|
40
|
+
### serve
|
|
41
|
+
|
|
42
|
+
Starts a local web server on port 3000, serving the book content.
|
package/hdoc-serve.js
CHANGED
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
|
|
9
9
|
exports.run = function (ui_path, source_path, md) {
|
|
10
10
|
|
|
11
|
-
console.log(
|
|
12
|
-
console.log(
|
|
13
|
-
console.log(
|
|
14
|
-
console.log(
|
|
11
|
+
console.log('Hornbill HDocBook Preview/Dev Server', '\r\n');
|
|
12
|
+
console.log(' Server Path:', __dirname);
|
|
13
|
+
console.log(' UI Root Path:', ui_path);
|
|
14
|
+
console.log(' Document Path:', source_path, '\r\n');
|
|
15
15
|
|
|
16
16
|
// Get an express server instance
|
|
17
17
|
var app = express();
|
|
18
18
|
|
|
19
19
|
// In the root of the project there is a hdocbook.json file which includes
|
|
20
20
|
// the id of the hdocbook we are working with
|
|
21
|
-
const hdocbook_project_config_path = path.join(source_path,
|
|
21
|
+
const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
|
|
22
22
|
|
|
23
23
|
// Load the hdocbook config file
|
|
24
24
|
var hdocbook_project = require(hdocbook_project_config_path);
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
var docId = hdocbook_project.docId;
|
|
28
28
|
|
|
29
29
|
// Get the path of the book.json file
|
|
30
|
-
const hdocbook_path = path.join(source_path, docId,
|
|
30
|
+
const hdocbook_path = path.join(source_path, docId, 'hdocbook.json');
|
|
31
31
|
|
|
32
32
|
// Pull in the book config file
|
|
33
33
|
var hdocbook_config = require(hdocbook_path);
|
|
@@ -40,67 +40,67 @@
|
|
|
40
40
|
title: hdocbook_config.title
|
|
41
41
|
}]
|
|
42
42
|
};
|
|
43
|
-
res.setHeader(
|
|
43
|
+
res.setHeader('Content-Type', 'application/json');
|
|
44
44
|
res.send(JSON.stringify(library, null, 3));
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
function content_type_for_ext(ext) {
|
|
49
49
|
switch (ext) {
|
|
50
|
-
case
|
|
51
|
-
return
|
|
52
|
-
case
|
|
53
|
-
return
|
|
54
|
-
case
|
|
55
|
-
return
|
|
56
|
-
case
|
|
57
|
-
return
|
|
58
|
-
case
|
|
59
|
-
return
|
|
60
|
-
case
|
|
61
|
-
return
|
|
62
|
-
case
|
|
63
|
-
return
|
|
64
|
-
case
|
|
65
|
-
return
|
|
66
|
-
case
|
|
67
|
-
return
|
|
68
|
-
case
|
|
69
|
-
return
|
|
70
|
-
case
|
|
71
|
-
return
|
|
72
|
-
case
|
|
73
|
-
return
|
|
74
|
-
case
|
|
75
|
-
return
|
|
76
|
-
case
|
|
77
|
-
return
|
|
78
|
-
case
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
return
|
|
83
|
-
case
|
|
84
|
-
return
|
|
85
|
-
case
|
|
86
|
-
return
|
|
87
|
-
case
|
|
88
|
-
return
|
|
50
|
+
case '.z':
|
|
51
|
+
return 'application/x-compress';
|
|
52
|
+
case '.tgz':
|
|
53
|
+
return 'application/x-compressed';
|
|
54
|
+
case '.gz':
|
|
55
|
+
return 'application/x-gzip';
|
|
56
|
+
case '.zip':
|
|
57
|
+
return 'application/x-zip-compressed';
|
|
58
|
+
case '.xml':
|
|
59
|
+
return 'application/xml';
|
|
60
|
+
case '.bmp':
|
|
61
|
+
return 'image/bmp';
|
|
62
|
+
case '.gif':
|
|
63
|
+
return 'image/gif';
|
|
64
|
+
case '.jpg':
|
|
65
|
+
return 'image/jpeg';
|
|
66
|
+
case '.png':
|
|
67
|
+
return 'image/png';
|
|
68
|
+
case '.tiff':
|
|
69
|
+
return 'image/tiff';
|
|
70
|
+
case '.ico':
|
|
71
|
+
return 'image/x-icon';
|
|
72
|
+
case '.png':
|
|
73
|
+
return 'image/png';
|
|
74
|
+
case '.svg':
|
|
75
|
+
return 'image/svg+xml';
|
|
76
|
+
case '.css':
|
|
77
|
+
return 'text/css';
|
|
78
|
+
case '.htm':
|
|
79
|
+
case '.html':
|
|
80
|
+
return 'text/html';
|
|
81
|
+
case '.txt':
|
|
82
|
+
return 'text/plain';
|
|
83
|
+
case '.md':
|
|
84
|
+
return 'text/plain';
|
|
85
|
+
case '.json':
|
|
86
|
+
return 'application/json';
|
|
87
|
+
case '.js':
|
|
88
|
+
return 'application/javascript';
|
|
89
89
|
default:
|
|
90
|
-
return
|
|
90
|
+
return 'application/octet-stream';
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
function expand_variables(text) {
|
|
95
95
|
// For debug mode our base path is our root??
|
|
96
|
-
text = text.replaceAll(
|
|
97
|
-
text = text.replaceAll(
|
|
96
|
+
text = text.replaceAll('{{BASE_PATH}}', '/' + docId);
|
|
97
|
+
text = text.replaceAll('{{BUILD_NUMBER}}', '0');
|
|
98
98
|
|
|
99
99
|
let build_date = new Date().toISOString();
|
|
100
100
|
build_date = build_date.replace('T', ' ');
|
|
101
101
|
build_date = build_date.substring(0, 19);
|
|
102
102
|
|
|
103
|
-
text = text.replaceAll(
|
|
103
|
+
text = text.replaceAll('{{BUILD_DATE}}', build_date);
|
|
104
104
|
return text;
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
let md_txt = expand_variables(fs.readFileSync(file_path).toString());
|
|
115
115
|
|
|
116
116
|
// Render markdown into HTML
|
|
117
|
-
let frontmatter_content =
|
|
117
|
+
let frontmatter_content = '';
|
|
118
118
|
var html_txt = md.render(md_txt.toString());
|
|
119
119
|
|
|
120
120
|
if (frontmatter_content.length) {
|
|
@@ -125,10 +125,10 @@
|
|
|
125
125
|
|
|
126
126
|
const base64 = buff.toString('base64');
|
|
127
127
|
|
|
128
|
-
res.setHeader(
|
|
128
|
+
res.setHeader('X-frontmatter', base64);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
res.setHeader(
|
|
131
|
+
res.setHeader('Content-Type', 'text/html');
|
|
132
132
|
res.send(html_txt);
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
@@ -140,11 +140,11 @@
|
|
|
140
140
|
|
|
141
141
|
let contentType = content_type_for_ext(path.extname(file_path));
|
|
142
142
|
|
|
143
|
-
if (path.extname(file_path) ==
|
|
144
|
-
res.setHeader(
|
|
143
|
+
if (path.extname(file_path) == '.md') {
|
|
144
|
+
res.setHeader('Content-Disposition', 'inline');
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
res.setHeader(
|
|
147
|
+
res.setHeader('Content-Type', contentType);
|
|
148
148
|
|
|
149
149
|
res.send(content_txt);
|
|
150
150
|
}
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
function send_file(req, res, file_path) {
|
|
153
153
|
// Need to set the content type here??
|
|
154
154
|
let contentType = content_type_for_ext(path.extname(file_path));
|
|
155
|
-
res.setHeader(
|
|
155
|
+
res.setHeader('Content-Type', contentType);
|
|
156
156
|
|
|
157
157
|
const r = fs.createReadStream(file_path);
|
|
158
158
|
const ps = new stream.PassThrough();
|
|
@@ -162,15 +162,15 @@
|
|
|
162
162
|
(err) => {
|
|
163
163
|
if (err) {
|
|
164
164
|
console.log(err); // No such file or any other kind of error
|
|
165
|
-
return res.sendStatus(400).send(
|
|
165
|
+
return res.sendStatus(400).send('Unexpected error');
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
ps.pipe(res);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
function send_content_resource_404(req, res) {
|
|
172
|
-
res.setHeader(
|
|
173
|
-
res.status(404).send(
|
|
172
|
+
res.setHeader('Content-Type', 'text/html');
|
|
173
|
+
res.status(404).send('Content resource not found');
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
// 1. If we request a file with a .html file extension, and that file DOES NOT exist,
|
|
@@ -199,19 +199,19 @@
|
|
|
199
199
|
|
|
200
200
|
let segs = url.split('/');
|
|
201
201
|
|
|
202
|
-
if (segs.length == 4 && segs[1] ==
|
|
202
|
+
if (segs.length == 4 && segs[1] == 'content' && segs[3] == 'book.json') {
|
|
203
203
|
// Special case of a virtual file here, we need to check the book ID and
|
|
204
204
|
// if its our book, send the json
|
|
205
205
|
if (hdocbook_config.docId == segs[2]) {
|
|
206
|
-
res.setHeader(
|
|
206
|
+
res.setHeader('Content-Type', 'application/json');
|
|
207
207
|
res.send(JSON.stringify(hdocbook_config, null, 3));
|
|
208
208
|
} else {
|
|
209
209
|
// Return a 404 error here
|
|
210
|
-
res.setHeader(
|
|
211
|
-
res.status(404).send(
|
|
210
|
+
res.setHeader('Content-Type', 'text/html');
|
|
211
|
+
res.status(404).send('Specified bookId ' + segs[2] + ' not found');
|
|
212
212
|
}
|
|
213
213
|
return;
|
|
214
|
-
} else if (segs.length == 3 && segs[1] ==
|
|
214
|
+
} else if (segs.length == 3 && segs[1] == 'content' && segs[2] == 'index.json') {
|
|
215
215
|
// For development mode, we always have an index with one book in it, the one being developed
|
|
216
216
|
if (hdocbook_config) {
|
|
217
217
|
let index = {
|
|
@@ -222,28 +222,28 @@
|
|
|
222
222
|
version: hdocbook_config.version
|
|
223
223
|
}]
|
|
224
224
|
};
|
|
225
|
-
res.setHeader(
|
|
225
|
+
res.setHeader('Content-Type', 'application/json');
|
|
226
226
|
res.send(JSON.stringify(index, null, 3));
|
|
227
227
|
} else {
|
|
228
228
|
// Return a 404 error here
|
|
229
|
-
res.setHeader(
|
|
230
|
-
res.status(404).send(
|
|
229
|
+
res.setHeader('Content-Type', 'text/html');
|
|
230
|
+
res.status(404).send('Specified bookId ' + segs[2] + ' not found');
|
|
231
231
|
}
|
|
232
232
|
return;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
url = url.replace(
|
|
235
|
+
url = url.replace('/content/', '/');
|
|
236
236
|
|
|
237
|
-
console.log(
|
|
237
|
+
console.log('URL Requested:', url);
|
|
238
238
|
|
|
239
239
|
let file_path = path.join(source_path, url);
|
|
240
240
|
let ui_file_path = path.join(ui_path, url);
|
|
241
241
|
|
|
242
242
|
// If the requested file is found in the UI folder
|
|
243
|
-
if (url ==
|
|
244
|
-
if (fs.existsSync(path.join(ui_file_path,
|
|
243
|
+
if (url == '/') {
|
|
244
|
+
if (fs.existsSync(path.join(ui_file_path, 'index.html'))) {
|
|
245
245
|
// We want the index.html, send it here
|
|
246
|
-
send_file(req, res, path.join(ui_file_path,
|
|
246
|
+
send_file(req, res, path.join(ui_file_path, 'index.html'));
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
249
|
// Return a 404 error here
|
|
@@ -255,21 +255,21 @@
|
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
if (path.extname(file_path) ==
|
|
258
|
+
if (path.extname(file_path) == '.html') {
|
|
259
259
|
// 1a. check for html files, and send/transform as required
|
|
260
260
|
if (fs.existsSync(file_path)) {
|
|
261
261
|
// HTML file exists on disk, just return it verbatim
|
|
262
|
-
res.setHeader(
|
|
262
|
+
res.setHeader('Content-Type', 'text/html');
|
|
263
263
|
send_file(req, res, file_path);
|
|
264
264
|
return true;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
if (fs.existsSync(file_path.replace(
|
|
268
|
-
if (transform_markdown_and_send_html(req, res, file_path.replace(
|
|
267
|
+
if (fs.existsSync(file_path.replace('.html', '.md'))) {
|
|
268
|
+
if (transform_markdown_and_send_html(req, res, file_path.replace('.html', '.md'))) {
|
|
269
269
|
return;
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
} else if (path.extname(file_path) ==
|
|
272
|
+
} else if (path.extname(file_path) == '.md') {
|
|
273
273
|
// If the markdown file exists, just send to caller as is
|
|
274
274
|
if (fs.existsSync(file_path)) {
|
|
275
275
|
send_content_file(req, res, file_path);
|
|
@@ -277,25 +277,25 @@
|
|
|
277
277
|
}
|
|
278
278
|
} else if (path.extname(file_path).length == 0) {
|
|
279
279
|
// 2. If we request a file, without any file extension
|
|
280
|
-
if (fs.existsSync(file_path +
|
|
281
|
-
if (transform_markdown_and_send_html(req, res, file_path +
|
|
280
|
+
if (fs.existsSync(file_path + '.md')) {
|
|
281
|
+
if (transform_markdown_and_send_html(req, res, file_path + '.md')) {
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
284
|
-
} else if (fs.existsSync(path.join(file_path +
|
|
285
|
-
if (transform_markdown_and_send_html(req, res, path.join(file_path,
|
|
284
|
+
} else if (fs.existsSync(path.join(file_path + 'index.md'))) {
|
|
285
|
+
if (transform_markdown_and_send_html(req, res, path.join(file_path, 'index.md'))) {
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
|
-
} else if (fs.existsSync(path.join(file_path +
|
|
289
|
-
res.setHeader(
|
|
290
|
-
send_content_file(req, res, path.join(file_path +
|
|
288
|
+
} else if (fs.existsSync(path.join(file_path + 'index.html'))) {
|
|
289
|
+
res.setHeader('Content-Type', 'text/html');
|
|
290
|
+
send_content_file(req, res, path.join(file_path + 'index.html'));
|
|
291
291
|
return;
|
|
292
|
-
} else if (fs.existsSync(file_path +
|
|
293
|
-
if (transform_markdown_and_send_html(req, res, file_path +
|
|
292
|
+
} else if (fs.existsSync(file_path + '/index.md')) {
|
|
293
|
+
if (transform_markdown_and_send_html(req, res, file_path + '/index.md')) {
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
|
-
} else if (fs.existsSync(path.join(file_path +
|
|
297
|
-
res.setHeader(
|
|
298
|
-
send_content_file(req, res, path.join(file_path +
|
|
296
|
+
} else if (fs.existsSync(path.join(file_path + '/index.html'))) {
|
|
297
|
+
res.setHeader('Content-Type', 'text/html');
|
|
298
|
+
send_content_file(req, res, path.join(file_path + '/index.html'));
|
|
299
299
|
return;
|
|
300
300
|
}
|
|
301
301
|
} else if (fs.existsSync(file_path)) {
|
|
@@ -312,11 +312,11 @@
|
|
|
312
312
|
|
|
313
313
|
let segs = req.url.split('/');
|
|
314
314
|
|
|
315
|
-
if (segs.length > 3 && segs[2] ==
|
|
315
|
+
if (segs.length > 3 && segs[2] == 'content') {
|
|
316
316
|
// In this case we are looking for static content within the book
|
|
317
317
|
|
|
318
318
|
// Create the file path
|
|
319
|
-
let url = req.url.replace(
|
|
319
|
+
let url = req.url.replace('/content/', '/');
|
|
320
320
|
let file_path = path.join(source_path, url);
|
|
321
321
|
|
|
322
322
|
// If the file exists, send it.
|
|
@@ -332,12 +332,12 @@
|
|
|
332
332
|
|
|
333
333
|
let ui_file_path = path.join(ui_path, req.url);
|
|
334
334
|
|
|
335
|
-
console.log(
|
|
335
|
+
console.log('URL Root:', req.url);
|
|
336
336
|
|
|
337
337
|
// To support the SPA application behavior, if there is no file extension present, then
|
|
338
338
|
// we simply return the /index.html file content to the client
|
|
339
339
|
if (path.extname(ui_file_path).length == 0) {
|
|
340
|
-
send_content_file(req, res, path.join(ui_path,
|
|
340
|
+
send_content_file(req, res, path.join(ui_path, 'index.html'));
|
|
341
341
|
return;
|
|
342
342
|
}
|
|
343
343
|
|
|
@@ -351,12 +351,12 @@
|
|
|
351
351
|
send_content_resource_404(req, res);
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
-
var server = app.listen(3000,
|
|
354
|
+
var server = app.listen(3000, '0.0.0.0', function () {
|
|
355
355
|
var host = server.address().address;
|
|
356
356
|
var port = server.address().port;
|
|
357
357
|
|
|
358
|
-
console.log(
|
|
359
|
-
console.log(
|
|
358
|
+
console.log('Server listening at http://%s:%s', host, port);
|
|
359
|
+
console.log('Document source path is: ' + source_path);
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
};
|
package/hdoc-stats.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
// Required modules
|
|
6
|
-
const { STATUS_CODES } = require('http');
|
|
6
|
+
// /const { STATUS_CODES } = require('http');
|
|
7
7
|
const fs = require('fs');
|
|
8
|
+
var path = require('path');
|
|
8
9
|
const dree = require('dree');
|
|
9
10
|
const html2text = require('html-to-text');
|
|
10
11
|
const { markdownToTxt } = require('markdown-to-txt');
|
|
@@ -82,18 +83,20 @@
|
|
|
82
83
|
//
|
|
83
84
|
// For each .md file, and for each static .HTML file (that is html files that we have not generated) we
|
|
84
85
|
// should do a word count, excluding MD or HTML tags
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
// STEVE: Get the docId (book root) from the hdocbook-project.json
|
|
88
88
|
// From there, loop through looking for:
|
|
89
89
|
// * HTML files without a matching MD, and word count those
|
|
90
90
|
// * MD files, and word count those
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
|
|
93
|
+
console.log('Hornbill HDocBook Stats', '\r\n');
|
|
94
|
+
|
|
95
|
+
const project_json_path = path.join(source_path, 'hdocbook-project.json');
|
|
93
96
|
|
|
94
97
|
if (!fs.existsSync(project_json_path)) {
|
|
95
98
|
// Book config does not exist
|
|
96
|
-
console.error('Required project file does not exist:
|
|
99
|
+
console.error('Required project file does not exist:', project_json_path);
|
|
97
100
|
return;
|
|
98
101
|
} else {
|
|
99
102
|
// Book config exists - load book details
|
|
@@ -101,53 +104,71 @@
|
|
|
101
104
|
try {
|
|
102
105
|
book_details = JSON.parse(fs.readFileSync(project_json_path, 'utf8'));
|
|
103
106
|
} catch (e) {
|
|
104
|
-
console.error('Error reading book configuration
|
|
107
|
+
console.error('Error reading book configuration:\r\n', e);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const bookPath = path.join(source_path, book_details.docId);
|
|
111
|
+
|
|
112
|
+
//Load book config
|
|
113
|
+
let bookConfig;
|
|
114
|
+
try {
|
|
115
|
+
bookConfig = JSON.parse(fs.readFileSync(path.join(bookPath, 'hdocbook.json'), 'utf8'));
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.error('Could not load book configuration:\r\n', e);
|
|
105
118
|
return;
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
// Scan content path directory, send file info to callback for processing
|
|
109
|
-
dree.scan(
|
|
122
|
+
dree.scan(bookPath, dreeOptions, fileCallback);
|
|
110
123
|
|
|
111
124
|
if (verbose) {
|
|
112
125
|
// Output verbose stats
|
|
113
126
|
|
|
114
127
|
// Output information about all markdown files in the book
|
|
115
|
-
console.log('
|
|
116
|
-
console.log(' Markdown ');
|
|
117
|
-
console.log('
|
|
128
|
+
console.log('--------------------');
|
|
129
|
+
console.log(' Markdown Files ');
|
|
130
|
+
console.log('--------------------\r\n');
|
|
118
131
|
if (stats.totalMDFiles === 0) {
|
|
119
|
-
console.log('
|
|
132
|
+
console.log('No markdown files found.\r\n');
|
|
120
133
|
} else {
|
|
121
134
|
for (const key in stats.mdFiles) {
|
|
122
135
|
if (stats.mdFiles.hasOwnProperty(key)) {
|
|
123
|
-
console.log('Relative Path:
|
|
124
|
-
console.log(' Word Count:
|
|
125
|
-
console.log('File Size (B):
|
|
136
|
+
console.log('Relative Path:', key);
|
|
137
|
+
console.log(' Word Count:', stats.mdFiles[key].wordCount);
|
|
138
|
+
console.log('File Size (B):', stats.mdFiles[key].sizeInBytes, '\r\n');
|
|
126
139
|
}
|
|
127
140
|
}
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
// Output information about all static HTML in the book
|
|
131
|
-
console.log('
|
|
132
|
-
console.log('
|
|
133
|
-
console.log('
|
|
144
|
+
console.log('-----------------------');
|
|
145
|
+
console.log(' Static HTML Files ');
|
|
146
|
+
console.log('-----------------------\r\n');
|
|
134
147
|
if (stats.totalStaticHTMLFiles === 0) {
|
|
135
|
-
console.log('No static HTML files found
|
|
148
|
+
console.log('No static HTML files found.\r\n');
|
|
136
149
|
} else {
|
|
137
150
|
for (const key in stats.staticHTMLFiles) {
|
|
138
151
|
if (stats.staticHTMLFiles.hasOwnProperty(key)) {
|
|
139
|
-
console.log('Relative Path:
|
|
140
|
-
console.log(' Word Count:
|
|
141
|
-
console.log('File Size (B):
|
|
152
|
+
console.log('Relative Path:', key);
|
|
153
|
+
console.log(' Word Count:', stats.staticHTMLFiles[key].wordCount);
|
|
154
|
+
console.log('File Size (B):', stats.staticHTMLFiles[key].sizeInBytes, '\r\n');
|
|
142
155
|
}
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
159
|
|
|
147
160
|
// Output stats
|
|
148
|
-
console.log('
|
|
149
|
-
console.log('
|
|
150
|
-
console.log('
|
|
161
|
+
console.log('----------------------');
|
|
162
|
+
console.log(' Book Information ');
|
|
163
|
+
console.log('----------------------\r\n');
|
|
164
|
+
console.log(' Document ID:', bookConfig.docId);
|
|
165
|
+
console.log(' Version:', bookConfig.version, '\r\n');
|
|
166
|
+
console.log(' Title:', bookConfig.title);
|
|
167
|
+
console.log(' Description:', bookConfig.description);
|
|
168
|
+
console.log(' Public Source:', bookConfig.publicSource, '\r\n');
|
|
169
|
+
console.log('Total Book Word Count:', stats.totalWordCount);
|
|
170
|
+
console.log(' Markdown Files:', stats.totalMDFiles);
|
|
171
|
+
console.log(' Static HTML Files:', stats.totalStaticHTMLFiles, '\r\n');
|
|
151
172
|
|
|
152
173
|
}
|
|
153
174
|
};
|
package/hdoc.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const { createCipheriv } = require('crypto');
|
|
4
|
+
|
|
3
5
|
(function () {
|
|
4
6
|
'use strict';
|
|
5
7
|
|
|
@@ -28,6 +30,19 @@
|
|
|
28
30
|
frontmatter_content = fm;
|
|
29
31
|
});
|
|
30
32
|
|
|
33
|
+
const packageFile = path.join(__dirname, 'package.json');
|
|
34
|
+
const getHdocPackageVersion = function (packagePath) {
|
|
35
|
+
if (fs.existsSync(packagePath)) {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(fs.readFileSync(packagePath, 'utf8')).version;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error('Could not parse package file: ', packagePath, ' - ', JSON.stringify(e));
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
console.error('Package file not found: ', packagePath);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
31
46
|
const tips = require(__dirname + '/custom_modules/tips.js');
|
|
32
47
|
|
|
33
48
|
md.use(tips, {
|
|
@@ -36,9 +51,9 @@
|
|
|
36
51
|
|
|
37
52
|
// Default source path to working directory
|
|
38
53
|
let source_path = process.cwd();
|
|
39
|
-
let ui_path = path.join(__dirname,
|
|
54
|
+
let ui_path = path.join(__dirname, 'ui');
|
|
40
55
|
|
|
41
|
-
let command =
|
|
56
|
+
let command = ''; // Our command to run
|
|
42
57
|
let verbose = false;
|
|
43
58
|
|
|
44
59
|
// Get options from command args
|
|
@@ -52,40 +67,44 @@
|
|
|
52
67
|
continue;
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
if (process.argv[x] ==
|
|
70
|
+
if (process.argv[x] == '-path') {
|
|
56
71
|
x++;
|
|
57
72
|
if (x < process.argv.length) {
|
|
58
73
|
source_path = process.argv[x];
|
|
59
74
|
}
|
|
60
|
-
} else if (process.argv[x] ==
|
|
75
|
+
} else if (process.argv[x] == '-ui-path') {
|
|
61
76
|
x++;
|
|
62
77
|
if (x < process.argv.length) {
|
|
63
78
|
ui_path = process.argv[x];
|
|
64
79
|
}
|
|
65
80
|
}
|
|
66
81
|
|
|
67
|
-
if (process.argv[x] ===
|
|
82
|
+
if (process.argv[x] === '-v') {
|
|
68
83
|
verbose = true;
|
|
69
84
|
}
|
|
70
85
|
}
|
|
71
86
|
|
|
72
|
-
console.log(
|
|
73
|
-
console.log(
|
|
74
|
-
console.log(
|
|
87
|
+
console.log('Hornbill HDocBook Tools v', getHdocPackageVersion(packageFile), '\r\n');
|
|
88
|
+
console.log(' Server Path:', __dirname);
|
|
89
|
+
console.log(' Document Path:', source_path, '\r\n');
|
|
75
90
|
|
|
76
|
-
if (command ==
|
|
77
|
-
const server = require(path.join(__dirname,
|
|
91
|
+
if (command == 'serve') {
|
|
92
|
+
const server = require(path.join(__dirname, 'hdoc-serve.js'));
|
|
78
93
|
server.run(ui_path, source_path, md);
|
|
79
|
-
} else if (command ==
|
|
80
|
-
const builder = require(path.join(__dirname,
|
|
94
|
+
} else if (command == 'build') {
|
|
95
|
+
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
|
81
96
|
builder.run(ui_path, source_path, md);
|
|
82
|
-
} else if (command ==
|
|
83
|
-
const stats = require(path.join(__dirname,
|
|
97
|
+
} else if (command == 'stats') {
|
|
98
|
+
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
|
84
99
|
stats.run(ui_path, source_path, md, verbose);
|
|
85
|
-
} else if (command ==
|
|
86
|
-
const init = require(path.join(__dirname,
|
|
100
|
+
} else if (command == 'init') {
|
|
101
|
+
const init = require(path.join(__dirname, 'hdoc-init.js'));
|
|
87
102
|
init.run(ui_path, source_path, md);
|
|
103
|
+
} else if (command == 'help') {
|
|
104
|
+
const init = require(path.join(__dirname, 'hdoc-help.js'));
|
|
105
|
+
init.run();
|
|
88
106
|
} else {
|
|
89
|
-
console.log(
|
|
107
|
+
console.log('Unknown command:', command, '\r\n');
|
|
108
|
+
console.log('Run hdoc help for information regarding this tool.\r\n');
|
|
90
109
|
}
|
|
91
110
|
})();
|