hdoc-tools 0.7.7 → 0.7.9

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/README.md CHANGED
@@ -1,42 +1,9 @@
1
- # hdoc-tools
1
+ # HDocBook documentation
2
+ This is an example of a simple static content documentation project that is compatible with the Hornbill Docs system
2
3
 
3
- Hornbill HDocBook Development Support Tool.
4
+ Make sure that you have installed hdoc-tools
4
5
 
5
- ## Usage
6
+ npm install hdoc-tools -g
6
7
 
7
- <code>hdoc argument switches</code>
8
-
9
- ## Arguments
10
-
11
- The arguments available to this command-line tool are as follows.
12
-
13
- ### help
14
-
15
- Outputs available arguments and switches.
16
-
17
- ### init
18
-
19
- Initializes a new HDocBook project from a template, using runtime input variables.
20
-
21
- ### stats
22
-
23
- Returns statistics regarding the book you are working on:
24
-
25
- - Document ID
26
- - Version
27
- - Title
28
- - Description
29
- - Public Source
30
- - Total Book Word Count
31
- - Number of Markdown Files in the Book
32
- - Number of Static HTML Files in the Book
33
-
34
- If the -v switch is provided, then a more verbose output is output, which includes a list of each MD and HTML file found, the file sizes, and file-specific word count.
35
-
36
- ### build
37
-
38
- Performs a local build of the book, and outputs as a ZIP file.
39
-
40
- ### serve
41
-
42
- Starts a local web server on port 3000, serving the book content.
8
+ To preview the documentation in a browser, you can open a terminal window and run the dev preview server with the
9
+ command `hdoc serve` and in a local browser go to the url `http://localhost:3000`
package/hdoc-init.js CHANGED
@@ -40,7 +40,7 @@
40
40
  }
41
41
  ];
42
42
 
43
- const createBook = function(server_path, source_path, docProps) {
43
+ const createBook = function (server_path, source_path, docProps) {
44
44
  console.log('\r\nCreating book with the following properties:\r\n');
45
45
  console.log(' Doc ID:', docProps.id);
46
46
  console.log(' Title:', docProps.title);
@@ -48,85 +48,72 @@
48
48
  console.log(' Author:', docProps.author);
49
49
  console.log(' Initial Version:', docProps.version, '\r\n');
50
50
 
51
- //Make folder in source path
52
- const bookPath = path.join(source_path, docProps.id);
53
- if (!fs.existsSync(bookPath)) {
54
-
55
- // Create target book folder
56
- fs.mkdirSync(bookPath);
57
-
58
- // Now copy files over
59
- const templatePath = path.join(server_path, 'templates','init');
60
- console.log('Copying template from:', templatePath);
51
+ // Now copy files over
52
+ const templatePath = path.join(server_path, 'templates', 'init');
53
+ console.log('Copying template from:', templatePath);
61
54
 
62
- if (fs.existsSync(templatePath)) {
63
- // If template path exists, do sync copy into book path
64
- try {
65
- fs.copySync(templatePath, bookPath);
66
- } catch (e){
67
- console.error('Error copying template:\r\n', e);
68
- process.exit(1);
69
- }
55
+ if (fs.existsSync(templatePath)) {
56
+ // If template path exists, do sync copy into book path
57
+ try {
58
+ fs.copySync(templatePath, source_path);
59
+ } catch (e) {
60
+ console.error('Error copying template:\r\n', e);
61
+ process.exit(1);
62
+ }
70
63
 
71
- // Rename _hdocbook folder to docId, sync as we need to wait
72
- // until this in complete for the next tasks to be successful
73
- const bookContentRoot = path.join(bookPath, docProps.id);
74
- try {
75
- fs.renameSync(path.join(bookPath, '_hdocbook'), bookContentRoot);
76
- } catch (e) {
77
- console.error('Error renaming template folder:\r\n', e);
78
- process.exit(1);
79
- }
64
+ // Rename _hdocbook folder to docId, sync as we need to wait
65
+ // until this in complete for the next tasks to be successful
66
+ const bookContentRoot = path.join(source_path, docProps.id);
67
+ try {
68
+ fs.renameSync(path.join(source_path, '_hdocbook'), bookContentRoot);
69
+ } catch (e) {
70
+ console.error('Error renaming template folder:\r\n', e);
71
+ process.exit(1);
72
+ }
80
73
 
81
- // The file update tasks can now all be done async now
82
- // we have the file and folder structure in place
74
+ // The file update tasks can now all be done async now
75
+ // we have the file and folder structure in place
83
76
 
84
- // Update hdocbook-project.json
85
- const hdocBookProjectFilePath = path.join(bookPath, 'hdocbook-project.json');
86
- const hdocBookProjectFile = require(hdocBookProjectFilePath);
87
- hdocBookProjectFile.docId = docProps.id;
88
- fs.writeFile(hdocBookProjectFilePath, JSON.stringify(hdocBookProjectFile, null, 2), function writeJSON(err) {
89
- if (err) return console.log('Error updating:',hdocBookProjectFilePath, '\r\n', err);
90
- console.log('Updated:', hdocBookProjectFilePath);
91
- });
77
+ // Update hdocbook-project.json
78
+ const hdocBookProjectFilePath = path.join(source_path, 'hdocbook-project.json');
79
+ const hdocBookProjectFile = require(hdocBookProjectFilePath);
80
+ hdocBookProjectFile.docId = docProps.id;
81
+ fs.writeFile(hdocBookProjectFilePath, JSON.stringify(hdocBookProjectFile, null, 2), function writeJSON(err) {
82
+ if (err) return console.log('Error updating:', hdocBookProjectFilePath, '\r\n', err);
83
+ console.log('Updated:', hdocBookProjectFilePath);
84
+ });
92
85
 
93
- // Update root/hdocbook.json
94
- const hdocBookFilePath = path.join(bookContentRoot, 'hdocbook.json');
95
- const hdocbookFile = require(hdocBookFilePath);
96
- hdocbookFile.docId = docProps.id;
97
- hdocbookFile.title = docProps.title;
98
- hdocbookFile.description = docProps.description;
99
- hdocbookFile.version = docProps.version;
100
- hdocbookFile.navigation.items[0].items = [
101
- {
102
- "text": "Welcome",
103
- "link": path.join(docProps.id, 'index')
104
- }
105
- ];
106
- fs.writeFile(hdocBookFilePath, JSON.stringify(hdocbookFile, null, 2), function writeJSON(err) {
107
- if (err) return console.log('Error updating:',hdocBookFilePath, '\r\n', err);
108
- console.log('Updated:', hdocBookFilePath);
109
- });
86
+ // Update root/hdocbook.json
87
+ const hdocBookFilePath = path.join(bookContentRoot, 'hdocbook.json');
88
+ const hdocbookFile = require(hdocBookFilePath);
89
+ hdocbookFile.docId = docProps.id;
90
+ hdocbookFile.title = docProps.title;
91
+ hdocbookFile.description = docProps.description;
92
+ hdocbookFile.version = docProps.version;
93
+ hdocbookFile.navigation.items[0].items = [{
94
+ "text": "Welcome",
95
+ "link": path.join(docProps.id, 'index')
96
+ }];
97
+ fs.writeFile(hdocBookFilePath, JSON.stringify(hdocbookFile, null, 2), function writeJSON(err) {
98
+ if (err) return console.log('Error updating:', hdocBookFilePath, '\r\n', err);
99
+ console.log('Updated:', hdocBookFilePath);
100
+ });
110
101
 
111
- // Update package.json
112
- const packageFilePath = path.join(bookPath, 'package.json');
113
- const packageFile = require(packageFilePath);
114
- packageFile.name = docProps.id;
115
- packageFile.version = docProps.version;
116
- hdocbookFile.description = docProps.description;
117
- hdocbookFile.version = docProps.version;
118
- hdocbookFile.author = docProps.author;
119
- fs.writeFile(packageFilePath, JSON.stringify(packageFile, null, 2), function writeJSON(err) {
120
- if (err) return console.log('Error updating:',packageFilePath, '\r\n', err);
121
- console.log('Updated:', packageFilePath);
122
- });
102
+ // Update package.json
103
+ const packageFilePath = path.join(source_path, 'package.json');
104
+ const packageFile = require(packageFilePath);
105
+ packageFile.name = docProps.id;
106
+ packageFile.version = docProps.version;
107
+ hdocbookFile.description = docProps.description;
108
+ hdocbookFile.version = docProps.version;
109
+ hdocbookFile.author = docProps.author;
110
+ fs.writeFile(packageFilePath, JSON.stringify(packageFile, null, 2), function writeJSON(err) {
111
+ if (err) return console.log('Error updating:', packageFilePath, '\r\n', err);
112
+ console.log('Updated:', packageFilePath);
113
+ });
123
114
 
124
- } else {
125
- console.error('Template path does not exist:', templatePath);
126
- process.exit(1);
127
- }
128
115
  } else {
129
- console.error('Target book path already exists:', bookPath);
116
+ console.error('Template path does not exist:', templatePath);
130
117
  process.exit(1);
131
118
  }
132
119
  };
package/hdoc-serve.js CHANGED
@@ -112,7 +112,7 @@
112
112
 
113
113
  function expand_variables(text) {
114
114
  // For debug mode our base path is our root??
115
- text = text.replaceAll('{{BASE_PATH}}', '/' + docId);
115
+ text = text.replaceAll('{{DOC_ID}}', docId);
116
116
  text = text.replaceAll('{{BUILD_NUMBER}}', '0');
117
117
 
118
118
  let build_date = new Date().toISOString();
@@ -329,26 +329,6 @@
329
329
  // Catch all
330
330
  app.get('/*', function (req, res) {
331
331
 
332
- let segs = req.url.split('/');
333
-
334
- if (segs.length > 3 && segs[2] == 'content') {
335
- // In this case we are looking for static content within the book
336
-
337
- // Create the file path
338
- let url = req.url.replace('/content/', '/');
339
- let file_path = path.join(source_path, url);
340
-
341
- // If the file exists, send it.
342
- if (fs.existsSync(file_path) == true) {
343
- send_file(req, res, file_path);
344
- return;
345
- }
346
-
347
- // All else fails, we have not file to return, so return a 404 error here
348
- send_content_resource_404(req, res);
349
- return;
350
- }
351
-
352
332
  let ui_file_path = path.join(ui_path, req.url);
353
333
 
354
334
  console.log('URL Root:', req.url);
@@ -376,6 +356,13 @@
376
356
 
377
357
  console.log('Server listening at http://127.0.0.1:%s', port);
378
358
  console.log('Document source path is: ' + source_path);
359
+
360
+ let _vars = ['{{DOC_ID}}', '{{BASE_PATH}}', '{{BUILD_NUMBER}}', '{{BUILD_DATE}}'];
361
+ console.log("Server Vars:");
362
+ for(let x = 0; x < _vars.length; x++) {
363
+ let name = _vars[x];
364
+ console.log(" ", name, " = ", expand_variables(name));
365
+ }
379
366
  });
380
367
 
381
368
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.7.7",
3
+ "version": "0.7.9",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {