hdoc-tools 0.9.46 → 0.9.48

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Hornbill Docs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/hdoc-build.js CHANGED
@@ -637,7 +637,7 @@
637
637
  console.log(`Loading product families...`);
638
638
  const prods = await hdoc.load_product_families();
639
639
  if (!prods.success) {
640
- console.log(`ERROR: Failed to load product families: ${prods.errors}\n`);
640
+ console.log(`${prods.errors}\n`);
641
641
  process.exit(1);
642
642
  } else {
643
643
  prod_families = prods.prod_families;
@@ -655,7 +655,7 @@
655
655
  try {
656
656
  css_templates.push(fs.readFileSync(css_files[i], 'utf8'));
657
657
  } catch (e) {
658
- console.log(`Error reading file [${css_files[i]}]: ${e}`);
658
+ console.log(`Error reading file[${css_files[i]}]: ${e}`);
659
659
  }
660
660
  }
661
661
  }
package/hdoc-module.js CHANGED
@@ -358,23 +358,30 @@
358
358
  prods_supported: [],
359
359
  errors: ''
360
360
  };
361
-
362
- try {
363
- const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
364
- httpsAgent: agent
365
- });
366
- if (prods.status === 200) {
367
- response.prod_families = prods.data;
368
- response.prods_supported = [];
369
- for (let i = 0; i < response.prod_families.products.length; i++) {
370
- response.prods_supported.push(response.prod_families.products[i].id);
361
+ const prod_families_url = 'https://docs.hornbill.com/_books/products.json';
362
+ for (let i = 1; i < 4; i++) {
363
+ try {
364
+ const prods = await axios.get(prod_families_url, {
365
+ httpsAgent: agent,
366
+ timeout: 5000
367
+ });
368
+ if (prods.status === 200) {
369
+ response.prod_families = prods.data;
370
+ response.prods_supported = [];
371
+ for (let i = 0; i < response.prod_families.products.length; i++) {
372
+ response.prods_supported.push(response.prod_families.products[i].id);
373
+ }
374
+ response.success = true;
375
+ break;
376
+ } else {
377
+ throw `Unexpected status - ${prods.status} ${prods.statusText}`;
371
378
  }
372
- response.success = true;
373
- } else {
374
- throw `Unexpected Status ${prods.status}`;
379
+ } catch (e) {
380
+ if (response.errors === '') response.errors = `Request to ${prod_families_url} failed:`;
381
+ response.errors += `\nAttempt ${i} - Error returning product families: ${e}`;
382
+ // Wait 2 seconds and try again
383
+ await new Promise(r => setTimeout(r, 2000));
375
384
  }
376
- } catch (e) {
377
- response.errors = (`Error returning product families: ${e}`);
378
385
  }
379
386
  return response;
380
387
  };
package/hdoc-validate.js CHANGED
@@ -12,10 +12,10 @@
12
12
  { trueCasePathSync } = require('true-case-path');
13
13
 
14
14
  const spellcheck_options = {
15
- british: true,
16
- spelling: true
17
- },
18
- regex_nav_paths = /[a-z0-9-\/]+/g,
15
+ british: true,
16
+ spelling: true
17
+ },
18
+ regex_nav_paths = /[a-z0-9-\/]+[a-z0-9]+#{0,1}[a-z0-9-\/]+/,
19
19
  agent = new https.Agent({
20
20
  rejectUnauthorized: false
21
21
  });
@@ -67,26 +67,28 @@
67
67
 
68
68
  const checkNavigation = async function (source_path, flat_nav) {
69
69
  let nav_errors = [];
70
- for (const key in flat_nav) {
70
+ for (let key in flat_nav) {
71
71
  if (flat_nav.hasOwnProperty(key)) {
72
72
  // doc paths should only contain a-z - characters
73
73
  const invalid_chars = key.replace(regex_nav_paths, '');
74
74
  if (invalid_chars !== '') {
75
75
  nav_errors.push(`Navigation path [${key}] contains the following invalid characters: [${[...invalid_chars].join('] [')}]`);
76
76
  }
77
+ const key_split = key.split('#');
78
+ const key_no_hash = key_split[0];
77
79
 
78
80
  // Validate path exists - key should be a html file at this point
79
81
  let file_exists = true;
80
- let file_name = path.join(source_path, key + '.html');
82
+ let file_name = path.join(source_path, key_no_hash + '.html');
81
83
  if (!fs.existsSync(file_name)) {
82
- file_name = path.join(source_path, key + '.htm');
84
+ file_name = path.join(source_path, key_no_hash + '.htm');
83
85
  if (!fs.existsSync(file_name)) {
84
- file_name = path.join(source_path, key, 'index.html');
86
+ file_name = path.join(source_path, key_no_hash, 'index.html');
85
87
  if (!fs.existsSync(file_name)) {
86
- file_name = path.join(source_path, key, 'index.htm');
88
+ file_name = path.join(source_path, key_no_hash, 'index.htm');
87
89
  if (!fs.existsSync(file_name)) {
88
90
  file_exists = false;
89
- nav_errors.push(`Navigation path [${key}] file does not exist.`);
91
+ nav_errors.push(`Navigation path [${key_no_hash}] file does not exist.`);
90
92
  }
91
93
  }
92
94
  }
@@ -121,6 +123,7 @@
121
123
  }
122
124
 
123
125
  // Validate display names/bookmarks
126
+ console.log(key)
124
127
  for (let i = 0; i < flat_nav[key].length; i++) {
125
128
  if (flat_nav[key][i].link === key) {
126
129
  const translate_output = translator.translate(flat_nav[key][i].text, spellcheck_options);
@@ -334,7 +337,7 @@
334
337
 
335
338
  exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported, gen_exclude) {
336
339
  console.log(`Performing Validation and Building SEO Link List...`);
337
-
340
+
338
341
  // Get a list of HTML files in source_path
339
342
  dree.scan(source_path, dreeOptions, fileCallback);
340
343
 
@@ -389,7 +392,7 @@
389
392
  }
390
393
 
391
394
  let excl_output = [];
392
-
395
+
393
396
  // Do spellchecking on markdown files
394
397
  let md_files_spellchecked = {};
395
398
  let mdPromiseArray = [];
@@ -402,7 +405,7 @@
402
405
  await Promise.all(mdPromiseArray.map(async (file) => {
403
406
  // Initiate maps for errors and verbose messages for markdown file
404
407
  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});
408
+ if (gen_exclude && exclusions.length > 0) excl_output.push({ document_path: file.relativePath.replace('.' + file.extension, ''), words: exclusions });
406
409
  md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')] = true;
407
410
  }));
408
411
 
@@ -419,7 +422,7 @@
419
422
  // Check for British spellings in static HTML content
420
423
  if (!md_files_spellchecked[file.relativePath.replace('.' + file.extension, '')]) {
421
424
  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});
425
+ if (gen_exclude && exclusions.length > 0) excl_output.push({ document_path: file.relativePath.replace('.' + file.extension, ''), words: exclusions });
423
426
  }
424
427
 
425
428
  const links = getLinks(file);
@@ -436,7 +439,7 @@
436
439
 
437
440
  // Check for multiple H1 tags
438
441
  await checkTags(file);
439
-
442
+
440
443
  // Build list content for Google
441
444
  listContent += `/${file.relativePath.replace(path.extname(file.relativePath), '')}`;
442
445
  listContent += '\r\n';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.9.46",
3
+ "version": "0.9.48",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "american-british-english-translator": "^0.2.1",
36
36
  "axios": "^1.3.2",
37
+ "axios-retry": "^3.5.0",
37
38
  "better-sqlite3": "^8.0.1",
38
39
  "body-parser": "^1.20.1",
39
40
  "cheerio": "^1.0.0-rc.12",
@@ -50,6 +51,7 @@
50
51
  "multer": "^1.4.5-lts.1",
51
52
  "prompt": "^1.3.0",
52
53
  "puppeteer": "^19.8.0",
54
+ "retry": "^0.13.1",
53
55
  "stream": "0.0.2",
54
56
  "true-case-path": "^2.2.1",
55
57
  "words-count": "^2.0.2",