hdoc-tools 0.9.39 → 0.9.40
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.js +15 -13
- package/hdoc-validate.js +20 -7
- package/hdoc.js +7 -4
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -574,7 +574,7 @@
|
|
574
574
|
sorted: true
|
575
575
|
};
|
576
576
|
|
577
|
-
exports.run = async function (source_path, verbose_output, github_api_token, validate, build_version = '') {
|
577
|
+
exports.run = async function (source_path, verbose_output, github_api_token, validate, gen_exclude, build_version = '') {
|
578
578
|
if (github_api_token !== '') {
|
579
579
|
git_token = github_api_token;
|
580
580
|
}
|
@@ -640,17 +640,19 @@
|
|
640
640
|
prods_supported = prods.prods_supported;
|
641
641
|
}
|
642
642
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
643
|
+
if (!validate) {
|
644
|
+
console.log('Caching CSS for PDF generation...');
|
645
|
+
const css_files = [
|
646
|
+
path.join(pdf_template_path, 'css', 'custom-block.css'),
|
647
|
+
path.join(pdf_template_path, 'css', 'hdocs-pdf.css'),
|
648
|
+
path.join(pdf_template_path, 'css', 'vars.css')
|
649
|
+
];
|
650
|
+
for (let i = 0; i < css_files.length; i++) {
|
651
|
+
try {
|
652
|
+
css_templates.push(fs.readFileSync(css_files[i], 'utf8'));
|
653
|
+
} catch (e) {
|
654
|
+
console.log(`Error reading file [${css_files[i]}]: ${e}`);
|
655
|
+
}
|
654
656
|
}
|
655
657
|
}
|
656
658
|
|
@@ -779,7 +781,7 @@
|
|
779
781
|
}
|
780
782
|
|
781
783
|
// Validate content
|
782
|
-
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported);
|
784
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported, gen_exclude);
|
783
785
|
if (!validation_success) {
|
784
786
|
const end_time = Date.now();
|
785
787
|
console.log(`\nTime Taken: ${get_duration(start_time, end_time)}\n`);
|
package/hdoc-validate.js
CHANGED
@@ -30,11 +30,12 @@
|
|
30
30
|
exclude_h1_count = {};
|
31
31
|
|
32
32
|
const spellcheckContent = async function (sourceFile, excludes) {
|
33
|
+
let spelling_errors = {};
|
34
|
+
let words = [];
|
33
35
|
const text = fs.readFileSync(sourceFile.path, 'utf8');
|
34
36
|
const source_path = sourceFile.relativePath.replace('.' + sourceFile.extension, '');
|
35
37
|
const translate_output = translator.translate(text, spellcheck_options);
|
36
38
|
if (Object.keys(translate_output).length) {
|
37
|
-
|
38
39
|
for (const key in translate_output) {
|
39
40
|
if (translate_output.hasOwnProperty(key)) {
|
40
41
|
let error_message = `Line ${key} - British spelling:`;
|
@@ -43,8 +44,10 @@
|
|
43
44
|
if (translate_output[key][i].hasOwnProperty(spelling) && (typeof translate_output[key][i][spelling].details === 'string')) {
|
44
45
|
if (!excludes[source_path]) {
|
45
46
|
errors[sourceFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
47
|
+
spelling_errors[spelling] = true;
|
46
48
|
} else if (!excludes[source_path].includes(spelling.toLowerCase())) {
|
47
49
|
errors[sourceFile.relativePath].push(`${error_message} ${spelling} should be ${translate_output[key][i][spelling].details}`);
|
50
|
+
spelling_errors[spelling] = true;
|
48
51
|
}
|
49
52
|
}
|
50
53
|
}
|
@@ -52,7 +55,14 @@
|
|
52
55
|
}
|
53
56
|
}
|
54
57
|
}
|
55
|
-
|
58
|
+
if (Object.keys(spelling_errors).length) {
|
59
|
+
for (const word in spelling_errors) {
|
60
|
+
if (spelling_errors.hasOwnProperty(word)) {
|
61
|
+
words.push(word);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return words;
|
56
66
|
};
|
57
67
|
|
58
68
|
const checkNavigation = async function (source_path, flat_nav) {
|
@@ -322,7 +332,7 @@
|
|
322
332
|
return links;
|
323
333
|
};
|
324
334
|
|
325
|
-
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported) {
|
335
|
+
exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported, gen_exclude) {
|
326
336
|
console.log(`Performing Validation and Building SEO Link List...`);
|
327
337
|
|
328
338
|
// Get a list of HTML files in source_path
|
@@ -378,6 +388,7 @@
|
|
378
388
|
}
|
379
389
|
}
|
380
390
|
|
391
|
+
let excl_output = [];
|
381
392
|
|
382
393
|
// Do spellchecking on markdown files
|
383
394
|
let md_files_spellchecked = {};
|
@@ -389,9 +400,9 @@
|
|
389
400
|
mdPromiseArray.push(md_to_validate[i]);
|
390
401
|
}
|
391
402
|
await Promise.all(mdPromiseArray.map(async (file) => {
|
392
|
-
//await transform_markdown_and_save_html(file);
|
393
403
|
// Initiate maps for errors and verbose messages for markdown file
|
394
|
-
await spellcheckContent(file, exclude_spellcheck);
|
404
|
+
const exclusions = await spellcheckContent(file, exclude_spellcheck);
|
405
|
+
if (gen_exclude && exclusions.length > 0) excl_output.push({document_path: file.relativePath.replace('.' + file.extension, ''), words: exclusions});
|
395
406
|
md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')] = true;
|
396
407
|
}));
|
397
408
|
|
@@ -407,7 +418,8 @@
|
|
407
418
|
await Promise.all(mdPromiseArray.map(async (file) => {
|
408
419
|
// Check for British spellings in static HTML content
|
409
420
|
if (!md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')]) {
|
410
|
-
await spellcheckContent(file, exclude_spellcheck);
|
421
|
+
const exclusions = await spellcheckContent(file, exclude_spellcheck);
|
422
|
+
if (gen_exclude && exclusions.length > 0) excl_output.push({document_path: file.relativePath.replace('.' + file.extension, ''), words: exclusions});
|
411
423
|
}
|
412
424
|
|
413
425
|
const links = getLinks(file);
|
@@ -430,6 +442,7 @@
|
|
430
442
|
listContent += '\r\n';
|
431
443
|
}));
|
432
444
|
|
445
|
+
if (gen_exclude) console.log(JSON.stringify(excl_output, null, 2));
|
433
446
|
|
434
447
|
try {
|
435
448
|
// Write list
|
@@ -474,7 +487,7 @@
|
|
474
487
|
}
|
475
488
|
}
|
476
489
|
|
477
|
-
console.log(`\r\nNo Validation Errors Found
|
490
|
+
console.log(`\r\nNo Validation Errors Found!\n`);
|
478
491
|
return true;
|
479
492
|
};
|
480
493
|
})();
|
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
|
|
@@ -28,7 +28,8 @@
|
|
28
28
|
let git_token = '',
|
29
29
|
command = '', // Our command to run
|
30
30
|
build_version = '',
|
31
|
-
verbose = false
|
31
|
+
verbose = false,
|
32
|
+
gen_exclude = false; // To generate spellcheck exclusions for all files
|
32
33
|
|
33
34
|
// Get options from command args
|
34
35
|
for (let x = 0; x < process.argv.length; x++) {
|
@@ -63,6 +64,8 @@
|
|
63
64
|
if (x < process.argv.length) {
|
64
65
|
build_version = process.argv[x];
|
65
66
|
}
|
67
|
+
} else if (process.argv[x] == '-e') {
|
68
|
+
gen_exclude = true;
|
66
69
|
}
|
67
70
|
}
|
68
71
|
source_path = trueCasePathSync(source_path);
|
@@ -76,13 +79,13 @@
|
|
76
79
|
server.run(ui_path, source_path);
|
77
80
|
} else if (command == 'build') {
|
78
81
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
79
|
-
await builder.run(source_path, verbose, git_token, false, build_version);
|
82
|
+
await builder.run(source_path, verbose, git_token, false, gen_exclude, build_version);
|
80
83
|
} else if (command == 'createDocs') {
|
81
84
|
const creator = require(path.join(__dirname, 'hdoc-create.js'));
|
82
85
|
await creator.run(source_path);
|
83
86
|
} else if (command == 'validate') {
|
84
87
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
85
|
-
await builder.run(source_path, verbose, git_token, true);
|
88
|
+
await builder.run(source_path, verbose, git_token, true, gen_exclude, build_version);
|
86
89
|
} else if (command == 'stats') {
|
87
90
|
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
88
91
|
stats.run(ui_path, source_path, verbose);
|