hdoc-tools 0.11.1 → 0.11.3

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-db.js CHANGED
@@ -1,9 +1,9 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
- const path = require('path'),
5
- hdoc_index = require(path.join(__dirname, 'hdoc-db.js')),
6
- database = require('better-sqlite3');
4
+ const path = require('path'),
5
+ hdoc_index = require(path.join(__dirname, 'hdoc-db.js')),
6
+ database = require('better-sqlite3');
7
7
 
8
8
  const db_schema = {
9
9
  hdoc_index: [
@@ -15,7 +15,8 @@
15
15
  'doc_content',
16
16
  'doc_preview UNINDEXED',
17
17
  'doc_family_id',
18
- 'doc_md5_hash UNINDEXED'
18
+ 'doc_md5_hash UNINDEXED',
19
+ 'lastmod'
19
20
  ],
20
21
  hdoc_meta: [
21
22
  'resource_url',
@@ -95,7 +96,8 @@
95
96
  file.index_html.text,
96
97
  file.index_html.preview,
97
98
  book_config.productFamily,
98
- file.md5
99
+ file.md5,
100
+ file.lastmod
99
101
  ];
100
102
  const index_response = hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
101
103
  if (!index_response.success) {
@@ -118,7 +120,7 @@
118
120
  console.log(`Inserted index record ${index_response.row_id}: ${doc_id} - ${file.index_html.fm_props.title}`);
119
121
  console.log(`Inserted index metadata record for index ID: ${meta_response.row_id}`);
120
122
  }
121
-
123
+
122
124
  // Now add contributor records
123
125
  for (let j = 0; j < file.contributors.length; j++) {
124
126
  const contrib_vals = [
@@ -136,7 +138,7 @@
136
138
  }
137
139
  if (verbose) {
138
140
  console.log(`Inserted document contributor recordL ${cont_response.row_id}`);
139
- }
141
+ }
140
142
  }
141
143
  response.index_success_count++;
142
144
  }
package/hdoc-build.js CHANGED
@@ -467,14 +467,14 @@
467
467
  }
468
468
 
469
469
  const index_details = hdoc_index.transform_html_for_index(html_txt);
470
-
471
470
  index_records.push({
472
471
  relative_path: relative_path,
473
472
  index_html: index_details,
474
473
  metadata: metadata,
475
474
  contributors: contribs,
476
475
  pdf_size: pdf_size,
477
- md5: file_path.hash
476
+ md5: file_path.hash,
477
+ lastmod: file_path.stat.mtime.toISOString()
478
478
  });
479
479
 
480
480
  // Add MD file to delete queue
@@ -563,6 +563,7 @@
563
563
  hash: true,
564
564
  extensions: ['md', 'html', 'htm'],
565
565
  normalize: true,
566
+ stat: true
566
567
  };
567
568
 
568
569
  const md5DreeOptions = {
package/hdoc-bump.js ADDED
@@ -0,0 +1,109 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const fs = require('fs'),
5
+ path = require('path');
6
+
7
+ exports.run = function (source_path, bump_type) {
8
+ if (bump_type !== 'patch' && bump_type !== 'minor' && bump_type !== 'major') {
9
+ console.log(`Unsupported bump type: ${bump_type}`);
10
+ process.exit(1);
11
+ }
12
+ console.log(`Bumping ${bump_type} book version...\n`);
13
+
14
+ // Get document ID
15
+ const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
16
+ let hdocbook_project;
17
+ try {
18
+ hdocbook_project = require(hdocbook_project_config_path);
19
+ } catch (e) {
20
+ console.log('File not found: hdocbook-project.json:');
21
+ console.log(e, '\n');
22
+ console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
23
+ process.exit(1);
24
+ }
25
+ const doc_id = hdocbook_project.docId;
26
+
27
+ const book_path = path.join(source_path, doc_id),
28
+ hdocbook_path = path.join(book_path, 'hdocbook.json');
29
+
30
+ let hdocbook_config;
31
+ try {
32
+ hdocbook_config = require(hdocbook_path);
33
+ } catch (e) {
34
+ console.log('File not found: hdocbook.json');
35
+ console.log(e, '\n');
36
+ console.log('hdoc bump needs to be run in the root of a HDoc Book.\n');
37
+ process.exit(1);
38
+ }
39
+ const initial_version = hdocbook_config.version;
40
+ let hdocbook_version = hdocbook_config.version.split('.');
41
+ if (hdocbook_version.length !== 3) {
42
+ console.log(`Book version does not appear to be in a semantic versioning format: ${initial_version}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ if (isNaN(hdocbook_version[0])) {
47
+ console.log(`Existing major version is not a number: ${hdocbook_version[0]}`);
48
+ process.exit(1);
49
+ }
50
+ if (isNaN(hdocbook_version[1])) {
51
+ console.log(`Existing minor version is not a number: ${hdocbook_version[1]}`);
52
+ process.exit(1);
53
+ }
54
+ if (isNaN(hdocbook_version[2])) {
55
+ console.log(`Existing patch version is not a number: ${hdocbook_version[2]}`);
56
+ process.exit(1);
57
+ }
58
+
59
+ switch (bump_type) {
60
+ case 'major':
61
+ try {
62
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10) + 1;
63
+ hdocbook_version[1] = 0;
64
+ hdocbook_version[2] = 0;
65
+ } catch (e) {
66
+ console.log('Failed to update major version:');
67
+ console.log(e);
68
+ process.exit(1);
69
+ }
70
+ break;
71
+ case 'minor':
72
+ try {
73
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
74
+ hdocbook_version[1] = parseInt(hdocbook_version[1], 10) + 1;
75
+ hdocbook_version[2] = 0;
76
+ } catch (e) {
77
+ console.log('Failed to update minor version:');
78
+ console.log(e);
79
+ process.exit(1);
80
+ }
81
+ break;
82
+ case 'patch':
83
+ default:
84
+ try {
85
+ hdocbook_version[0] = parseInt(hdocbook_version[0], 10);
86
+ hdocbook_version[1] = parseInt(hdocbook_version[1], 10);
87
+ hdocbook_version[2] = parseInt(hdocbook_version[2], 10) + 1;
88
+ } catch (e) {
89
+ console.log('Failed to update patch version:');
90
+ console.log(e);
91
+ process.exit(1);
92
+ }
93
+ break;
94
+ }
95
+
96
+ hdocbook_config.version = hdocbook_version.join('.');
97
+
98
+ try {
99
+ fs.writeFileSync(hdocbook_path, JSON.stringify(hdocbook_config, null, 2));
100
+ } catch (e) {
101
+ console.log('Error writing bumped version to book config:', e);
102
+ process.exit(1);
103
+ }
104
+
105
+ console.log(`Book version updated from ${initial_version} to ${hdocbook_config.version}\n`);
106
+ return true;
107
+ };
108
+
109
+ })();
package/hdoc-ver.js ADDED
@@ -0,0 +1,43 @@
1
+ (function () {
2
+ 'use strict';
3
+
4
+ const fs = require('fs'),
5
+ path = require('path');
6
+
7
+ exports.run = function (source_path) {
8
+ console.log(`Retrieving book version...\n`);
9
+
10
+ // Get document ID
11
+ const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json');
12
+ let hdocbook_project;
13
+ try {
14
+ hdocbook_project = require(hdocbook_project_config_path);
15
+ } catch (e) {
16
+ console.log('File not found: hdocbook-project.json:');
17
+ console.log(e, '\n');
18
+ console.log('hdoc ver needs to be run in the root of a HDoc Book.\n');
19
+ process.exit(1);
20
+ }
21
+ const doc_id = hdocbook_project.docId;
22
+
23
+ const book_path = path.join(source_path, doc_id),
24
+ hdocbook_path = path.join(book_path, 'hdocbook.json');
25
+
26
+ let hdocbook_config;
27
+ try {
28
+ hdocbook_config = require(hdocbook_path);
29
+ } catch (e) {
30
+ console.log('File not found: hdocbook.json');
31
+ console.log(e, '\n');
32
+ console.log('hdoc ver needs to be run in the root of a HDoc Book.\n');
33
+ process.exit(1);
34
+ }
35
+ if (hdocbook_config.version && hdocbook_config.version !== '') {
36
+ console.log(`Book version: ${hdocbook_config.version}\n`);
37
+ } else {
38
+ console.log(`Error - this book has no version defined.\n`);
39
+ process.exit(1);
40
+ }
41
+ };
42
+
43
+ })();
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -12,6 +12,7 @@
12
12
  "hdoc-build.js",
13
13
  "hdoc-build-db.js",
14
14
  "hdoc-build-pdf.js",
15
+ "hdoc-bump.js",
15
16
  "hdoc-create.js",
16
17
  "hdoc-help.js",
17
18
  "hdoc-init.js",
@@ -19,6 +20,7 @@
19
20
  "hdoc-serve.js",
20
21
  "hdoc-stats.js",
21
22
  "hdoc-validate.js",
23
+ "hdoc-ver.js",
22
24
  "validateNodeVer.js",
23
25
  "ui",
24
26
  "custom_modules",