hdoc-tools 0.8.22 → 0.8.23
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-build-db.js +141 -0
- package/hdoc-build.js +10 -10
- package/hdoc.js +3 -3
- package/package.json +2 -1
package/hdoc-build-db.js
ADDED
@@ -0,0 +1,141 @@
|
|
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
|
+
'relative_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
|
+
],
|
19
|
+
hdoc_meta: [
|
20
|
+
'doc_id INTEGER',
|
21
|
+
'contributor_count INTEGER UNINDEXED',
|
22
|
+
'edit_url UNINDEXED',
|
23
|
+
'last_commit UNINDEXED'
|
24
|
+
],
|
25
|
+
hdoc_contributors: [
|
26
|
+
'doc_id INTEGER',
|
27
|
+
'login',
|
28
|
+
'name',
|
29
|
+
'avatar UNINDEXED',
|
30
|
+
'url UNINDEXED'
|
31
|
+
]
|
32
|
+
};
|
33
|
+
|
34
|
+
exports.create_table = function (db, table, cols, virtual, fts5) {
|
35
|
+
const table_created = hdoc_index.create_table(db, table, cols, virtual, fts5);
|
36
|
+
if (table_created !== null) {
|
37
|
+
return `\nError creating table: ${table_created}`;
|
38
|
+
} else {
|
39
|
+
console.log(`\nTable created: ${table}`);
|
40
|
+
}
|
41
|
+
return null;
|
42
|
+
};
|
43
|
+
|
44
|
+
exports.create_db = function (db_path, doc_id) {
|
45
|
+
let response = {
|
46
|
+
error: null,
|
47
|
+
db: null
|
48
|
+
};
|
49
|
+
console.log('Performing SQlite index creation...');
|
50
|
+
let db_name = path.join(db_path, doc_id, 'index.db');
|
51
|
+
response.db = new database(db_name);
|
52
|
+
response.db.pragma('encoding="UTF-8"');
|
53
|
+
console.log(`\nDatabase created: ${db_name}`);
|
54
|
+
|
55
|
+
// Create tables
|
56
|
+
for (const key in db_schema) {
|
57
|
+
if (db_schema.hasOwnProperty(key)) {
|
58
|
+
const virtual = key === 'hdoc_index' ? true : false;
|
59
|
+
const fts5 = key === 'hdoc_index' ? true : false;
|
60
|
+
const table_created_error = this.create_table(response.db, key, db_schema[key], virtual, fts5);
|
61
|
+
if (table_created_error !== null) {
|
62
|
+
console.log(table_created_error);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return response;
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.populate_index = function (db, doc_id, book_config, index_records, verbose = false) {
|
70
|
+
let response = {
|
71
|
+
success: false,
|
72
|
+
index_success_count: 0,
|
73
|
+
error: ''
|
74
|
+
};
|
75
|
+
|
76
|
+
if (!book_config.tags) book_config.tags = [];
|
77
|
+
|
78
|
+
for (let i = 0; i < index_records.length; i++) {
|
79
|
+
let index_path_name = index_records[i].relative_path.replace('\\', '/').replace(`${doc_id}/`, '');
|
80
|
+
index_path_name = index_path_name.replace(path.extname(index_records[i].relative_path), '');
|
81
|
+
const index_vals = [
|
82
|
+
index_path_name,
|
83
|
+
doc_id,
|
84
|
+
book_config.audience.join(','),
|
85
|
+
book_config.tags.join(','),
|
86
|
+
index_records[i].index_html.fm_props.title,
|
87
|
+
index_records[i].index_html.text,
|
88
|
+
index_records[i].index_html.preview,
|
89
|
+
book_config.productFamily
|
90
|
+
];
|
91
|
+
const index_response = hdoc_index.insert_record(db, 'hdoc_index', db_schema.hdoc_index, index_vals);
|
92
|
+
if (!index_response.success) {
|
93
|
+
console.log(`Index record creation failed - ${doc_id}/${index_records[i].index_html.fm_props.title}: ${index_response.error}`);
|
94
|
+
continue;
|
95
|
+
}
|
96
|
+
|
97
|
+
// Now add metadata
|
98
|
+
const meta_vals = [
|
99
|
+
parseInt(index_response.row_id, 10),
|
100
|
+
index_records[i].metadata.contributor_count,
|
101
|
+
index_records[i].metadata.edit_url,
|
102
|
+
index_records[i].metadata.last_commit
|
103
|
+
];
|
104
|
+
const meta_response = hdoc_index.insert_record(db, 'hdoc_meta', db_schema.hdoc_meta, meta_vals);
|
105
|
+
if (!meta_response.success) {
|
106
|
+
console.log(`Index metadata record creation failed - ${doc_id}/${index_response.row_id}/${index_records[i].index_html.fm_props.title}: ${meta_response.error}`);
|
107
|
+
continue;
|
108
|
+
}
|
109
|
+
if (verbose) {
|
110
|
+
console.log(`Inserted index record ${index_response.row_id}: ${doc_id} - ${index_records[i].index_html.fm_props.title}`);
|
111
|
+
console.log(`Inserted index metadata record for index ID: ${meta_response.row_id}`);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Now add contributor records
|
115
|
+
for (let j = 0; j < index_records[i].contributors.length; j++) {
|
116
|
+
const contrib_vals = [
|
117
|
+
parseInt(index_response.row_id, 10),
|
118
|
+
index_records[i].contributors[j].login,
|
119
|
+
index_records[i].contributors[j].name,
|
120
|
+
index_records[i].contributors[j].avatar_url,
|
121
|
+
index_records[i].contributors[j].html_url
|
122
|
+
];
|
123
|
+
const cont_response = hdoc_index.insert_record(db, 'hdoc_contributors', db_schema.hdoc_contributors, contrib_vals);
|
124
|
+
if (!cont_response.success) {
|
125
|
+
console.log(`Index document contributor record creation failed - ${doc_id}/${index_response.row_id}/${index_records[i].index_html.fm_props.title}: ${cont_response.error}`);
|
126
|
+
continue;
|
127
|
+
}
|
128
|
+
if (verbose) {
|
129
|
+
console.log(`Inserted document contributor recordL ${cont_response.row_id}`);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
response.index_success_count++;
|
134
|
+
|
135
|
+
}
|
136
|
+
response.success = true;
|
137
|
+
console.log(`\nIndex Build Complete:`);
|
138
|
+
console.log(`${response.index_success_count} document index records created.`);
|
139
|
+
return response;
|
140
|
+
};
|
141
|
+
})();
|
package/hdoc-build.js
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
static_html_files = [],
|
38
38
|
work_path_content = '';
|
39
39
|
|
40
|
-
const transform_static_html = function (file_path) {
|
40
|
+
const transform_static_html = async function (file_path) {
|
41
41
|
if (fs.existsSync(file_path.path)) {
|
42
42
|
// Load HTML file
|
43
43
|
let html_txt = fs.readFileSync(file_path.path, 'utf8');
|
@@ -211,7 +211,7 @@
|
|
211
211
|
}
|
212
212
|
};
|
213
213
|
|
214
|
-
const transform_markdown_and_save_html = function (file_path) {
|
214
|
+
const transform_markdown_and_save_html = async function (file_path) {
|
215
215
|
conversion_attempted++;
|
216
216
|
if (fs.existsSync(file_path.path)) {
|
217
217
|
// Load markdown file
|
@@ -603,7 +603,7 @@
|
|
603
603
|
//console.log(JSON.stringify(bc, null, 2));
|
604
604
|
};
|
605
605
|
|
606
|
-
exports.run = function (source_path, verbose, github_api_token) {
|
606
|
+
exports.run = async function (source_path, verbose, github_api_token) {
|
607
607
|
if (github_api_token !== '') {
|
608
608
|
git_token = github_api_token;
|
609
609
|
}
|
@@ -669,14 +669,14 @@
|
|
669
669
|
dree.scan(work_path, dreeOptions, build_file_callback);
|
670
670
|
|
671
671
|
// Work through MD files and convert to HTML
|
672
|
-
md_files.
|
673
|
-
transform_markdown_and_save_html(
|
674
|
-
}
|
675
|
-
|
672
|
+
for (let i = 0; i < md_files.length; i++) {
|
673
|
+
await transform_markdown_and_save_html(md_files[i]);
|
674
|
+
}
|
675
|
+
|
676
676
|
// Work through Static HTML files and add Frontmatter tags
|
677
|
-
static_html_files.
|
678
|
-
transform_static_html(
|
679
|
-
}
|
677
|
+
for (let i = 0; i < static_html_files.length; i++) {
|
678
|
+
await transform_static_html(static_html_files[i]);
|
679
|
+
}
|
680
680
|
|
681
681
|
// Output to console
|
682
682
|
console.log(` MD files found: ${conversion_attempted}`);
|
package/hdoc.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/env node
|
1
|
+
#!/usr/bin/env node
|
2
2
|
|
3
|
-
(function () {
|
3
|
+
(async function () {
|
4
4
|
'use strict';
|
5
5
|
|
6
6
|
const preRun = require('./validateNodeVer.js'),
|
@@ -71,7 +71,7 @@
|
|
71
71
|
server.run(ui_path, source_path);
|
72
72
|
} else if (command == 'build') {
|
73
73
|
const builder = require(path.join(__dirname, 'hdoc-build.js'));
|
74
|
-
builder.run(source_path, verbose, git_token);
|
74
|
+
await builder.run(source_path, verbose, git_token);
|
75
75
|
} else if (command == 'stats') {
|
76
76
|
const stats = require(path.join(__dirname, 'hdoc-stats.js'));
|
77
77
|
stats.run(ui_path, source_path, verbose);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hdoc-tools",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.23",
|
4
4
|
"description": "Hornbill HDocBook Development Support Tool",
|
5
5
|
"main": "hdoc.js",
|
6
6
|
"bin": {
|
@@ -10,6 +10,7 @@
|
|
10
10
|
"hdoc.js",
|
11
11
|
"hdoc-db.js",
|
12
12
|
"hdoc-build.js",
|
13
|
+
"hdoc-build-db.js",
|
13
14
|
"hdoc-help.js",
|
14
15
|
"hdoc-init.js",
|
15
16
|
"hdoc-module.js",
|