hdoc-tools 0.19.7 → 0.20.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/custom_modules/tips.js +88 -86
- package/hdoc-build-db.js +260 -198
- package/hdoc-build-pdf.js +219 -173
- package/hdoc-build.js +1480 -1503
- package/hdoc-bump.js +123 -109
- package/hdoc-create.js +108 -95
- package/hdoc-db.js +97 -125
- package/hdoc-help.js +48 -51
- package/hdoc-init.js +181 -147
- package/hdoc-module.js +708 -723
- package/hdoc-serve.js +390 -361
- package/hdoc-stats.js +187 -184
- package/hdoc-validate.js +956 -717
- package/hdoc-ver.js +43 -43
- package/hdoc.js +142 -124
- package/package.json +60 -60
- package/templates/init/_hdocbook/hdocbook.json +23 -23
- package/templates/init/hdocbook-project.json +10 -10
- package/templates/init/package.json +8 -10
- package/ui/js/doc.hornbill.js +708 -659
- package/validateNodeVer.js +17 -14
package/hdoc-stats.js
CHANGED
@@ -1,184 +1,187 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
1
|
+
(() => {
|
2
|
+
// Required modules
|
3
|
+
const fs = require("node:fs");
|
4
|
+
const path = require("node:path");
|
5
|
+
const dree = require("dree");
|
6
|
+
const html2text = require("html-to-text");
|
7
|
+
const wordsCount = require("words-count").default;
|
8
|
+
|
9
|
+
// Regex to remove Hornbill-specific tags
|
10
|
+
const hbMDTagRegex =
|
11
|
+
/(:{3}[ ]note)|(:{3}[ ]tip)|(:{3}[ ]important)|(:{3}[ ]caution)|(:{3}[ ]warning)|(:{3})/g;
|
12
|
+
|
13
|
+
const stats = {
|
14
|
+
totalMDFiles: 0,
|
15
|
+
totalStaticHTMLFiles: 0,
|
16
|
+
totalWordCount: 0,
|
17
|
+
mdFiles: {},
|
18
|
+
staticHTMLFiles: {},
|
19
|
+
};
|
20
|
+
|
21
|
+
const markdownFiles = [];
|
22
|
+
|
23
|
+
// File callback for scan
|
24
|
+
const fileCallback = (element) => {
|
25
|
+
if (element.extension === "md") {
|
26
|
+
markdownFiles.push(element);
|
27
|
+
stats.totalMDFiles++;
|
28
|
+
} else {
|
29
|
+
// file must be html
|
30
|
+
const mdFilePath = `${element.path.slice(0, element.path.lastIndexOf("."))}.md`;
|
31
|
+
//Do we have a matching MD file - if not, then word count the HTML
|
32
|
+
if (!fs.existsSync(mdFilePath)) {
|
33
|
+
stats.totalStaticHTMLFiles++;
|
34
|
+
const html = fs.readFileSync(element.path, "utf8");
|
35
|
+
const text = html2text.convert(html, {
|
36
|
+
wordwrap: null,
|
37
|
+
});
|
38
|
+
const wordCount = wordsCount(text);
|
39
|
+
stats.totalWordCount += wordCount;
|
40
|
+
stats.staticHTMLFiles[element.relativePath] = {
|
41
|
+
wordCount: wordCount,
|
42
|
+
sizeInBytes: element.sizeInBytes,
|
43
|
+
};
|
44
|
+
}
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
48
|
+
const dreeOptions = {
|
49
|
+
descendants: true,
|
50
|
+
depth: 10,
|
51
|
+
extensions: ["md", "html", "htm"],
|
52
|
+
hash: false,
|
53
|
+
normalize: true,
|
54
|
+
size: true,
|
55
|
+
sizeInBytes: true,
|
56
|
+
stat: false,
|
57
|
+
symbolicLinks: false,
|
58
|
+
};
|
59
|
+
|
60
|
+
exports.run = (ui_path, source_path, verbose = false) => {
|
61
|
+
// GERRY: The stats here are needed to support content development. The idea is to count all of the ]
|
62
|
+
// words in a HDocBook so we know the size of the book, this helps with 3rd party involvement where
|
63
|
+
// we generally need to know the word count of the content in order to get a quote for things like
|
64
|
+
// copy editing. reviewing and translations.
|
65
|
+
//
|
66
|
+
// For each .md file, and for each static .HTML file (that is html files that we have not generated) we
|
67
|
+
// should do a word count, excluding MD or HTML tags
|
68
|
+
|
69
|
+
// STEVE: Get the docId (book root) from the hdocbook-project.json
|
70
|
+
// From there, loop through looking for:
|
71
|
+
// * HTML files without a matching MD, and word count those
|
72
|
+
// * MD files, and word count those
|
73
|
+
|
74
|
+
console.log(`Hornbill HDocBook Stats : verbose=${verbose}\r\n`);
|
75
|
+
|
76
|
+
const project_json_path = path.join(source_path, "hdocbook-project.json");
|
77
|
+
|
78
|
+
if (!fs.existsSync(project_json_path)) {
|
79
|
+
// Book config does not exist
|
80
|
+
console.error("Required project file does not exist:", project_json_path);
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
// Book config exists - load book details
|
84
|
+
let book_details;
|
85
|
+
try {
|
86
|
+
book_details = JSON.parse(fs.readFileSync(project_json_path, "utf8"));
|
87
|
+
} catch (e) {
|
88
|
+
console.error("Error reading book configuration:\r\n", e);
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
const bookPath = path.join(source_path, book_details.docId);
|
92
|
+
|
93
|
+
//Load book config
|
94
|
+
let bookConfig;
|
95
|
+
try {
|
96
|
+
bookConfig = JSON.parse(
|
97
|
+
fs.readFileSync(path.join(bookPath, "hdocbook.json"), "utf8"),
|
98
|
+
);
|
99
|
+
} catch (e) {
|
100
|
+
console.error("Could not load book configuration:\r\n", e);
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
// Load markdown-it module
|
104
|
+
const md = require("markdown-it")({
|
105
|
+
html: true,
|
106
|
+
linkify: true,
|
107
|
+
typographer: true,
|
108
|
+
});
|
109
|
+
|
110
|
+
// Scan content path directory, send file info to callback for processing
|
111
|
+
dree.scan(bookPath, dreeOptions, fileCallback);
|
112
|
+
for (const element of markdownFiles) {
|
113
|
+
// Load markdown file
|
114
|
+
const md_txt = fs.readFileSync(element.path, "utf8");
|
115
|
+
|
116
|
+
const html_txt = md.render(md_txt.toString());
|
117
|
+
const text = html2text.convert(html_txt, {
|
118
|
+
wordwrap: null,
|
119
|
+
});
|
120
|
+
|
121
|
+
// Do the wordcount and add to status
|
122
|
+
const wordCount = wordsCount(text);
|
123
|
+
stats.totalWordCount += wordCount;
|
124
|
+
stats.mdFiles[element.relativePath] = {
|
125
|
+
wordCount: wordCount,
|
126
|
+
sizeInBytes: element.sizeInBytes,
|
127
|
+
};
|
128
|
+
}
|
129
|
+
|
130
|
+
if (verbose) {
|
131
|
+
// Output verbose stats
|
132
|
+
|
133
|
+
// Output information about all markdown files in the book
|
134
|
+
console.log("--------------------");
|
135
|
+
console.log(" Markdown Files ");
|
136
|
+
console.log("--------------------\r\n");
|
137
|
+
if (stats.totalMDFiles === 0) {
|
138
|
+
console.log("No markdown files found.\r\n");
|
139
|
+
} else {
|
140
|
+
for (const key in stats.mdFiles) {
|
141
|
+
if (Object.hasOwn(stats.mdFiles, key)) {
|
142
|
+
console.log("Relative Path:", key);
|
143
|
+
console.log(" Word Count:", stats.mdFiles[key].wordCount);
|
144
|
+
console.log(
|
145
|
+
"File Size (B):",
|
146
|
+
stats.mdFiles[key].sizeInBytes,
|
147
|
+
"\r\n",
|
148
|
+
);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
// Output information about all static HTML in the book
|
154
|
+
console.log("-----------------------");
|
155
|
+
console.log(" Static HTML Files ");
|
156
|
+
console.log("-----------------------\r\n");
|
157
|
+
if (stats.totalStaticHTMLFiles === 0) {
|
158
|
+
console.log("No static HTML files found.\r\n");
|
159
|
+
} else {
|
160
|
+
for (const key in stats.staticHTMLFiles) {
|
161
|
+
if (Object.hasOwn(stats.staticHTMLFiles, key)) {
|
162
|
+
console.log("Relative Path:", key);
|
163
|
+
console.log(" Word Count:", stats.staticHTMLFiles[key].wordCount);
|
164
|
+
console.log(
|
165
|
+
"File Size (B):",
|
166
|
+
stats.staticHTMLFiles[key].sizeInBytes,
|
167
|
+
"\r\n",
|
168
|
+
);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
// Output stats
|
175
|
+
console.log("----------------------");
|
176
|
+
console.log(" Book Information ");
|
177
|
+
console.log("----------------------\r\n");
|
178
|
+
console.log(" Document ID:", bookConfig.docId);
|
179
|
+
console.log(" Version:", bookConfig.version, "\r\n");
|
180
|
+
console.log(" Title:", bookConfig.title);
|
181
|
+
console.log(" Description:", bookConfig.description);
|
182
|
+
console.log(" Public Source:", bookConfig.publicSource, "\r\n");
|
183
|
+
console.log("Total Book Word Count:", stats.totalWordCount);
|
184
|
+
console.log(" Markdown Files:", stats.totalMDFiles);
|
185
|
+
console.log(" Static HTML Files:", stats.totalStaticHTMLFiles, "\r\n");
|
186
|
+
};
|
187
|
+
})();
|