hdoc-tools 0.11.7 → 0.11.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/LICENSE +21 -0
- package/hdoc-build-db.js +152 -152
- package/hdoc-build-pdf.js +172 -172
- package/hdoc-build.js +7 -2
- package/hdoc-bump.js +108 -108
- package/hdoc-create.js +90 -90
- package/hdoc-db.js +94 -94
- package/hdoc-help.js +49 -49
- package/hdoc-module.js +390 -390
- package/hdoc-serve.js +14 -17
- package/hdoc-validate.js +548 -548
- package/hdoc-ver.js +42 -42
- package/package.json +1 -1
- package/templates/doc-header-non-git.html +22 -22
- package/templates/doc-header.html +29 -29
- package/templates/pdf/css/custom-block.css +90 -90
- package/templates/pdf/css/fonts.css +221 -221
- package/templates/pdf/css/hdocs-pdf.css +246 -246
- package/templates/pdf/css/vars.css +393 -393
- package/templates/pdf/template-footer.html +19 -19
- package/templates/pdf/template-header.html +37 -37
- package/templates/pdf/template.html +20 -20
- package/templates/pdf-header-non-git.html +12 -12
- package/templates/pdf-header.html +16 -16
- package/validateNodeVer.js +12 -12
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Hornbill Docs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/hdoc-build-db.js
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
(function () {
|
2
|
-
'use strict';
|
3
|
-
|
4
|
-
const path = require('path'),
|
5
|
-
hdoc_index = require(path.join(__dirname, 'hdoc-db.js')),
|
6
|
-
database = require('better-sqlite3');
|
7
|
-
|
8
|
-
const db_schema = {
|
9
|
-
hdoc_index: [
|
10
|
-
'resource_url UNINDEXED',
|
11
|
-
'book_id',
|
12
|
-
'book_audience UNINDEXED',
|
13
|
-
'book_tags',
|
14
|
-
'doc_title',
|
15
|
-
'doc_content',
|
16
|
-
'doc_preview UNINDEXED',
|
17
|
-
'doc_family_id',
|
18
|
-
'doc_md5_hash UNINDEXED',
|
19
|
-
'doc_lastmod'
|
20
|
-
],
|
21
|
-
hdoc_meta: [
|
22
|
-
'resource_url',
|
23
|
-
'book_id',
|
24
|
-
'contributor_count INTEGER UNINDEXED',
|
25
|
-
'edit_url UNINDEXED',
|
26
|
-
'last_commit UNINDEXED',
|
27
|
-
'pdf_size INTEGER UNINDEXED'
|
28
|
-
],
|
29
|
-
hdoc_contributors: [
|
30
|
-
'resource_url',
|
31
|
-
'book_id',
|
32
|
-
'login',
|
33
|
-
'name',
|
34
|
-
'avatar UNINDEXED',
|
35
|
-
'url UNINDEXED'
|
36
|
-
]
|
37
|
-
};
|
38
|
-
|
39
|
-
exports.create_table = function (db, table, cols, virtual, fts5) {
|
40
|
-
const table_created = hdoc_index.create_table(db, table, cols, virtual, fts5);
|
41
|
-
if (table_created !== null) {
|
42
|
-
return `\nError creating table: ${table_created}`;
|
43
|
-
} else {
|
44
|
-
console.log(`\nTable created: ${table}`);
|
45
|
-
}
|
46
|
-
return null;
|
47
|
-
};
|
48
|
-
|
49
|
-
exports.create_db = function (db_path, doc_id) {
|
50
|
-
let response = {
|
51
|
-
error: null,
|
52
|
-
db: null
|
53
|
-
};
|
54
|
-
console.log('\nPerforming SQlite index creation...');
|
55
|
-
let db_name = path.join(db_path, doc_id, 'index.db');
|
56
|
-
response.db = new database(db_name);
|
57
|
-
response.db.pragma('encoding="UTF-8"');
|
58
|
-
console.log(`\nDatabase created: ${db_name}`);
|
59
|
-
|
60
|
-
// Create tables
|
61
|
-
for (const key in db_schema) {
|
62
|
-
if (db_schema.hasOwnProperty(key)) {
|
63
|
-
const virtual = key === 'hdoc_index' ? true : false;
|
64
|
-
const fts5 = key === 'hdoc_index' ? true : false;
|
65
|
-
const table_created_error = this.create_table(response.db, key, db_schema[key], virtual, fts5);
|
66
|
-
if (table_created_error !== null) {
|
67
|
-
console.log(table_created_error);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
return response;
|
72
|
-
};
|
73
|
-
|
74
|
-
exports.populate_index = async function (db, doc_id, book_config, index_records, verbose = false) {
|
75
|
-
let response = {
|
76
|
-
success: false,
|
77
|
-
index_success_count: 0,
|
78
|
-
error: ''
|
79
|
-
};
|
80
|
-
|
81
|
-
if (!book_config.tags) book_config.tags = [];
|
82
|
-
|
83
|
-
let indexPromises = [];
|
84
|
-
for (let i = 0; i < index_records.length; i++) {
|
85
|
-
indexPromises.push(index_records[i]);
|
86
|
-
}
|
87
|
-
await Promise.all(indexPromises.map(async (file) => {
|
88
|
-
let index_path_name = file.relative_path.replace('\\', '/');
|
89
|
-
index_path_name = '/' + index_path_name.replace(path.extname(file.relative_path), '');
|
90
|
-
const index_vals = [
|
91
|
-
index_path_name,
|
92
|
-
doc_id,
|
93
|
-
book_config.audience.join(','),
|
94
|
-
book_config.tags.join(','),
|
95
|
-
file.index_html.fm_props.title,
|
96
|
-
file.index_html.text,
|
97
|
-
file.index_html.preview,
|
98
|
-
book_config.productFamily,
|
99
|
-
file.md5,
|
100
|
-
file.lastmod
|
101
|
-
];
|
102
|
-
const index_response = hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
|
103
|
-
if (!index_response.success) {
|
104
|
-
console.log(`Index record creation failed - ${doc_id}/${file.index_html.fm_props.title}: ${index_response.error}`);
|
105
|
-
} else {
|
106
|
-
// Now add metadata
|
107
|
-
const meta_vals = [
|
108
|
-
index_path_name,
|
109
|
-
doc_id,
|
110
|
-
file.metadata.contributor_count,
|
111
|
-
file.metadata.edit_url,
|
112
|
-
file.metadata.last_commit,
|
113
|
-
file.pdf_size
|
114
|
-
];
|
115
|
-
const meta_response = await hdoc_index.insert_record(db, 'hdoc_meta', db_schema.hdoc_meta, meta_vals);
|
116
|
-
if (!meta_response.success) {
|
117
|
-
console.log(`Index metadata record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${meta_response.error}`);
|
118
|
-
} else {
|
119
|
-
if (verbose) {
|
120
|
-
console.log(`Inserted index record ${index_response.row_id}: ${doc_id} - ${file.index_html.fm_props.title}`);
|
121
|
-
console.log(`Inserted index metadata record for index ID: ${meta_response.row_id}`);
|
122
|
-
}
|
123
|
-
|
124
|
-
// Now add contributor records
|
125
|
-
for (let j = 0; j < file.contributors.length; j++) {
|
126
|
-
const contrib_vals = [
|
127
|
-
index_path_name,
|
128
|
-
doc_id,
|
129
|
-
file.contributors[j].login,
|
130
|
-
file.contributors[j].name,
|
131
|
-
file.contributors[j].avatar_url,
|
132
|
-
file.contributors[j].html_url
|
133
|
-
];
|
134
|
-
const cont_response = await hdoc_index.insert_record(db, 'hdoc_contributors', db_schema.hdoc_contributors, contrib_vals);
|
135
|
-
if (!cont_response.success) {
|
136
|
-
console.log(`Index document contributor record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${cont_response.error}`);
|
137
|
-
continue;
|
138
|
-
}
|
139
|
-
if (verbose) {
|
140
|
-
console.log(`Inserted document contributor recordL ${cont_response.row_id}`);
|
141
|
-
}
|
142
|
-
}
|
143
|
-
response.index_success_count++;
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
}));
|
148
|
-
|
149
|
-
response.success = true;
|
150
|
-
console.log(`\nIndex Build Complete: ${response.index_success_count} document index records created.`);
|
151
|
-
return response;
|
152
|
-
};
|
1
|
+
(function () {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
const path = require('path'),
|
5
|
+
hdoc_index = require(path.join(__dirname, 'hdoc-db.js')),
|
6
|
+
database = require('better-sqlite3');
|
7
|
+
|
8
|
+
const db_schema = {
|
9
|
+
hdoc_index: [
|
10
|
+
'resource_url UNINDEXED',
|
11
|
+
'book_id',
|
12
|
+
'book_audience UNINDEXED',
|
13
|
+
'book_tags',
|
14
|
+
'doc_title',
|
15
|
+
'doc_content',
|
16
|
+
'doc_preview UNINDEXED',
|
17
|
+
'doc_family_id',
|
18
|
+
'doc_md5_hash UNINDEXED',
|
19
|
+
'doc_lastmod'
|
20
|
+
],
|
21
|
+
hdoc_meta: [
|
22
|
+
'resource_url',
|
23
|
+
'book_id',
|
24
|
+
'contributor_count INTEGER UNINDEXED',
|
25
|
+
'edit_url UNINDEXED',
|
26
|
+
'last_commit UNINDEXED',
|
27
|
+
'pdf_size INTEGER UNINDEXED'
|
28
|
+
],
|
29
|
+
hdoc_contributors: [
|
30
|
+
'resource_url',
|
31
|
+
'book_id',
|
32
|
+
'login',
|
33
|
+
'name',
|
34
|
+
'avatar UNINDEXED',
|
35
|
+
'url UNINDEXED'
|
36
|
+
]
|
37
|
+
};
|
38
|
+
|
39
|
+
exports.create_table = function (db, table, cols, virtual, fts5) {
|
40
|
+
const table_created = hdoc_index.create_table(db, table, cols, virtual, fts5);
|
41
|
+
if (table_created !== null) {
|
42
|
+
return `\nError creating table: ${table_created}`;
|
43
|
+
} else {
|
44
|
+
console.log(`\nTable created: ${table}`);
|
45
|
+
}
|
46
|
+
return null;
|
47
|
+
};
|
48
|
+
|
49
|
+
exports.create_db = function (db_path, doc_id) {
|
50
|
+
let response = {
|
51
|
+
error: null,
|
52
|
+
db: null
|
53
|
+
};
|
54
|
+
console.log('\nPerforming SQlite index creation...');
|
55
|
+
let db_name = path.join(db_path, doc_id, 'index.db');
|
56
|
+
response.db = new database(db_name);
|
57
|
+
response.db.pragma('encoding="UTF-8"');
|
58
|
+
console.log(`\nDatabase created: ${db_name}`);
|
59
|
+
|
60
|
+
// Create tables
|
61
|
+
for (const key in db_schema) {
|
62
|
+
if (db_schema.hasOwnProperty(key)) {
|
63
|
+
const virtual = key === 'hdoc_index' ? true : false;
|
64
|
+
const fts5 = key === 'hdoc_index' ? true : false;
|
65
|
+
const table_created_error = this.create_table(response.db, key, db_schema[key], virtual, fts5);
|
66
|
+
if (table_created_error !== null) {
|
67
|
+
console.log(table_created_error);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
return response;
|
72
|
+
};
|
73
|
+
|
74
|
+
exports.populate_index = async function (db, doc_id, book_config, index_records, verbose = false) {
|
75
|
+
let response = {
|
76
|
+
success: false,
|
77
|
+
index_success_count: 0,
|
78
|
+
error: ''
|
79
|
+
};
|
80
|
+
|
81
|
+
if (!book_config.tags) book_config.tags = [];
|
82
|
+
|
83
|
+
let indexPromises = [];
|
84
|
+
for (let i = 0; i < index_records.length; i++) {
|
85
|
+
indexPromises.push(index_records[i]);
|
86
|
+
}
|
87
|
+
await Promise.all(indexPromises.map(async (file) => {
|
88
|
+
let index_path_name = file.relative_path.replace('\\', '/');
|
89
|
+
index_path_name = '/' + index_path_name.replace(path.extname(file.relative_path), '');
|
90
|
+
const index_vals = [
|
91
|
+
index_path_name,
|
92
|
+
doc_id,
|
93
|
+
book_config.audience.join(','),
|
94
|
+
book_config.tags.join(','),
|
95
|
+
file.index_html.fm_props.title,
|
96
|
+
file.index_html.text,
|
97
|
+
file.index_html.preview,
|
98
|
+
book_config.productFamily,
|
99
|
+
file.md5,
|
100
|
+
file.lastmod
|
101
|
+
];
|
102
|
+
const index_response = hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
|
103
|
+
if (!index_response.success) {
|
104
|
+
console.log(`Index record creation failed - ${doc_id}/${file.index_html.fm_props.title}: ${index_response.error}`);
|
105
|
+
} else {
|
106
|
+
// Now add metadata
|
107
|
+
const meta_vals = [
|
108
|
+
index_path_name,
|
109
|
+
doc_id,
|
110
|
+
file.metadata.contributor_count,
|
111
|
+
file.metadata.edit_url,
|
112
|
+
file.metadata.last_commit,
|
113
|
+
file.pdf_size
|
114
|
+
];
|
115
|
+
const meta_response = await hdoc_index.insert_record(db, 'hdoc_meta', db_schema.hdoc_meta, meta_vals);
|
116
|
+
if (!meta_response.success) {
|
117
|
+
console.log(`Index metadata record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${meta_response.error}`);
|
118
|
+
} else {
|
119
|
+
if (verbose) {
|
120
|
+
console.log(`Inserted index record ${index_response.row_id}: ${doc_id} - ${file.index_html.fm_props.title}`);
|
121
|
+
console.log(`Inserted index metadata record for index ID: ${meta_response.row_id}`);
|
122
|
+
}
|
123
|
+
|
124
|
+
// Now add contributor records
|
125
|
+
for (let j = 0; j < file.contributors.length; j++) {
|
126
|
+
const contrib_vals = [
|
127
|
+
index_path_name,
|
128
|
+
doc_id,
|
129
|
+
file.contributors[j].login,
|
130
|
+
file.contributors[j].name,
|
131
|
+
file.contributors[j].avatar_url,
|
132
|
+
file.contributors[j].html_url
|
133
|
+
];
|
134
|
+
const cont_response = await hdoc_index.insert_record(db, 'hdoc_contributors', db_schema.hdoc_contributors, contrib_vals);
|
135
|
+
if (!cont_response.success) {
|
136
|
+
console.log(`Index document contributor record creation failed - ${doc_id}/${index_response.row_id}/${file.index_html.fm_props.title}: ${cont_response.error}`);
|
137
|
+
continue;
|
138
|
+
}
|
139
|
+
if (verbose) {
|
140
|
+
console.log(`Inserted document contributor recordL ${cont_response.row_id}`);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
response.index_success_count++;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
}));
|
148
|
+
|
149
|
+
response.success = true;
|
150
|
+
console.log(`\nIndex Build Complete: ${response.index_success_count} document index records created.`);
|
151
|
+
return response;
|
152
|
+
};
|
153
153
|
})();
|