hdoc-tools 0.8.49 → 0.9.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/hdoc-build-db.js +4 -4
- package/hdoc-build.js +18 -15
- package/hdoc-db.js +1 -1
- package/hdoc-validate.js +80 -5
- package/hdoc.js +5 -2
- package/package.json +2 -1
package/hdoc-build-db.js
CHANGED
@@ -69,7 +69,7 @@
|
|
69
69
|
return response;
|
70
70
|
};
|
71
71
|
|
72
|
-
exports.populate_index = function (db, doc_id, book_config, index_records, verbose = false) {
|
72
|
+
exports.populate_index = async function (db, doc_id, book_config, index_records, verbose = false) {
|
73
73
|
let response = {
|
74
74
|
success: false,
|
75
75
|
index_success_count: 0,
|
@@ -91,7 +91,7 @@
|
|
91
91
|
index_records[i].index_html.preview,
|
92
92
|
book_config.productFamily
|
93
93
|
];
|
94
|
-
const index_response = hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
|
94
|
+
const index_response = await hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
|
95
95
|
if (!index_response.success) {
|
96
96
|
console.log(`Index record creation failed - ${doc_id}/${index_records[i].index_html.fm_props.title}: ${index_response.error}`);
|
97
97
|
continue;
|
@@ -106,7 +106,7 @@
|
|
106
106
|
index_records[i].metadata.last_commit,
|
107
107
|
index_records[i].pdf_size
|
108
108
|
];
|
109
|
-
const meta_response = hdoc_index.insert_record(db, 'hdoc_meta', db_schema.hdoc_meta, meta_vals);
|
109
|
+
const meta_response = await hdoc_index.insert_record(db, 'hdoc_meta', db_schema.hdoc_meta, meta_vals);
|
110
110
|
if (!meta_response.success) {
|
111
111
|
console.log(`Index metadata record creation failed - ${doc_id}/${index_response.row_id}/${index_records[i].index_html.fm_props.title}: ${meta_response.error}`);
|
112
112
|
continue;
|
@@ -126,7 +126,7 @@
|
|
126
126
|
index_records[i].contributors[j].avatar_url,
|
127
127
|
index_records[i].contributors[j].html_url
|
128
128
|
];
|
129
|
-
const cont_response = hdoc_index.insert_record(db, 'hdoc_contributors', db_schema.hdoc_contributors, contrib_vals);
|
129
|
+
const cont_response = await hdoc_index.insert_record(db, 'hdoc_contributors', db_schema.hdoc_contributors, contrib_vals);
|
130
130
|
if (!cont_response.success) {
|
131
131
|
console.log(`Index document contributor record creation failed - ${doc_id}/${index_response.row_id}/${index_records[i].index_html.fm_props.title}: ${cont_response.error}`);
|
132
132
|
continue;
|
package/hdoc-build.js
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
mdfm = require('markdown-it-front-matter'),
|
8
8
|
path = require('path'),
|
9
9
|
URL = require("url").URL,
|
10
|
-
|
10
|
+
hdoc_validate = require(path.join(__dirname, 'hdoc-validate.js')),
|
11
11
|
hdoc = require(path.join(__dirname, 'hdoc-module.js')),
|
12
12
|
hdoc_build_db = require(path.join(__dirname, 'hdoc-build-db.js')),
|
13
13
|
hdoc_build_pdf = require(path.join(__dirname, 'hdoc-build-pdf.js')),
|
@@ -667,11 +667,12 @@
|
|
667
667
|
}
|
668
668
|
};
|
669
669
|
|
670
|
-
exports.run = async function (source_path, verbose_output, github_api_token) {
|
670
|
+
exports.run = async function (source_path, verbose_output, github_api_token, validate) {
|
671
671
|
if (github_api_token !== '') {
|
672
672
|
git_token = github_api_token;
|
673
673
|
}
|
674
674
|
verbose = verbose_output;
|
675
|
+
|
675
676
|
// GERRY: The purpose of this function is to create a zip file containing the hdocbook content,
|
676
677
|
// * Create a _work folder
|
677
678
|
// * copy the hdocbook content to the work folder
|
@@ -691,7 +692,8 @@
|
|
691
692
|
const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
|
692
693
|
hdocbook_project = require(hdocbook_project_config_path);
|
693
694
|
doc_id = hdocbook_project.docId;
|
694
|
-
|
695
|
+
|
696
|
+
if (!validate && hdocbook_project.pdfGeneration !== undefined && hdocbook_project.pdfGeneration.enable !== undefined) {
|
695
697
|
pdf_enable = hdocbook_project.pdfGeneration.enable;
|
696
698
|
}
|
697
699
|
|
@@ -791,7 +793,7 @@
|
|
791
793
|
console.log(` Static HTML Files Found: ${static_html_files.length}\n`);
|
792
794
|
|
793
795
|
// Validate content
|
794
|
-
const validation_success = await
|
796
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project);
|
795
797
|
if (!validation_success) {
|
796
798
|
process.exit(1);
|
797
799
|
}
|
@@ -814,22 +816,23 @@
|
|
814
816
|
process.exit(1);
|
815
817
|
}
|
816
818
|
|
817
|
-
const index = hdoc_build_db.populate_index(db.db, doc_id, hdocbook_config, index_records, verbose);
|
819
|
+
const index = await hdoc_build_db.populate_index(db.db, doc_id, hdocbook_config, index_records, verbose);
|
818
820
|
if (!index.success) {
|
819
821
|
console.log(index.error);
|
820
822
|
process.exit(1);
|
821
823
|
}
|
822
824
|
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
825
|
+
if (!validate) {
|
826
|
+
try {
|
827
|
+
const zip_path = path.join(work_path, doc_id + '.zip');
|
828
|
+
await zip(work_path_content, zip_path);
|
829
|
+
console.log(`\nZIP Creation Success: ${zip_path}\n`);
|
830
|
+
console.log(' Build Started:', build_start_dt);
|
831
|
+
console.log(`Build Completed: ${new Date().toLocaleString()}\n`);
|
832
|
+
|
833
|
+
} catch (e) {
|
834
|
+
console.log('\nError creating ZIP: ' + e);
|
835
|
+
}
|
832
836
|
}
|
833
|
-
|
834
837
|
};
|
835
838
|
})();
|
package/hdoc-db.js
CHANGED
package/hdoc-validate.js
CHANGED
@@ -5,13 +5,17 @@
|
|
5
5
|
cheerio = require('cheerio'),
|
6
6
|
dree = require('dree'),
|
7
7
|
fs = require('fs'),
|
8
|
+
html2text = require('html-to-text'),
|
8
9
|
https = require('https'),
|
9
10
|
path = require('path'),
|
10
|
-
hdoc = require(path.join(__dirname, 'hdoc-module.js'))
|
11
|
+
hdoc = require(path.join(__dirname, 'hdoc-module.js')),
|
12
|
+
translator = require('american-british-english-translator');
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
const agent = new https.Agent({
|
15
|
+
rejectUnauthorized: false
|
16
|
+
});
|
17
|
+
|
18
|
+
let prod_families = {};
|
15
19
|
|
16
20
|
let errors = {},
|
17
21
|
messages = {},
|
@@ -20,6 +24,48 @@
|
|
20
24
|
html_files = [],
|
21
25
|
exclude_links = {};
|
22
26
|
|
27
|
+
const load_product_families = async function() {
|
28
|
+
try {
|
29
|
+
const prods = await axios.get('https://docs.hornbill.com/_books/products.json', { httpsAgent: agent });
|
30
|
+
if (prods.status === 200) {
|
31
|
+
prod_families = prods.data;
|
32
|
+
} else {
|
33
|
+
throw `Unexpected Status ${prods.status}`;
|
34
|
+
}
|
35
|
+
} catch (e) {
|
36
|
+
// Handle errors
|
37
|
+
console.log(`Error returning product families: ${e}`);
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
return true;
|
41
|
+
};
|
42
|
+
|
43
|
+
const checkBritishSpellings = async function (htmlFile) {
|
44
|
+
const htmlBody = fs.readFileSync(htmlFile.path, 'utf8');
|
45
|
+
const text = html2text.convert(htmlBody, {
|
46
|
+
wordwrap: null
|
47
|
+
});
|
48
|
+
|
49
|
+
var options = {
|
50
|
+
british: true,
|
51
|
+
spelling: true
|
52
|
+
};
|
53
|
+
const translate_output = translator.translate(text, options);
|
54
|
+
if(Object.keys(translate_output).length){
|
55
|
+
for (const key in translate_output) {
|
56
|
+
if (translate_output.hasOwnProperty(key)) {
|
57
|
+
let error_message = `Line ${key} - British spelling:`;
|
58
|
+
for (let i = 0; i < translate_output[key].length; i++) {
|
59
|
+
for (const spelling in translate_output[key][i]) {
|
60
|
+
if (translate_output[key][i].hasOwnProperty(spelling)) {
|
61
|
+
errors[htmlFile.relativePath].push(`${error_message} ${spelling}`);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
};
|
23
69
|
|
24
70
|
const checkLinks = async function (source_path, htmlFile, links, hdocbook_config) {
|
25
71
|
for (let i = 0; i < links.length; i++) {
|
@@ -40,10 +86,15 @@
|
|
40
86
|
if (valid_url.protocol === 'mailto:') {
|
41
87
|
continue;
|
42
88
|
}
|
89
|
+
|
43
90
|
// Skip if the link is excluded in the project config
|
44
91
|
if (exclude_links[links[i]]) {
|
45
92
|
continue;
|
46
93
|
}
|
94
|
+
if (links[i].toLowerCase().includes('docs.hornbill.com') || links[i].toLowerCase().includes('docs-internal.hornbill.com')) {
|
95
|
+
errors[htmlFile.relativePath].push(`Links to Hornbill Docs should rooted and not fully-qualified: ${links[i]}`);
|
96
|
+
continue;
|
97
|
+
}
|
47
98
|
|
48
99
|
try {
|
49
100
|
await axios.get(links[i], { httpsAgent: agent });
|
@@ -172,16 +223,37 @@
|
|
172
223
|
};
|
173
224
|
|
174
225
|
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project) {
|
226
|
+
console.log(`Performing Validation and Building SEO Link List...`);
|
227
|
+
|
228
|
+
// Load product families
|
229
|
+
await load_product_families();
|
230
|
+
|
175
231
|
// Get a list of HTML files in source_path
|
176
232
|
dree.scan(source_path, dreeOptions, fileCallback);
|
177
233
|
|
234
|
+
// Check product family
|
235
|
+
let valid_product = false;
|
236
|
+
for (let i = 0; i < prod_families.products.length; i++) {
|
237
|
+
if (prod_families.products[i].id === hdocbook_config.productFamily) {
|
238
|
+
valid_product = true;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
if (!valid_product) {
|
242
|
+
console.log('\r\n-----------------------');
|
243
|
+
console.log(' Validation Output ');
|
244
|
+
console.log('-----------------------\r\n');
|
245
|
+
console.log(`- Incorrect productFamily: ${hdocbook_config.productFamily}`)
|
246
|
+
console.log(`\r\n1 Validation Errors Found\r\n`);
|
247
|
+
console.log(``)
|
248
|
+
return false;
|
249
|
+
}
|
250
|
+
|
178
251
|
if (hdocbook_project.validation && hdocbook_project.validation.exclude_links && hdocbook_project.validation.exclude_links instanceof Array) {
|
179
252
|
hdocbook_project.validation.exclude_links.forEach(function(excl_link) {
|
180
253
|
exclude_links[excl_link] = true;
|
181
254
|
});
|
182
255
|
}
|
183
256
|
|
184
|
-
console.log(`Performing Validation and Building SEO Link List...`);
|
185
257
|
|
186
258
|
let listContent = '';
|
187
259
|
for (let i = 0; i < html_files.length; i++) {
|
@@ -191,6 +263,9 @@
|
|
191
263
|
messages[html_files[i].relativePath] = [];
|
192
264
|
warnings[html_files[i].relativePath] = [];
|
193
265
|
|
266
|
+
// Check for Britishisms
|
267
|
+
await checkBritishSpellings(html_files[i]);
|
268
|
+
|
194
269
|
const links = getLinks(html_files[i]);
|
195
270
|
if (links.href.length === 0) {
|
196
271
|
messages[html_files[i].relativePath].push('No links found in file');
|
package/hdoc.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env node
|
1
|
+
#!/usr/bin/env node
|
2
2
|
(async function () {
|
3
3
|
'use strict';
|
4
4
|
|
@@ -68,7 +68,10 @@
|
|
68
68
|
server.run(ui_path, source_path);
|
69
69
|
} else if (command == 'build') {
|
70
70
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
71
|
-
await builder.run(source_path, verbose, git_token);
|
71
|
+
await builder.run(source_path, verbose, git_token, false);
|
72
|
+
} else if (command == 'validate') {
|
73
|
+
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
74
|
+
await builder.run(source_path, verbose, git_token, true);
|
72
75
|
} else if (command == 'stats') {
|
73
76
|
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
74
77
|
stats.run(ui_path, source_path, verbose);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdoc-tools",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.0",
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
5
5
|
"main": "hdoc.js",
|
6
6
|
"bin": {
|
@@ -30,6 +30,7 @@
|
|
30
30
|
"author": "Hornbill Technologies Ltd",
|
31
31
|
"license": "ISC",
|
32
32
|
"dependencies": {
|
33
|
+
"american-british-english-translator": "^0.2.1",
|
33
34
|
"axios": "^1.3.2",
|
34
35
|
"better-sqlite3": "^8.0.1",
|
35
36
|
"body-parser": "^1.20.1",
|