hdoc-tools 0.7.0 → 0.7.2

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
@@ -4,7 +4,7 @@
4
4
  const fs = require('fs-extra'),
5
5
  path = require('path'),
6
6
  dree = require('dree'),
7
- AdmZip = require("adm-zip");
7
+ zipper = require('zip-local');
8
8
 
9
9
  let conversion_attempted = 0,
10
10
  conversion_success = 0,
@@ -33,11 +33,11 @@
33
33
 
34
34
  // Render markdown into HTML
35
35
  var html_txt = md.render(md_txt.toString());
36
-
36
+
37
37
  // Save HTML into HTML file
38
38
  const target_file = file_path.replace(path.extname(file_path), '.html');
39
- fs.writeFile(target_file, html_txt, function writeJSON(err) {
40
- if (err) return console.log('Error writing:',target_file, '\r\n', err);
39
+ fs.writeFileSync(target_file, html_txt, function writeJSON(err) {
40
+ if (err) return console.log('Error writing:', target_file, '\r\n', err);
41
41
  });
42
42
  conversion_success++;
43
43
  return true;
@@ -74,29 +74,24 @@
74
74
  // folder, conceptually we are making a little mini website crawler to index all of the content
75
75
  // within the book.
76
76
  // * Package everything up into a ZIP file, ready for the build controller to package and publish
77
-
77
+
78
78
  console.log('Hornbill HDocBook Build', '\r\n');
79
+ console.log(' Document Path:', source_path, '\r\n');
79
80
 
80
81
  // Load the hdocbook-project.json file to get the docId
81
82
  // use the docId to get the book config
82
- const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json'),
83
- hdocbook_project = require(hdocbook_project_config_path);
83
+ const hdocbook_project_config_path = path.join(source_path, 'hdocbook-project.json'),
84
+ hdocbook_project = require(hdocbook_project_config_path);
84
85
 
85
86
  docId = hdocbook_project.docId;
86
87
 
87
- const book_path = path.join(source_path, docId),
88
- hdocbook_path = path.join(book_path, 'hdocbook.json'),
89
- hdocbook_config = require(hdocbook_path);
88
+ const book_path = path.join(source_path, docId),
89
+ hdocbook_path = path.join(book_path, 'hdocbook.json'),
90
+ hdocbook_config = require(hdocbook_path);
90
91
 
91
92
  console.log(`Building: ${docId} v${hdocbook_config.version}...\r\n`);
92
93
 
93
- // Get source-path - 1 to work out where to store _work
94
- const work_path_arr = source_path.split(path.sep);
95
- let work_path = work_path_arr[0];
96
- for (let i = 1; i < work_path_arr.length - 1; i++) {
97
- work_path += path.sep + work_path_arr[i];
98
- }
99
- work_path = path.join(work_path, '_work_' + docId);
94
+ const work_path = path.join(source_path, '_work');
100
95
 
101
96
  // Make _work folder to copy everything into
102
97
  if (fs.existsSync(work_path)) {
@@ -105,42 +100,35 @@
105
100
  force: true
106
101
  });
107
102
  }
108
-
109
- // Create target book folder
110
103
  fs.mkdirSync(work_path);
111
104
 
112
105
  // Copy files from book into _work-docId folder
113
106
  try {
114
- fs.copySync(source_path, work_path);
107
+ fs.copySync(path.join(source_path, docId), path.join(work_path, docId));
108
+ fs.copyFileSync(path.join(source_path, 'hdocbook-project.json'), path.join(work_path, 'hdocbook-project.json'));
109
+ fs.copyFileSync(path.join(source_path, 'LICENSE'), path.join(work_path, 'LICENSE'));
110
+ fs.copyFileSync(path.join(source_path, 'README.md'), path.join(work_path, 'README.md'));
111
+ fs.copyFileSync(path.join(source_path, 'package.json'), path.join(work_path, 'package.json'));
115
112
  } catch (e) {
116
113
  console.error('Error copying from source_path:\r\n', e);
117
114
  process.exit(1);
118
115
  }
119
116
 
120
- // Remove git stuff from work_path
121
- fs.rmSync(path.join(work_path, '.git'), {
122
- recursive: true,
123
- force: true
124
- });
125
-
126
117
  // Get a list of MD files in work_path
127
118
  dree.scan(work_path, dreeOptions, fileCallback);
128
-
129
119
  // Work through MD files and convert to HTML
130
- md_files.forEach(function(md_file){
120
+ md_files.forEach(function (md_file) {
131
121
  transform_markdown_and_save_html(md_file, md);
132
122
  });
133
-
134
123
  console.log(` MD files found: ${conversion_attempted}`);
135
124
  console.log(`Successfully converted to HTML: ${conversion_success}`);
136
125
  console.log(` Failed to convert: ${conversion_failed}`);
137
126
 
138
- // ZIP up content of _work-docId, save as docId_vx_y_z.zip where x/y/z is semantic version
139
- const zip_path = path.join(work_path, docId + '_v' + hdocbook_config.version.replace('.', '_') + '.zip');
140
- const zip = new AdmZip();
141
- zip.addLocalFolder(work_path);
142
- zip.writeZip(zip_path);
127
+ const zip_path = path.join(work_path, docId + '.zip');
128
+ zipper.sync.zip(work_path).compress().save(zip_path);
129
+
143
130
  console.log(` ZIP Creation Success: ${zip_path}\r\n`);
144
131
  console.log('Build Complete\r\n');
132
+
145
133
  };
146
134
  })();
package/hdoc-serve.js CHANGED
@@ -28,6 +28,11 @@
28
28
  console.log(' Document Path:', source_path, '\r\n');
29
29
  console.log(' Server Port:', port);
30
30
 
31
+ if(fs.existsSync(path.join(source_path, 'hdocbook-project.json')) == false) {
32
+ console.log("No hdocbook-project.js file found in working folder. Unable to continue.");
33
+ return -1;
34
+ }
35
+
31
36
  // Get an express server instance
32
37
  var app = express();
33
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -25,7 +25,6 @@
25
25
  "author": "Hornbill Technologies Ltd",
26
26
  "license": "ISC",
27
27
  "dependencies": {
28
- "adm-zip": "^0.5.9",
29
28
  "body-parser": "^1.20.1",
30
29
  "cookie-parser": "^1.4.6",
31
30
  "dree": "^3.4.2",
@@ -42,6 +41,7 @@
42
41
  "multer": "^1.4.5-lts.1",
43
42
  "prompt": "^1.3.0",
44
43
  "stream": "0.0.2",
45
- "words-count": "^2.0.2"
44
+ "words-count": "^2.0.2",
45
+ "zip-local": "^0.3.5"
46
46
  }
47
47
  }