hdoc-tools 0.8.8 → 0.8.10

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 CHANGED
@@ -1,11 +1,10 @@
1
- const {
2
- stat
3
- } = require('fs');
4
-
5
1
  (function () {
6
2
  'use strict';
7
3
 
8
- const dree = require('dree'),
4
+ const {
5
+ createHash
6
+ } = require('crypto'),
7
+ dree = require('dree'),
9
8
  fs = require('fs-extra'),
10
9
  mdfm = require('markdown-it-front-matter'),
11
10
  path = require('path'),
@@ -38,7 +37,10 @@ const {
38
37
  docId = '',
39
38
  md_files = [],
40
39
  static_html_files = [],
41
- index_records = [];
40
+ index_records = [],
41
+ work_path_content = '',
42
+ built_relative_paths = [],
43
+ built_file_hashes = [];
42
44
 
43
45
  const transform_static_html = function (file_path) {
44
46
  if (fs.existsSync(file_path.path)) {
@@ -99,7 +101,10 @@ const {
99
101
  console.log(`No frontmatter title property, or ${h_tags_to_search.join(', ')} tags detected in ${file_path.path}`);
100
102
  }
101
103
  }
102
- index_records.push({relative_path: file_path.relativePath, index_html: hdoc_index.transform_html_for_index(html_txt)});
104
+ index_records.push({
105
+ relative_path: file_path.relativePath,
106
+ index_html: hdoc_index.transform_html_for_index(html_txt)
107
+ });
103
108
  if (html_txt_updated) {
104
109
  // Save HTML into HTML file
105
110
  fs.writeFile(file_path.path, html_txt, function writeJSON(err) {
@@ -185,10 +190,13 @@ const {
185
190
  fs.writeFile(target_file, html_txt, function writeJSON(err) {
186
191
  if (err) return console.log('Error writing:', target_file, '\r\n', err);
187
192
  });
188
-
189
- const index_details = hdoc_index.transform_html_for_index(html_txt);
190
-
191
- index_records.push({relative_path: relative_path, index_html: index_details});
193
+
194
+ const index_details = hdoc_index.transform_html_for_index(html_txt);
195
+
196
+ index_records.push({
197
+ relative_path: relative_path,
198
+ index_html: index_details
199
+ });
192
200
 
193
201
  // Delete MD file from _work path
194
202
  try {
@@ -204,8 +212,8 @@ const {
204
212
  return false;
205
213
  };
206
214
 
207
- // File callbacks for scans
208
- const fileCallback = function (element) {
215
+ // File callback for build scan
216
+ const build_file_callback = function (element) {
209
217
  if (element.extension === 'md') {
210
218
  md_files.push(element);
211
219
  } else {
@@ -222,16 +230,28 @@ const {
222
230
  }
223
231
  };
224
232
 
233
+ // File & folder callback for MD5 hash of built content
234
+ const hash_callback = function (element) {
235
+ if (element.extension !== 'db') {
236
+ built_file_hashes.push({
237
+ path: element.relativePath,
238
+ hash: element.hash
239
+ });
240
+ }
241
+ };
242
+
225
243
  const dreeOptions = {
226
- descendants: true,
227
- depth: 10,
228
244
  extensions: ['md', 'html', 'htm'],
229
- hash: false,
230
245
  normalize: true,
231
- size: false,
232
- sizeInBytes: false,
233
- stat: false,
234
- symbolicLinks: false
246
+ };
247
+
248
+ const md5DreeOptions = {
249
+ hash: true,
250
+ hashAlgorithm: 'md5',
251
+ hashEncoding: 'hex',
252
+ normalize: true,
253
+ size: true,
254
+ sorted: true
235
255
  };
236
256
 
237
257
  exports.run = function (source_path, verbose) {
@@ -262,7 +282,7 @@ const {
262
282
  console.log(`Building: ${docId} v${hdocbook_config.version}...\r\n`);
263
283
 
264
284
  const work_path = path.join(source_path, '_work');
265
-
285
+ work_path_content = path.join(work_path, docId);
266
286
  // Make _work folder to copy everything into
267
287
  if (fs.existsSync(work_path)) {
268
288
  fs.rmSync(work_path, {
@@ -274,14 +294,14 @@ const {
274
294
 
275
295
  // Copy files from book into _work-docId folder
276
296
  try {
277
- fs.copySync(path.join(source_path, docId), path.join(work_path, docId));
297
+ fs.copySync(path.join(source_path, docId), work_path_content);
278
298
  } catch (e) {
279
299
  console.error('Error copying from source_path:\r\n', e);
280
300
  process.exit(1);
281
301
  }
282
302
 
283
303
  // Get a list of MD files in work_path
284
- dree.scan(work_path, dreeOptions, fileCallback);
304
+ dree.scan(work_path, dreeOptions, build_file_callback);
285
305
 
286
306
  // Work through MD files and convert to HTML
287
307
  md_files.forEach(function (md_file) {
@@ -352,9 +372,31 @@ const {
352
372
  console.log(`\nIndex Build Complete: ${index_success_count} records created.`);
353
373
  }
354
374
 
375
+ // Now create MD5 hash of built content
376
+ dree.scan(work_path_content, md5DreeOptions, hash_callback);
377
+ let concat_hash = '|';
378
+ for (let i = 0; i < built_file_hashes.length; i++) {
379
+ concat_hash += built_file_hashes[i].path + ':' + built_file_hashes[i].hash + '|';
380
+ }
381
+ if (concat_hash === '|') {
382
+ console.log('No hash of content has been returned.');
383
+ process.exit(1);
384
+ }
385
+
386
+ const hash = createHash("md5").update(concat_hash).digest("hex");
387
+ const checksum_path = path.join(work_path_content, 'checksum.md5');
388
+ try {
389
+ fs.writeFileSync(checksum_path, hash);
390
+ console.log('\nHash file creation success:', checksum_path);
391
+ } catch (e) {
392
+ console.log('\nError creating', checksum_path, ':', e);
393
+ process.exit(1);
394
+ }
395
+
396
+
355
397
  try {
356
398
  const zip_path = path.join(work_path, docId + '.zip');
357
- zipper.sync.zip(path.join(work_path, docId)).compress().save(zip_path);
399
+ zipper.sync.zip(work_path_content).compress().save(zip_path);
358
400
  console.log(`\nZIP Creation Success: ${zip_path}\n`);
359
401
  console.log('Build Complete\n');
360
402
  } catch (e) {
package/hdoc-stats.js CHANGED
@@ -60,7 +60,7 @@
60
60
  symbolicLinks: false
61
61
  };
62
62
 
63
- exports.run = function(ui_path, source_path, md, verbose = false) {
63
+ exports.run = function(ui_path, source_path, verbose = false) {
64
64
 
65
65
  // GERRY: The stats here are needed to support content development. The idea is to count all of the ]
66
66
  // words in a HDocBook so we know the size of the book, this helps with 3rd party involvement where
@@ -76,7 +76,7 @@
76
76
  // * MD files, and word count those
77
77
 
78
78
 
79
- console.log('Hornbill HDocBook Stats', '\r\n');
79
+ console.log('Hornbill HDocBook Stats : verbose=' + verbose, '\r\n');
80
80
 
81
81
  const project_json_path = path.join(source_path, 'hdocbook-project.json');
82
82
 
package/hdoc.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  (function () {
4
4
  'use strict';
@@ -58,6 +58,8 @@
58
58
 
59
59
  }
60
60
 
61
+ console.log("VERBOSE: ", verbose);
62
+
61
63
  console.log('Hornbill HDocBook Tools v' + getHdocPackageVersion(packageFile), '\r\n');
62
64
  console.log(' Server Path:', __dirname);
63
65
  console.log(' Document Path:', source_path, '\r\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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.