hdoc-tools 0.9.33 → 0.9.34

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-pdf.js CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  const axios = require('axios'),
5
5
  cheerio = require('cheerio'),
6
- dree = require('dree'),
7
6
  fs = require('fs-extra'),
8
7
  mime = require('mime-types'),
9
8
  path = require('path'),
@@ -102,8 +101,6 @@
102
101
  exports.generate_pdf = async function (browser, pdf_template_path, pdf_template_content, book_config, html_source, target_file, css_templates, verbose = false) {
103
102
  let pdf_size = 0;
104
103
 
105
- //dree.scan(pdf_template_path, dree_options_css, file_callback_css);
106
-
107
104
  // Cache footer
108
105
  if (footer === '') footer = get_footer(pdf_template_path);
109
106
 
package/hdoc-build.js CHANGED
@@ -41,6 +41,8 @@
41
41
  pdf_header_template = '',
42
42
  pdf_header_template_non_git = '',
43
43
  pdf_template = '',
44
+ prod_families = {},
45
+ prods_supported = [],
44
46
  doc_id = '',
45
47
  git_token = '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', // Github fine-grained personal access token that has minimum read-only access to Hornbill Docs org repo content
46
48
  hdocbook_config = {},
@@ -628,6 +630,17 @@
628
630
 
629
631
  if (hdocbook_config.publicSource.endsWith('.git')) hdocbook_config.publicSource = hdocbook_config.publicSource.substring(0, hdocbook_config.publicSource.length - 4);
630
632
 
633
+ console.log(`Loading product families...`);
634
+ const prods = await hdoc.load_product_families();
635
+ console.log(prods)
636
+ if (!prods.success) {
637
+ console.log(`ERROR: Failed to load product families: ${prods.errors}\n`);
638
+ process.exit(1);
639
+ } else {
640
+ prod_families = prods.prod_families;
641
+ prods_supported = prods.prods_supported;
642
+ }
643
+
631
644
  console.log('Caching CSS for PDF generation...');
632
645
  const css_files = [
633
646
  path.join(pdf_template_path, 'css', 'custom-block.css'),
@@ -767,7 +780,7 @@
767
780
  }
768
781
 
769
782
  // Validate content
770
- const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc);
783
+ const validation_success = await hdoc_validate.run(work_path, doc_id, verbose, hdocbook_config, hdocbook_project, bc, prod_families, prods_supported);
771
784
  if (!validation_success) {
772
785
  const end_time = Date.now();
773
786
  console.log(`\nTime Taken: ${get_duration(start_time, end_time)}\n`);
package/hdoc-module.js CHANGED
@@ -4,9 +4,13 @@
4
4
  const axios = require('axios'),
5
5
  cheerio = require('cheerio'),
6
6
  html2text = require('html-to-text'),
7
+ https = require('https'),
7
8
  wordsCount = require('words-count').default;
8
9
 
9
- let includesCache = {};
10
+ let includesCache = {},
11
+ agent = new https.Agent({
12
+ rejectUnauthorized: false
13
+ });
10
14
 
11
15
  exports.content_type_for_ext = function (ext) {
12
16
  switch (ext) {
@@ -394,4 +398,33 @@
394
398
  }
395
399
  return bc;
396
400
  };
401
+
402
+ exports.load_product_families = async function () {
403
+ let response = {
404
+ success: false,
405
+ prod_families: {},
406
+ prods_supported: [],
407
+ errors: ''
408
+ };
409
+
410
+ try {
411
+ const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
412
+ httpsAgent: agent
413
+ });
414
+ console.log(prods.status)
415
+ if (prods.status === 200) {
416
+ response.prod_families = prods.data;
417
+ response.prods_supported = [];
418
+ for (let i = 0; i < response.prod_families.products.length; i++) {
419
+ response.prods_supported.push(response.prod_families.products[i].id);
420
+ }
421
+ response.success = true;
422
+ } else {
423
+ throw `Unexpected Status ${prods.status}`;
424
+ }
425
+ } catch (e) {
426
+ response.errors = (`Error returning product families: ${e}`);
427
+ }
428
+ return response;
429
+ };
397
430
  })();
package/hdoc-validate.js CHANGED
@@ -5,24 +5,17 @@
5
5
  cheerio = require('cheerio'),
6
6
  dree = require('dree'),
7
7
  fs = require('fs'),
8
- https = require('https'),
9
8
  path = require('path'),
10
9
  hdoc = require(path.join(__dirname, 'hdoc-module.js')),
11
10
  translator = require('american-british-english-translator'),
12
11
  { trueCasePathSync } = require('true-case-path');
13
12
 
14
- const agent = new https.Agent({
15
- rejectUnauthorized: false
16
- }),
17
- spellcheck_options = {
13
+ const spellcheck_options = {
18
14
  british: true,
19
15
  spelling: true
20
16
  },
21
17
  regex_nav_paths = /[a-z0-9-\/]+/g;
22
18
 
23
- let prod_families = {},
24
- prods_supported = [];
25
-
26
19
  let errors = {},
27
20
  messages = {},
28
21
  warnings = {},
@@ -32,26 +25,6 @@
32
25
  exclude_spellcheck = {},
33
26
  exclude_h1_count = {};
34
27
 
35
- const load_product_families = async function () {
36
- try {
37
- const prods = await axios.get('https://docs.hornbill.com/_books/products.json', {
38
- httpsAgent: agent
39
- });
40
- if (prods.status === 200) {
41
- prod_families = prods.data;
42
- for (let i = 0; i < prod_families.products.length; i++) {
43
- prods_supported.push(prod_families.products[i].id);
44
- }
45
- } else {
46
- throw `Unexpected Status ${prods.status}`;
47
- }
48
- } catch (e) {
49
- console.log(`Error returning product families: ${e}`);
50
- return false;
51
- }
52
- return true;
53
- };
54
-
55
28
  const spellcheckContent = async function (sourceFile, excludes) {
56
29
  const text = fs.readFileSync(sourceFile.path, 'utf8');
57
30
  const source_path = sourceFile.relativePath.replace('.' + sourceFile.extension, '');
@@ -344,7 +317,7 @@
344
317
  return links;
345
318
  };
346
319
 
347
- exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items) {
320
+ exports.run = async function (source_path, doc_id, verbose, hdocbook_config, hdocbook_project, nav_items, prod_families, prods_supported) {
348
321
  console.log(`Performing Validation and Building SEO Link List...`);
349
322
 
350
323
  // Load product families
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.9.33",
3
+ "version": "0.9.34",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {