hdoc-tools 0.9.39 → 0.9.41
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 +21 -14
- package/hdoc-validate.js +20 -7
- package/hdoc.js +6 -3
- package/package.json +1 -1
package/hdoc-build.js
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
non_git_pdf_header_template_path = path.join(__dirname, 'templates', 'pdf-header-non-git.html'),
|
25
25
|
pdf_template_path = path.join(__dirname, 'templates', 'pdf'),
|
26
26
|
pdf_template_file_path = path.join(pdf_template_path, 'template.html'),
|
27
|
+
regex_set_version = /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{0,6}$/,
|
27
28
|
regex_version = /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,6}$/;
|
28
29
|
|
29
30
|
let bc = {}, // Breadcrumbs map
|
@@ -574,7 +575,7 @@
|
|
574
575
|
sorted: true
|
575
576
|
};
|
576
577
|
|
577
|
-
exports.run = async function (source_path, verbose_output, github_api_token, validate, build_version = '') {
|
578
|
+
exports.run = async function (source_path, verbose_output, github_api_token, validate, gen_exclude, build_version = '') {
|
578
579
|
if (github_api_token !== '') {
|
579
580
|
git_token = github_api_token;
|
580
581
|
}
|
@@ -620,7 +621,11 @@
|
|
620
621
|
|
621
622
|
hdocbook_config = require(hdocbook_path);
|
622
623
|
if (build_version !== '') {
|
623
|
-
|
624
|
+
if (build_version.match(regex_version)) {
|
625
|
+
hdocbook_config.version = build_version;
|
626
|
+
} else {
|
627
|
+
console.log(`\n[WARNING] Argument build version [${build_version}] does not match expected pattern, defaulting to version specified in book [${hdocbook_config.version}]\n`);
|
628
|
+
}
|
624
629
|
}
|
625
630
|
|
626
631
|
if (!hdocbook_config.version.match(regex_version)) {
|
@@ -640,17 +645,19 @@
|
|
640
645
|
prods_supported = prods.prods_supported;
|
641
646
|
}
|
642
647
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
648
|
+
if (!validate) {
|
649
|
+
console.log('Caching CSS for PDF generation...');
|
650
|
+
const css_files = [
|
651
|
+
path.join(pdf_template_path, 'css', 'custom-block.css'),
|
652
|
+
path.join(pdf_template_path, 'css', 'hdocs-pdf.css'),
|
653
|
+
path.join(pdf_template_path, 'css', 'vars.css')
|
654
|
+
];
|
655
|
+
for (let i = 0; i < css_files.length; i++) {
|
656
|
+
try {
|
657
|
+
css_templates.push(fs.readFileSync(css_files[i], 'utf8'));
|
658
|
+
} catch (e) {
|
659
|
+
console.log(`Error reading file [${css_files[i]}]: ${e}`);
|
660
|
+
}
|
654
661
|
}
|
655
662
|
}
|
656
663
|
|
@@ -779,7 +786,7 @@
|
|
779
786
|
}
|
780
787
|
|
781
788
|
// Validate content
|
782
|
-
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported);
|
789
|
+
const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported, gen_exclude);
|
783
790
|
if (!validation_success) {
|
784
791
|
const end_time = Date.now();
|
785
792
|
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
@@ -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);
|