hdoc-tools 0.19.7 → 0.20.0
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/custom_modules/tips.js +88 -86
- package/hdoc-build-db.js +260 -198
- package/hdoc-build-pdf.js +219 -173
- package/hdoc-build.js +1480 -1503
- package/hdoc-bump.js +123 -109
- package/hdoc-create.js +108 -95
- package/hdoc-db.js +97 -125
- package/hdoc-help.js +48 -51
- package/hdoc-init.js +181 -147
- package/hdoc-module.js +708 -723
- package/hdoc-serve.js +390 -361
- package/hdoc-stats.js +187 -184
- package/hdoc-validate.js +956 -717
- package/hdoc-ver.js +43 -43
- package/hdoc.js +142 -124
- package/package.json +60 -60
- package/templates/init/_hdocbook/hdocbook.json +23 -23
- package/templates/init/hdocbook-project.json +10 -10
- package/templates/init/package.json +8 -10
- package/ui/js/doc.hornbill.js +708 -659
- package/validateNodeVer.js +17 -14
package/hdoc-init.js
CHANGED
@@ -1,147 +1,181 @@
|
|
1
|
-
(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
1
|
+
(() => {
|
2
|
+
// Required modules
|
3
|
+
const prompt = require("prompt");
|
4
|
+
const fs = require("fs-extra");
|
5
|
+
const path = require("node:path");
|
6
|
+
|
7
|
+
// Configure prompt module preferences
|
8
|
+
prompt.message = false;
|
9
|
+
const promptProps = [
|
10
|
+
{
|
11
|
+
name: "id",
|
12
|
+
description: "Document ID",
|
13
|
+
validator: /^[a-z][a-z0-9-]+[a-z0-9]$/,
|
14
|
+
warning:
|
15
|
+
"Document ID must only contain lower case letters, decimal digits and dashes.",
|
16
|
+
required: true,
|
17
|
+
},
|
18
|
+
{
|
19
|
+
name: "title",
|
20
|
+
description: "Title",
|
21
|
+
required: true,
|
22
|
+
},
|
23
|
+
{
|
24
|
+
name: "description",
|
25
|
+
description: "Description",
|
26
|
+
required: true,
|
27
|
+
},
|
28
|
+
{
|
29
|
+
name: "version",
|
30
|
+
description: "Initial Version",
|
31
|
+
validator: /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$/,
|
32
|
+
warning:
|
33
|
+
"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,
|
40
|
+
},
|
41
|
+
];
|
42
|
+
|
43
|
+
const createBook = (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
|
+
// Now copy files over
|
52
|
+
const templatePath = path.join(server_path, "templates", "init");
|
53
|
+
console.log("Copying template from:", templatePath);
|
54
|
+
|
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
|
+
}
|
63
|
+
|
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
|
+
}
|
73
|
+
|
74
|
+
// Update hdocbook-project.json
|
75
|
+
const hdocBookProjectFilePath = path.join(
|
76
|
+
source_path,
|
77
|
+
"hdocbook-project.json",
|
78
|
+
);
|
79
|
+
const hdocBookProjectFile = require(hdocBookProjectFilePath);
|
80
|
+
hdocBookProjectFile.docId = docProps.id;
|
81
|
+
fs.writeFile(
|
82
|
+
hdocBookProjectFilePath,
|
83
|
+
JSON.stringify(hdocBookProjectFile, null, 2),
|
84
|
+
function writeJSON(err) {
|
85
|
+
if (err)
|
86
|
+
return console.error(
|
87
|
+
"Error updating:",
|
88
|
+
hdocBookProjectFilePath,
|
89
|
+
"\r\n",
|
90
|
+
err,
|
91
|
+
);
|
92
|
+
console.log("Updated:", hdocBookProjectFilePath);
|
93
|
+
},
|
94
|
+
);
|
95
|
+
|
96
|
+
// Update root/hdocbook.json
|
97
|
+
const hdocBookFilePath = path.join(bookContentRoot, "hdocbook.json");
|
98
|
+
const hdocbookFile = require(hdocBookFilePath);
|
99
|
+
hdocbookFile.docId = docProps.id;
|
100
|
+
hdocbookFile.title = docProps.title;
|
101
|
+
hdocbookFile.description = docProps.description;
|
102
|
+
hdocbookFile.version = docProps.version;
|
103
|
+
hdocbookFile.publicSource = `https://github.com/Hornbill-Docs/${docProps.id}`;
|
104
|
+
hdocbookFile.navigation.items[0].items = [
|
105
|
+
{
|
106
|
+
text: "Welcome",
|
107
|
+
link: `${docProps.id}/index`,
|
108
|
+
},
|
109
|
+
];
|
110
|
+
fs.writeFile(
|
111
|
+
hdocBookFilePath,
|
112
|
+
JSON.stringify(hdocbookFile, null, 2),
|
113
|
+
function writeJSON(err) {
|
114
|
+
if (err)
|
115
|
+
return console.error(
|
116
|
+
"Error updating:",
|
117
|
+
hdocBookFilePath,
|
118
|
+
"\r\n",
|
119
|
+
err,
|
120
|
+
);
|
121
|
+
console.log("Updated:", hdocBookFilePath);
|
122
|
+
},
|
123
|
+
);
|
124
|
+
|
125
|
+
// Update package.json
|
126
|
+
const packageFilePath = path.join(source_path, "package.json");
|
127
|
+
const packageFile = require(packageFilePath);
|
128
|
+
packageFile.name = docProps.id;
|
129
|
+
packageFile.version = docProps.version;
|
130
|
+
hdocbookFile.description = docProps.description;
|
131
|
+
hdocbookFile.version = docProps.version;
|
132
|
+
hdocbookFile.author = docProps.author;
|
133
|
+
fs.writeFile(
|
134
|
+
packageFilePath,
|
135
|
+
JSON.stringify(packageFile, null, 2),
|
136
|
+
function writeJSON(err) {
|
137
|
+
if (err)
|
138
|
+
return console.error(
|
139
|
+
"Error updating:",
|
140
|
+
packageFilePath,
|
141
|
+
"\r\n",
|
142
|
+
err,
|
143
|
+
);
|
144
|
+
console.log("Updated:", packageFilePath);
|
145
|
+
},
|
146
|
+
);
|
147
|
+
|
148
|
+
// Rename gitignore to .gitignore
|
149
|
+
const gitignorePath = path.join(source_path, "gitignore");
|
150
|
+
const newGitignorePath = path.join(source_path, ".gitignore");
|
151
|
+
fs.renameSync(gitignorePath, newGitignorePath);
|
152
|
+
} else {
|
153
|
+
console.error("Template path does not exist:", templatePath);
|
154
|
+
process.exit(1);
|
155
|
+
}
|
156
|
+
};
|
157
|
+
|
158
|
+
exports.run = (server_path, source_path, md) => {
|
159
|
+
// GERRY: The init function should create a new starting point HDocBook folder structure
|
160
|
+
// ready to run the preview server and start editing.
|
161
|
+
//
|
162
|
+
// The init function should prompt for the ID of the doc book, title and initial version, then
|
163
|
+
// create the required files and folders. Its possible to just create a template and copy
|
164
|
+
// those files into place, with a few variable replacements.
|
165
|
+
|
166
|
+
console.log("Hornbill HDocBook Init", "\r\n");
|
167
|
+
|
168
|
+
const curr_dirs = source_path.split(path.sep);
|
169
|
+
const doc_id = curr_dirs[curr_dirs.length - 1];
|
170
|
+
|
171
|
+
prompt.start();
|
172
|
+
promptProps[0].default = doc_id;
|
173
|
+
prompt.get(promptProps, (err, result) => {
|
174
|
+
if (err) {
|
175
|
+
console.error(err);
|
176
|
+
return err;
|
177
|
+
}
|
178
|
+
createBook(server_path, source_path, result);
|
179
|
+
});
|
180
|
+
};
|
181
|
+
})();
|