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 +6 -39
- package/hdoc-init.js +59 -72
- package/hdoc-serve.js +8 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,42 +1,9 @@
|
|
|
1
|
-
#
|
|
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
|
-
|
|
4
|
+
Make sure that you have installed hdoc-tools
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
npm install hdoc-tools -g
|
|
6
7
|
|
|
7
|
-
|
|
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
|
-
//
|
|
52
|
-
const
|
|
53
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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('
|
|
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('{{
|
|
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
|
};
|