hdoc-tools 0.6.4 → 0.6.5
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-init.js +125 -14
- package/hdoc-stats.js +1 -1
- package/hdoc.js +2 -2
- package/package.json +3 -1
package/hdoc-init.js
CHANGED
|
@@ -1,36 +1,147 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
// Required modules
|
|
4
5
|
const prompt = require('prompt');
|
|
6
|
+
//const fs = require('fs');
|
|
7
|
+
const fs = require('fs-extra');
|
|
8
|
+
const path = require('path');
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
// Configure prompt module preferences
|
|
11
|
+
prompt.message = false;
|
|
12
|
+
const promptProps = [{
|
|
13
|
+
name: 'id',
|
|
14
|
+
description: 'Document ID',
|
|
15
|
+
validator: /^[a-z][a-z-]+[a-z]$/,
|
|
16
|
+
warning: 'Document ID must only contain lower case letters and dashes',
|
|
17
|
+
required: true
|
|
10
18
|
},
|
|
11
19
|
{
|
|
12
|
-
name: 'title'
|
|
20
|
+
name: 'title',
|
|
21
|
+
description: 'Title',
|
|
22
|
+
required: true
|
|
13
23
|
},
|
|
14
24
|
{
|
|
15
|
-
name: '
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
name: 'description',
|
|
26
|
+
description: 'Description',
|
|
27
|
+
required: true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'version',
|
|
31
|
+
description: 'Initial Version',
|
|
32
|
+
validator: /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$/,
|
|
33
|
+
warning: 'Version must formatted using semantic versioning - major.minor.patch, eg: 0.1.2',
|
|
34
|
+
required: true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'author',
|
|
38
|
+
description: 'Package Author',
|
|
39
|
+
required: true
|
|
18
40
|
}
|
|
19
41
|
];
|
|
20
42
|
|
|
21
|
-
|
|
43
|
+
const createBook = function(server_path, source_path, docProps) {
|
|
44
|
+
console.log('\r\nCreating book with the following properties:\r\n');
|
|
45
|
+
console.log(' Doc ID:', docProps.id);
|
|
46
|
+
console.log(' Title:', docProps.title);
|
|
47
|
+
console.log(' Description:', docProps.description);
|
|
48
|
+
console.log(' Author:', docProps.author);
|
|
49
|
+
console.log(' Initial Version:', docProps.version, '\r\n');
|
|
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);
|
|
61
|
+
|
|
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
|
+
}
|
|
70
|
+
|
|
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
|
+
}
|
|
80
|
+
|
|
81
|
+
// The file update tasks can now all be done async now
|
|
82
|
+
// we have the file and folder structure in place
|
|
22
83
|
|
|
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
|
+
});
|
|
92
|
+
|
|
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
|
+
fs.writeFile(hdocBookFilePath, JSON.stringify(hdocbookFile, null, 2), function writeJSON(err) {
|
|
101
|
+
if (err) return console.log('Error updating:',hdocBookFilePath, '\r\n', err);
|
|
102
|
+
console.log('Updated:', hdocBookFilePath);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Update hdocbook-project.json
|
|
106
|
+
const packageFilePath = path.join(bookPath, 'package.json');
|
|
107
|
+
const packageFile = require(packageFilePath);
|
|
108
|
+
packageFile.name = docProps.id;
|
|
109
|
+
packageFile.version = docProps.version;
|
|
110
|
+
hdocbookFile.description = docProps.description;
|
|
111
|
+
hdocbookFile.version = docProps.version;
|
|
112
|
+
hdocbookFile.author = docProps.author;
|
|
113
|
+
fs.writeFile(packageFilePath, JSON.stringify(packageFile, null, 2), function writeJSON(err) {
|
|
114
|
+
if (err) return console.log('Error updating:',packageFilePath, '\r\n', err);
|
|
115
|
+
console.log('Updated:', packageFilePath);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
} else {
|
|
119
|
+
console.error('Template path does not exist:', templatePath);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
console.error('Target book path already exists:', bookPath);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
exports.run = function (server_path, source_path, md) {
|
|
23
129
|
// GERRY: The init function should create a new starting point HDocBook folder structure
|
|
24
130
|
// ready to run the preview server and start editing.
|
|
25
131
|
//
|
|
26
132
|
// The init function should prompt for the ID of the doc book, title and initial version, then
|
|
27
133
|
// create the required files and folders. Its possible to just create a template and copy
|
|
28
|
-
// those files into place, with a few variable replacements.
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
console.log("Init is not yet implemented");
|
|
134
|
+
// those files into place, with a few variable replacements.
|
|
33
135
|
|
|
136
|
+
console.log('Hornbill HDocBook Init', '\r\n');
|
|
137
|
+
prompt.start();
|
|
138
|
+
prompt.get(promptProps, function (err, result) {
|
|
139
|
+
if (err) {
|
|
140
|
+
console.error(err);
|
|
141
|
+
return err;
|
|
142
|
+
}
|
|
143
|
+
createBook(server_path, source_path, result);
|
|
144
|
+
});
|
|
34
145
|
|
|
35
146
|
};
|
|
36
147
|
})();
|
package/hdoc-stats.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Required modules
|
|
6
6
|
// /const { STATUS_CODES } = require('http');
|
|
7
7
|
const fs = require('fs');
|
|
8
|
-
|
|
8
|
+
const path = require('path');
|
|
9
9
|
const dree = require('dree');
|
|
10
10
|
const html2text = require('html-to-text');
|
|
11
11
|
const { markdownToTxt } = require('markdown-to-txt');
|
package/hdoc.js
CHANGED
|
@@ -84,7 +84,7 @@ const { createCipheriv } = require('crypto');
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
console.log('Hornbill HDocBook Tools v'
|
|
87
|
+
console.log('Hornbill HDocBook Tools v' + getHdocPackageVersion(packageFile), '\r\n');
|
|
88
88
|
console.log(' Server Path:', __dirname);
|
|
89
89
|
console.log(' Document Path:', source_path, '\r\n');
|
|
90
90
|
|
|
@@ -99,7 +99,7 @@ const { createCipheriv } = require('crypto');
|
|
|
99
99
|
stats.run(ui_path, source_path, md, verbose);
|
|
100
100
|
} else if (command == 'init') {
|
|
101
101
|
const init = require(path.join(__dirname, 'hdoc-init.js'));
|
|
102
|
-
init.run(
|
|
102
|
+
init.run(__dirname, source_path, md);
|
|
103
103
|
} else if (command == 'help') {
|
|
104
104
|
const init = require(path.join(__dirname, 'hdoc-help.js'));
|
|
105
105
|
init.run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hdoc-tools",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
|
5
5
|
"main": "hdoc.js",
|
|
6
6
|
"bin": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"cookie-parser": "^1.4.6",
|
|
27
27
|
"dree": "^3.4.2",
|
|
28
28
|
"express": "^4.18.2",
|
|
29
|
+
"fs-extra": "^11.1.0",
|
|
29
30
|
"hdoc-tools": "^0.1.0",
|
|
30
31
|
"highlight.js": "^11.6.0",
|
|
31
32
|
"html-to-text": "^8.2.1",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"markdown-it-front-matter": "^0.2.3",
|
|
37
38
|
"markdown-to-txt": "^2.0.1",
|
|
38
39
|
"multer": "^1.4.5-lts.1",
|
|
40
|
+
"prompt": "^1.3.0",
|
|
39
41
|
"stream": "0.0.2",
|
|
40
42
|
"words-count": "^2.0.2"
|
|
41
43
|
}
|