hdoc-tools 0.9.38 → 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 +27 -15
- 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,6 +55,14 @@
|
|
52
55
|
}
|
53
56
|
}
|
54
57
|
}
|
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;
|
55
66
|
};
|
56
67
|
|
57
68
|
const checkNavigation = async function (source_path, flat_nav) {
|
@@ -321,7 +332,7 @@
|
|
321
332
|
return links;
|
322
333
|
};
|
323
334
|
|
324
|
-
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) {
|
325
336
|
console.log(`Performing Validation and Building SEO Link List...`);
|
326
337
|
|
327
338
|
// Get a list of HTML files in source_path
|
@@ -377,20 +388,21 @@
|
|
377
388
|
}
|
378
389
|
}
|
379
390
|
|
391
|
+
let excl_output = [];
|
392
|
+
|
380
393
|
// Do spellchecking on markdown files
|
381
394
|
let md_files_spellchecked = {};
|
382
395
|
let mdPromiseArray = [];
|
383
396
|
for (let i = 0; i < md_to_validate.length; i++) {
|
397
|
+
errors[md_to_validate[i].relativePath] = [];
|
398
|
+
messages[md_to_validate[i].relativePath] = [];
|
399
|
+
warnings[md_to_validate[i].relativePath] = [];
|
384
400
|
mdPromiseArray.push(md_to_validate[i]);
|
385
401
|
}
|
386
402
|
await Promise.all(mdPromiseArray.map(async (file) => {
|
387
|
-
//await transform_markdown_and_save_html(file);
|
388
403
|
// Initiate maps for errors and verbose messages for markdown file
|
389
|
-
|
390
|
-
|
391
|
-
warnings[file.relativePath] = [];
|
392
|
-
|
393
|
-
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});
|
394
406
|
md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')] = true;
|
395
407
|
}));
|
396
408
|
|
@@ -398,17 +410,16 @@
|
|
398
410
|
let listContent = '';
|
399
411
|
let htmlPromiseArray = [];
|
400
412
|
for (let i = 0; i < html_to_validate.length; i++) {
|
413
|
+
errors[html_to_validate[i].relativePath] = [];
|
414
|
+
messages[html_to_validate[i].relativePath] = [];
|
415
|
+
warnings[html_to_validate[i].relativePath] = [];
|
401
416
|
htmlPromiseArray.push(html_to_validate[i]);
|
402
417
|
}
|
403
418
|
await Promise.all(mdPromiseArray.map(async (file) => {
|
404
|
-
// Initiate maps for errors and verbose messages for HTML file
|
405
|
-
errors[file.relativePath] = [];
|
406
|
-
messages[file.relativePath] = [];
|
407
|
-
warnings[file.relativePath] = [];
|
408
|
-
|
409
419
|
// Check for British spellings in static HTML content
|
410
420
|
if (!md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')]) {
|
411
|
-
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});
|
412
423
|
}
|
413
424
|
|
414
425
|
const links = getLinks(file);
|
@@ -431,6 +442,7 @@
|
|
431
442
|
listContent += '\r\n';
|
432
443
|
}));
|
433
444
|
|
445
|
+
if (gen_exclude) console.log(JSON.stringify(excl_output, null, 2));
|
434
446
|
|
435
447
|
try {
|
436
448
|
// Write list
|
@@ -475,7 +487,7 @@
|
|
475
487
|
}
|
476
488
|
}
|
477
489
|
|
478
|
-
console.log(`\r\nNo Validation Errors Found
|
490
|
+
console.log(`\r\nNo Validation Errors Found!\n`);
|
479
491
|
return true;
|
480
492
|
};
|
481
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);
|