spec-up-t 1.2.3 → 1.2.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/.sonarlint/connectedMode.json +5 -0
- package/assets/compiled/body.js +35 -32
- package/assets/compiled/head.css +7 -5
- package/assets/compiled/head.js +3 -3
- package/assets/css/add-bootstrap-classes-to-images.css +34 -0
- package/assets/css/adjust-font-size.css +6 -11
- package/assets/css/backToTop.css +0 -1
- package/assets/css/image-full-size.css +44 -0
- package/assets/css/index.css +1 -2
- package/assets/css/pdf-styles.css +23 -27
- package/assets/css/repo-issues.css +0 -6
- package/assets/css/search.css +0 -1
- package/assets/css/sidebar-toc.css +13 -12
- package/assets/css/terms-and-definitions.css +43 -37
- package/assets/js/add-bootstrap-classes-to-images.js +98 -0
- package/assets/js/add-href-to-snapshot-link.js +2 -1
- package/assets/js/addAnchorsToTerms.js +0 -1
- package/assets/js/adjust-font-size.js +0 -9
- package/assets/js/create-alphabet-index.js +12 -3
- package/assets/js/create-term-filter.js +12 -0
- package/assets/js/custom-elements.js +13 -18
- package/assets/js/declare-markdown-it.js +1 -1
- package/assets/js/hide-show-utility-container.js +17 -0
- package/assets/js/highlightMenuItems.js +3 -3
- package/assets/js/image-full-size.js +76 -0
- package/assets/js/index.js +1 -5
- package/assets/js/insert-trefs.js +2 -2
- package/assets/js/modal.js +3 -3
- package/assets/js/search.js +15 -3
- package/assets/js/utils.js +2 -3
- package/index.js +7 -17
- package/package.json +2 -2
- package/src/README.md +3 -3
- package/src/add-remove-xref-source.js +0 -2
- package/src/asset-map.json +5 -0
- package/src/collect-external-references.js +187 -179
- package/src/collectExternalReferences/fetchTermsFromIndex.js +2 -1
- package/src/config/paths.js +2 -2
- package/src/create-external-specs-list.js +1 -1
- package/src/create-term-index.js +126 -22
- package/src/fix-markdown-files.js +152 -90
- package/src/health-check/external-specs-checker.js +173 -94
- package/src/health-check/output-gitignore-checker.js +327 -191
- package/src/health-check/specs-configuration-checker.js +288 -210
- package/src/health-check/term-references-checker.js +200 -123
- package/src/health-check/tref-term-checker.js +264 -179
- package/src/health-check.js +52 -36
- package/src/init.js +1 -4
- package/src/insert-term-index.js +5 -5
- package/src/install-from-boilerplate/add-scripts-keys.js +3 -1
- package/src/install-from-boilerplate/boilerplate/gitignore +2 -1
- package/src/install-from-boilerplate/config-system-files.js +9 -1
- package/src/install-from-boilerplate/copy-system-files.js +1 -1
- package/src/markdown-it-extensions.js +199 -106
- package/src/references.js +1 -2
- package/src/utils/doesUrlExist.js +7 -5
- package/src/utils/fetch.js +14 -14
- package/templates/template.html +1 -2
- package/assets/js/insert-xrefs.js +0 -370
- package/src/create-term-relations.js +0 -131
- package/src/prepare-tref.js +0 -174
package/assets/js/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
function delegateEvent(type, selector, fn, options = {}){
|
|
3
2
|
return (options.container || document).addEventListener(type, e => {
|
|
4
3
|
let match = e.target.closest(selector);
|
|
@@ -6,8 +5,8 @@ function delegateEvent(type, selector, fn, options = {}){
|
|
|
6
5
|
}, options);
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
skipAnimationFrame = fn => requestAnimationFrame(() => requestAnimationFrame(fn));
|
|
8
|
+
const skipAnimationFrame = fn => requestAnimationFrame(() => requestAnimationFrame(fn));
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
const domReady = new Promise(resolve => {
|
|
12
11
|
document.addEventListener('DOMContentLoaded', e => resolve())
|
|
13
12
|
});
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { initialize } = require('./src/init');
|
|
2
|
-
const {fetchExternalTerms} = require('./src/utils/fetch');
|
|
3
2
|
|
|
4
3
|
module.exports = async function (options = {}) {
|
|
5
4
|
try {
|
|
@@ -18,9 +17,6 @@ module.exports = async function (options = {}) {
|
|
|
18
17
|
const { runJsonKeyValidatorSync } = require('./src/json-key-validator.js');
|
|
19
18
|
runJsonKeyValidatorSync();
|
|
20
19
|
|
|
21
|
-
// const { createTermRelations } = require('./src/create-term-relations.js');
|
|
22
|
-
// createTermRelations();
|
|
23
|
-
|
|
24
20
|
const { createTermIndex } = require('./src/create-term-index.js');
|
|
25
21
|
createTermIndex();
|
|
26
22
|
|
|
@@ -29,9 +25,7 @@ module.exports = async function (options = {}) {
|
|
|
29
25
|
|
|
30
26
|
const findPkgDir = require('find-pkg-dir');
|
|
31
27
|
const modulePath = findPkgDir(__dirname);
|
|
32
|
-
let config = fs.readJsonSync('
|
|
33
|
-
|
|
34
|
-
const externalTerms = fetchExternalTerms();
|
|
28
|
+
let config = fs.readJsonSync('./.cache/specs-generated.json');
|
|
35
29
|
|
|
36
30
|
const createExternalSpecsList = require('./src/create-external-specs-list.js');
|
|
37
31
|
|
|
@@ -42,16 +36,14 @@ module.exports = async function (options = {}) {
|
|
|
42
36
|
|
|
43
37
|
const { fixMarkdownFiles } = require('./src/fix-markdown-files.js');
|
|
44
38
|
|
|
45
|
-
// const { prepareTref } = require('./src/prepare-tref.js');
|
|
46
|
-
|
|
47
39
|
let template = fs.readFileSync(path.join(modulePath, 'templates/template.html'), 'utf8');
|
|
48
40
|
let assets = fs.readJsonSync(modulePath + '/src/asset-map.json');
|
|
49
41
|
let externalReferences;
|
|
50
42
|
let references = [];
|
|
51
43
|
let definitions = [];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
let toc;
|
|
45
|
+
let specGroups = {};
|
|
46
|
+
let noticeTitles = {};
|
|
55
47
|
|
|
56
48
|
const noticeTypes = {
|
|
57
49
|
note: 1,
|
|
@@ -61,7 +53,7 @@ module.exports = async function (options = {}) {
|
|
|
61
53
|
todo: 1
|
|
62
54
|
};
|
|
63
55
|
const spaceRegex = /\s+/g;
|
|
64
|
-
const specNameRegex = /^spec$|^spec
|
|
56
|
+
const specNameRegex = /^spec$|^spec-*\w+$/i;
|
|
65
57
|
const terminologyRegex = /^def$|^ref$|^xref|^tref$/i;
|
|
66
58
|
const specCorpus = fs.readJsonSync(modulePath + '/assets/compiled/refs.json');
|
|
67
59
|
const containers = require('markdown-it-container');
|
|
@@ -221,14 +213,12 @@ module.exports = async function (options = {}) {
|
|
|
221
213
|
}
|
|
222
214
|
];
|
|
223
215
|
|
|
224
|
-
// prepareTref(path.join(config.specs[0].spec_directory, config.specs[0].spec_terms_directory));
|
|
225
|
-
|
|
226
216
|
// Synchronously process markdown files
|
|
227
217
|
fixMarkdownFiles(path.join(config.specs[0].spec_directory, config.specs[0].spec_terms_directory));
|
|
228
218
|
|
|
229
219
|
function createScriptElementWithXTrefDataForEmbeddingInHtml() {
|
|
230
220
|
// Test if xtrefs-data.js exists, else make it an empty string
|
|
231
|
-
const inputPath = path.join('
|
|
221
|
+
const inputPath = path.join('.cache', 'xtrefs-data.js');
|
|
232
222
|
|
|
233
223
|
let xtrefsData = '';
|
|
234
224
|
if (fs.existsSync(inputPath)) {
|
|
@@ -397,7 +387,7 @@ module.exports = async function (options = {}) {
|
|
|
397
387
|
|
|
398
388
|
// Then filter to find the one with the terms-and-definitions-list class
|
|
399
389
|
const dlElements = allDls.filter(dl => {
|
|
400
|
-
return dl
|
|
390
|
+
return dl?.classList?.contains('terms-and-definitions-list');
|
|
401
391
|
});
|
|
402
392
|
|
|
403
393
|
// Find any transcluded term dt elements anywhere in the document
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
|
|
5
5
|
"main": "./index",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"gulp": "4.0.2",
|
|
35
35
|
"gulp-clean-css": "4.3.0",
|
|
36
36
|
"gulp-concat": "2.6.1",
|
|
37
|
-
"gulp-terser": "1.
|
|
37
|
+
"gulp-terser": "^2.1.0",
|
|
38
38
|
"jsdom": "^25.0.0",
|
|
39
39
|
"markdown-it": "^13.0.1",
|
|
40
40
|
"markdown-it-anchor": "^9.2.0",
|
package/src/README.md
CHANGED
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
<ul>
|
|
79
79
|
<li>Creates three output files:
|
|
80
80
|
<ul>
|
|
81
|
-
<li><code
|
|
82
|
-
<li><code
|
|
83
|
-
<li><code
|
|
81
|
+
<li><code>.cache/xtrefs-data.json</code> - JSON data file</li>
|
|
82
|
+
<li><code>.cache/xtrefs-data.js</code> - JavaScript module file</li>
|
|
83
|
+
<li><code>.cache/xtrefs-history/xtrefs-data-[timestamp].js</code> - Historical record</li>
|
|
84
84
|
</ul>
|
|
85
85
|
</li>
|
|
86
86
|
</ul>
|
|
@@ -125,7 +125,6 @@ function updateJSON() {
|
|
|
125
125
|
externalSpecs.push(inputs);
|
|
126
126
|
|
|
127
127
|
fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
|
|
128
|
-
// console.log(`Updated ${JSON_FILE} successfully.`);
|
|
129
128
|
console.log(`Updated successfully.`);
|
|
130
129
|
} catch (error) {
|
|
131
130
|
console.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
|
|
@@ -159,7 +158,6 @@ function removeEntry(externalSpec) {
|
|
|
159
158
|
data.specs[0].external_specs = filteredSpecs;
|
|
160
159
|
|
|
161
160
|
fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
|
|
162
|
-
// console.log(`Removed entry with external_spec "${externalSpec}" successfully.`);
|
|
163
161
|
console.log(`Removed entry successfully.`);
|
|
164
162
|
} catch (error) {
|
|
165
163
|
console.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
|
package/src/asset-map.json
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"assets/css/external-links.css",
|
|
24
24
|
"assets/css/repo-issues.css",
|
|
25
25
|
"assets/css/adjust-font-size.css",
|
|
26
|
+
"assets/css/image-full-size.css",
|
|
27
|
+
"assets/css/add-bootstrap-classes-to-images.css",
|
|
26
28
|
"assets/css/index.css"
|
|
27
29
|
],
|
|
28
30
|
"js": [
|
|
@@ -44,6 +46,7 @@
|
|
|
44
46
|
"assets/js/tippy.js",
|
|
45
47
|
"assets/js/diff.min.js",
|
|
46
48
|
"assets/js/edit-term-buttons.js",
|
|
49
|
+
"assets/js/hide-show-utility-container.js",
|
|
47
50
|
"assets/js/create-alphabet-index.js",
|
|
48
51
|
"assets/js/search.js",
|
|
49
52
|
"assets/js/highlightMenuItems.js",
|
|
@@ -66,6 +69,8 @@
|
|
|
66
69
|
"assets/js/close-off-canvas-menu.js",
|
|
67
70
|
"assets/js/index.js",
|
|
68
71
|
"assets/js/horizontal-scroll-hint.js",
|
|
72
|
+
"assets/js/add-bootstrap-classes-to-images.js",
|
|
73
|
+
"assets/js/image-full-size.js",
|
|
69
74
|
"assets/js/bootstrap.bundle.min.js"
|
|
70
75
|
]
|
|
71
76
|
}
|
|
@@ -40,39 +40,58 @@
|
|
|
40
40
|
* @since 2024-06-09
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
require('dotenv').config();
|
|
44
44
|
const { shouldProcessFile } = require('./utils/file-filter');
|
|
45
45
|
const path = require('path');
|
|
46
|
+
const fs = require('fs-extra');
|
|
47
|
+
const readlineSync = require('readline-sync');
|
|
46
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Checks if a specific xtref is present in the markdown content
|
|
51
|
+
*
|
|
52
|
+
* @param {Object} xtref - The xtref object to check for
|
|
53
|
+
* @param {string} markdownContent - The markdown content to search in
|
|
54
|
+
* @returns {boolean} True if the xtref is found in the content
|
|
55
|
+
*/
|
|
47
56
|
function isXTrefInMarkdown(xtref, markdownContent) {
|
|
48
57
|
const regex = new RegExp(`\\[\\[(?:x|t)ref:${xtref.externalSpec},\\s*${xtref.term}\\]\\]`, 'g');
|
|
49
58
|
return regex.test(markdownContent);
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Helper function to process an XTref string and return an object.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} xtref - The xtref string to process
|
|
65
|
+
* @returns {Object} An object with externalSpec and term properties
|
|
66
|
+
*/
|
|
53
67
|
function processXTref(xtref) {
|
|
54
68
|
let [externalSpec, term] = xtref
|
|
55
69
|
.replace(/\[\[(?:xref|tref):/, '')
|
|
56
70
|
.replace(/\]\]/, '')
|
|
57
71
|
.trim()
|
|
58
72
|
.split(/,/, 2);
|
|
59
|
-
|
|
73
|
+
const xtrefObject = {
|
|
60
74
|
externalSpec: externalSpec.trim(),
|
|
61
75
|
term: term.trim()
|
|
62
76
|
};
|
|
63
|
-
}
|
|
64
77
|
|
|
78
|
+
return xtrefObject;
|
|
79
|
+
}
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Adds new xtrefs found in markdown content to the existing collection
|
|
83
|
+
*
|
|
84
|
+
* @param {string} allMarkdownContent - The content to search for XTrefs
|
|
85
|
+
* @param {Object} allXTrefs - An object with an array property "xtrefs" to which new entries will be added
|
|
86
|
+
* @returns {Object} The updated allXTrefs object
|
|
87
|
+
*/
|
|
68
88
|
function addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs) {
|
|
69
89
|
const regex = /\[\[(?:xref|tref):.*?\]\]/g;
|
|
70
90
|
if (regex.test(allMarkdownContent)) {
|
|
71
91
|
const xtrefs = allMarkdownContent.match(regex);
|
|
72
92
|
xtrefs.forEach(xtref => {
|
|
73
93
|
const newXTrefObj = processXTref(xtref);
|
|
74
|
-
|
|
75
|
-
if (!allXTrefs.xtrefs.some(existingXTref =>
|
|
94
|
+
if (!allXTrefs?.xtrefs?.some(existingXTref =>
|
|
76
95
|
existingXTref.term === newXTrefObj.term &&
|
|
77
96
|
existingXTref.externalSpec === newXTrefObj.externalSpec)) {
|
|
78
97
|
allXTrefs.xtrefs.push(newXTrefObj);
|
|
@@ -82,6 +101,165 @@ function addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs) {
|
|
|
82
101
|
return allXTrefs;
|
|
83
102
|
}
|
|
84
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Extends xtref objects with additional information like repository URL and directory information
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} config - The configuration object from specs.json
|
|
108
|
+
* @param {Array} xtrefs - Array of xtref objects to extend
|
|
109
|
+
*/
|
|
110
|
+
function extendXTrefs(config, xtrefs) {
|
|
111
|
+
if (config.specs[0].external_specs_repos) {
|
|
112
|
+
console.log("ℹ️ PLEASE NOTE: Your specs.json file is outdated (not your fault, we changed something). Use this one: https://github.com/trustoverip/spec-up-t/blob/master/src/install-from-boilerplate/boilerplate/specs.json");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
xtrefs.forEach(xtref => {
|
|
117
|
+
config.specs.forEach(spec => {
|
|
118
|
+
// Loop through "external_specs" to find the repository URL for each xtref
|
|
119
|
+
xtref.repoUrl = null;
|
|
120
|
+
xtref.terms_dir = null;
|
|
121
|
+
xtref.owner = null;
|
|
122
|
+
xtref.repo = null;
|
|
123
|
+
|
|
124
|
+
spec.external_specs.forEach(repo => {
|
|
125
|
+
if (repo.external_spec === xtref.externalSpec) {
|
|
126
|
+
xtref.repoUrl = repo.url;
|
|
127
|
+
xtref.terms_dir = repo.terms_dir;
|
|
128
|
+
const urlParts = new URL(xtref.repoUrl).pathname.split('/');
|
|
129
|
+
xtref.owner = urlParts[1];
|
|
130
|
+
xtref.repo = urlParts[2];
|
|
131
|
+
xtref.avatarUrl = repo.avatar_url;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Loop through "external_specs" to find the site URL for each xtref
|
|
136
|
+
xtref.site = null;
|
|
137
|
+
spec?.external_specs?.forEach(externalSpec => {
|
|
138
|
+
const key = Object.keys(externalSpec)[0];
|
|
139
|
+
if (key === xtref.externalSpec) {
|
|
140
|
+
xtref.site = externalSpec[key];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Processes the main functionality after initial validation checks
|
|
149
|
+
*
|
|
150
|
+
* @param {Object} config - The configuration object from specs.json
|
|
151
|
+
* @param {string} GITHUB_API_TOKEN - The GitHub API token
|
|
152
|
+
* @param {Object} options - Configuration options
|
|
153
|
+
*/
|
|
154
|
+
function processExternalReferences(config, GITHUB_API_TOKEN, options) {
|
|
155
|
+
const { processXTrefsData } = require('./collectExternalReferences/processXTrefsData.js');
|
|
156
|
+
const { doesUrlExist } = require('./utils/doesUrlExist.js');
|
|
157
|
+
const externalSpecsRepos = config.specs[0].external_specs;
|
|
158
|
+
|
|
159
|
+
// Check if the URLs for the external specs repositories are valid, and prompt the user to abort if they are not.
|
|
160
|
+
externalSpecsRepos.forEach(repo => {
|
|
161
|
+
doesUrlExist(repo.url).then(exists => {
|
|
162
|
+
if (!exists) {
|
|
163
|
+
const userInput = readlineSync.question(
|
|
164
|
+
`❌ This external reference is not a valid URL:
|
|
165
|
+
|
|
166
|
+
Repository: ${repo.url},
|
|
167
|
+
|
|
168
|
+
Terms directory: ${repo.terms_dir}
|
|
169
|
+
|
|
170
|
+
Please fix the external references in the specs.json file that you will find at the root of your project.
|
|
171
|
+
|
|
172
|
+
Do you want to stop? (yes/no): `);
|
|
173
|
+
if (userInput.toLowerCase() === 'yes' || userInput.toLowerCase() === 'y') {
|
|
174
|
+
console.log('ℹ️ Stopping...');
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}).catch(error => {
|
|
179
|
+
console.error('❌ Error checking URL existence:', error);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Collect all directories that contain files with a term and definition
|
|
184
|
+
// This maps over the specs in the config file and constructs paths to directories
|
|
185
|
+
// where the term definition files are located.
|
|
186
|
+
const specTermsDirectories = config.specs.map(spec =>
|
|
187
|
+
path.join(spec.spec_directory, spec.spec_terms_directory)
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// Ensure that the 'output' directory exists, creating it if necessary.
|
|
191
|
+
const outputDir = '.cache';
|
|
192
|
+
if (!fs.existsSync(outputDir)) {
|
|
193
|
+
fs.mkdirSync(outputDir);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Ensure that the 'xtrefs-history' in outputDir exists, creating it if necessary.
|
|
197
|
+
const xtrefsHistoryDir = path.join(outputDir, 'xtrefs-history');
|
|
198
|
+
if (!fs.existsSync(xtrefsHistoryDir)) {
|
|
199
|
+
fs.mkdirSync(xtrefsHistoryDir);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Define paths for various output files, including JSON and JS files.
|
|
203
|
+
const outputPathJSON = path.join(outputDir, 'xtrefs-data.json');
|
|
204
|
+
const outputPathJS = path.join(outputDir, 'xtrefs-data.js');
|
|
205
|
+
const outputPathJSTimeStamped = path.join(xtrefsHistoryDir, `xtrefs-data-${Date.now()}.js`);
|
|
206
|
+
|
|
207
|
+
// Initialize an object to store all xtrefs.
|
|
208
|
+
let allXTrefs = { xtrefs: [] };
|
|
209
|
+
|
|
210
|
+
// If the output JSON file exists, load its data.
|
|
211
|
+
if (fs.existsSync(outputPathJSON)) {
|
|
212
|
+
const existingXTrefs = fs.readJsonSync(outputPathJSON);
|
|
213
|
+
if (existingXTrefs?.xtrefs) {
|
|
214
|
+
allXTrefs = existingXTrefs;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Collect all markdown content
|
|
219
|
+
let allMarkdownContent = '';
|
|
220
|
+
|
|
221
|
+
// Read all main repo Markdown files from a list of directories and concatenate their content into a single string.
|
|
222
|
+
specTermsDirectories.forEach(specDirectory => {
|
|
223
|
+
fs.readdirSync(specDirectory).forEach(file => {
|
|
224
|
+
if (shouldProcessFile(file)) {
|
|
225
|
+
const filePath = path.join(specDirectory, file);
|
|
226
|
+
const markdown = fs.readFileSync(filePath, 'utf8');
|
|
227
|
+
allMarkdownContent += markdown;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Remove existing entries if not in the combined markdown content
|
|
233
|
+
allXTrefs.xtrefs = allXTrefs.xtrefs.filter(existingXTref => {
|
|
234
|
+
return isXTrefInMarkdown(existingXTref, allMarkdownContent);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs);
|
|
238
|
+
|
|
239
|
+
// Example at this point:
|
|
240
|
+
// allXTrefs.xtrefs: [
|
|
241
|
+
// { externalSpec: 'kmg-1', term: 'authentic-chained-data-container' },
|
|
242
|
+
// ]
|
|
243
|
+
|
|
244
|
+
// Extend each xref with additional data and fetch commit information from GitHub.
|
|
245
|
+
extendXTrefs(config, allXTrefs.xtrefs);
|
|
246
|
+
|
|
247
|
+
// Example at this point:
|
|
248
|
+
// allXTrefs.xtrefs: [
|
|
249
|
+
// {
|
|
250
|
+
// externalSpec: 'kmg-1',
|
|
251
|
+
// term: 'authentic-chained-data-container',
|
|
252
|
+
// repoUrl: 'https://github.com/henkvancann/keri-main-glossary',
|
|
253
|
+
// terms_dir: 'spec/terms-definitions',
|
|
254
|
+
// owner: 'henkvancann',
|
|
255
|
+
// repo: 'keri-main-glossary',
|
|
256
|
+
// site: null
|
|
257
|
+
// }
|
|
258
|
+
// ]
|
|
259
|
+
|
|
260
|
+
processXTrefsData(allXTrefs, GITHUB_API_TOKEN, outputPathJSON, outputPathJS, outputPathJSTimeStamped, options);
|
|
261
|
+
}
|
|
262
|
+
|
|
85
263
|
/**
|
|
86
264
|
* Collects external references from markdown files and processes them into usable data files.
|
|
87
265
|
*
|
|
@@ -107,9 +285,6 @@ function addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs) {
|
|
|
107
285
|
* collectExternalReferences({ pat: 'github_pat_xxxxxxxxxxxx' });
|
|
108
286
|
*/
|
|
109
287
|
function collectExternalReferences(options = {}) {
|
|
110
|
-
require('dotenv').config();
|
|
111
|
-
const fs = require('fs-extra');
|
|
112
|
-
const readlineSync = require('readline-sync');
|
|
113
288
|
const config = fs.readJsonSync('specs.json');
|
|
114
289
|
const externalSpecsRepos = config.specs[0].external_specs;
|
|
115
290
|
const GITHUB_API_TOKEN = options.pat || process.env.GITHUB_API_TOKEN;
|
|
@@ -134,7 +309,6 @@ function collectExternalReferences(options = {}) {
|
|
|
134
309
|
|
|
135
310
|
`;
|
|
136
311
|
|
|
137
|
-
|
|
138
312
|
// First do some checks
|
|
139
313
|
|
|
140
314
|
// Do not run the script if the GitHub API token is not set
|
|
@@ -148,7 +322,6 @@ function collectExternalReferences(options = {}) {
|
|
|
148
322
|
return;
|
|
149
323
|
}
|
|
150
324
|
}
|
|
151
|
-
|
|
152
325
|
else if (externalSpecsRepos.length === 0) {
|
|
153
326
|
// Check if the URLs for the external specs repositories are valid, and prompt the user to abort if they are not.
|
|
154
327
|
console.log(explanationNoExternalReferences);
|
|
@@ -160,173 +333,8 @@ function collectExternalReferences(options = {}) {
|
|
|
160
333
|
return;
|
|
161
334
|
}
|
|
162
335
|
} else {
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function main() {
|
|
167
|
-
const { processXTrefsData } = require('./collectExternalReferences/processXTrefsData.js');
|
|
168
|
-
const { doesUrlExist } = require('./utils/doesUrlExist.js');
|
|
169
|
-
|
|
170
|
-
// Check if the URLs for the external specs repositories are valid, and prompt the user to abort if they are not.
|
|
171
|
-
externalSpecsRepos.forEach(repo => {
|
|
172
|
-
doesUrlExist(repo.url).then(exists => {
|
|
173
|
-
if (!exists) {
|
|
174
|
-
const userInput = readlineSync.question(
|
|
175
|
-
`❌ This external reference is not a valid URL:
|
|
176
|
-
|
|
177
|
-
Repository: ${repo.url},
|
|
178
|
-
|
|
179
|
-
Terms directory: ${repo.terms_dir}
|
|
180
|
-
|
|
181
|
-
Please fix the external references in the specs.json file that you will find at the root of your project.
|
|
182
|
-
|
|
183
|
-
Do you want to stop? (yes/no): `);
|
|
184
|
-
if (userInput.toLowerCase() === 'yes' || userInput.toLowerCase() === 'y') {
|
|
185
|
-
console.log('ℹ️ Stopping...');
|
|
186
|
-
process.exit(1);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}).catch(error => {
|
|
190
|
-
console.error('❌ Error checking URL existence:', error);
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Collect all directories that contain files with a term and definition
|
|
195
|
-
// This maps over the specs in the config file and constructs paths to directories
|
|
196
|
-
// where the term definition files are located.
|
|
197
|
-
const specTermsDirectories = config.specs.map(spec =>
|
|
198
|
-
path.join(spec.spec_directory, spec.spec_terms_directory)
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
// Ensure that the 'output' directory exists, creating it if necessary.
|
|
202
|
-
const outputDir = 'output';
|
|
203
|
-
if (!fs.existsSync(outputDir)) {
|
|
204
|
-
fs.mkdirSync(outputDir);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Ensure that the 'output/xtrefs-history' directory exists, creating it if necessary.
|
|
208
|
-
const xtrefsHistoryDir = path.join(outputDir, 'xtrefs-history');
|
|
209
|
-
if (!fs.existsSync(xtrefsHistoryDir)) {
|
|
210
|
-
fs.mkdirSync(xtrefsHistoryDir);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Define paths for various output files, including JSON and JS files.
|
|
214
|
-
const outputPathJSON = path.join(outputDir, 'xtrefs-data.json');
|
|
215
|
-
const outputPathJS = path.join(outputDir, 'xtrefs-data.js');
|
|
216
|
-
const outputPathJSTimeStamped = path.join(xtrefsHistoryDir, `xtrefs-data-${Date.now()}.js`);
|
|
217
|
-
|
|
218
|
-
// Function to extend xtref objects with additional information, such as repository URL and directory information.
|
|
219
|
-
function extendXTrefs(config, xtrefs) {
|
|
220
|
-
if (config.specs[0].external_specs_repos) {
|
|
221
|
-
console.log("ℹ️ PLEASE NOTE: Your specs.json file is outdated (not your fault, we changed something). Use this one: https://github.com/trustoverip/spec-up-t/blob/master/src/install-from-boilerplate/boilerplate/specs.json");
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
xtrefs.forEach(xtref => {
|
|
226
|
-
config.specs.forEach(spec => {
|
|
227
|
-
// Loop through "external_specs" to find the repository URL for each xtref
|
|
228
|
-
xtref.repoUrl = null;
|
|
229
|
-
xtref.terms_dir = null;
|
|
230
|
-
xtref.owner = null;
|
|
231
|
-
xtref.repo = null;
|
|
232
|
-
|
|
233
|
-
spec.external_specs.forEach(repo => {
|
|
234
|
-
if (repo.external_spec === xtref.externalSpec) {
|
|
235
|
-
xtref.repoUrl = repo.url;
|
|
236
|
-
xtref.terms_dir = repo.terms_dir;
|
|
237
|
-
const urlParts = new URL(xtref.repoUrl).pathname.split('/');
|
|
238
|
-
xtref.owner = urlParts[1];
|
|
239
|
-
xtref.repo = urlParts[2];
|
|
240
|
-
xtref.avatarUrl = repo.avatar_url;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// Loop through "external_specs" to find the site URL for each xtref
|
|
245
|
-
|
|
246
|
-
xtref.site = null;
|
|
247
|
-
if (spec.external_specs) {
|
|
248
|
-
spec.external_specs.forEach(externalSpec => {
|
|
249
|
-
const key = Object.keys(externalSpec)[0];
|
|
250
|
-
if (key === xtref.externalSpec) {
|
|
251
|
-
xtref.site = externalSpec[key];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Function to process and clean up xref / tref strings found in the markdown file, returning an object with `externalSpec` and `term` properties.
|
|
260
|
-
//TODO: check if this is correct
|
|
261
|
-
function processXTref(xtref) {
|
|
262
|
-
let [externalSpec, term] = xtref.replace(/\[\[(?:xref|tref):/, '').replace(/\]\]/, '').trim().split(/,/, 2);
|
|
263
|
-
const xtrefObject = {
|
|
264
|
-
externalSpec: externalSpec.trim(),
|
|
265
|
-
term: term.trim()
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
return xtrefObject;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Initialize an object to store all xtrefs.
|
|
272
|
-
let allXTrefs = { xtrefs: [] };
|
|
273
|
-
|
|
274
|
-
// If the output JSON file exists, load its data.
|
|
275
|
-
if (fs.existsSync(outputPathJSON)) {
|
|
276
|
-
const existingXTrefs = fs.readJsonSync(outputPathJSON);
|
|
277
|
-
if (existingXTrefs && existingXTrefs.xtrefs) {
|
|
278
|
-
allXTrefs = existingXTrefs;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Collect all markdown content
|
|
283
|
-
let allMarkdownContent = '';
|
|
284
|
-
|
|
285
|
-
// Read all main repo Markdown files from a list of directories and concatenate their content into a single string.
|
|
286
|
-
specTermsDirectories.forEach(specDirectory => {
|
|
287
|
-
fs.readdirSync(specDirectory).forEach(file => {
|
|
288
|
-
if (shouldProcessFile(file)) {
|
|
289
|
-
const filePath = path.join(specDirectory, file);
|
|
290
|
-
const markdown = fs.readFileSync(filePath, 'utf8');
|
|
291
|
-
allMarkdownContent += markdown;
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// Remove existing entries if not in the combined markdown content
|
|
297
|
-
allXTrefs.xtrefs = allXTrefs.xtrefs.filter(existingXTref => {
|
|
298
|
-
return isXTrefInMarkdown(existingXTref, allMarkdownContent);
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs);
|
|
302
|
-
|
|
303
|
-
// Example at this point:
|
|
304
|
-
// allXTrefs.xtrefs: [
|
|
305
|
-
// { externalSpec: 'kmg-1', term: 'authentic-chained-data-container' },
|
|
306
|
-
// ]
|
|
307
|
-
|
|
308
|
-
// Extend each xref with additional data and fetch commit information from GitHub.
|
|
309
|
-
extendXTrefs(config, allXTrefs.xtrefs);
|
|
310
|
-
|
|
311
|
-
// Example at this point:
|
|
312
|
-
// allXTrefs.xtrefs: [
|
|
313
|
-
// {
|
|
314
|
-
// externalSpec: 'kmg-1',
|
|
315
|
-
// term: 'authentic-chained-data-container',
|
|
316
|
-
// repoUrl: 'https://github.com/henkvancann/keri-main-glossary',
|
|
317
|
-
// terms_dir: 'spec/terms-definitions',
|
|
318
|
-
// owner: 'henkvancann',
|
|
319
|
-
// repo: 'keri-main-glossary',
|
|
320
|
-
// site: null
|
|
321
|
-
// }
|
|
322
|
-
// ]
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
processXTrefsData(allXTrefs, GITHUB_API_TOKEN, outputPathJSON, outputPathJS, outputPathJSTimeStamped, options);
|
|
326
|
-
|
|
336
|
+
processExternalReferences(config, GITHUB_API_TOKEN, options);
|
|
327
337
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
338
|
}
|
|
331
339
|
|
|
332
340
|
module.exports = {
|
|
@@ -33,10 +33,11 @@ function generateCacheKey(owner, repo) {
|
|
|
33
33
|
* @param {object} options - Options object
|
|
34
34
|
* @param {number} options.cacheTTL - Time-to-live for cache in milliseconds (default: 24 hours)
|
|
35
35
|
* @returns {object|null} - Cached data or null if not found or expired
|
|
36
|
+
* @example
|
|
37
|
+
* const cacheTTL = options.cacheTTL || 24 * 60 * 60 * 1000; // Default: 24 hours
|
|
36
38
|
*/
|
|
37
39
|
function getFromCache(cacheKey, options = {}) {
|
|
38
40
|
const cachePath = path.join(CACHE_DIR, `${cacheKey}.json`);
|
|
39
|
-
// const cacheTTL = options.cacheTTL || 24 * 60 * 60 * 1000; // Default: 24 hours
|
|
40
41
|
const cacheTTL = 0;
|
|
41
42
|
|
|
42
43
|
if (!fs.existsSync(cachePath)) {
|
package/src/config/paths.js
CHANGED
|
@@ -12,9 +12,9 @@ const paths = {};
|
|
|
12
12
|
// console.log(getAllPaths());
|
|
13
13
|
|
|
14
14
|
// Add paths
|
|
15
|
-
paths['output-local-terms'] = path.resolve('
|
|
15
|
+
paths['output-local-terms'] = path.resolve('.cache', 'local-terms-dir');
|
|
16
16
|
paths['specsjson'] = path.resolve('specs.json');
|
|
17
|
-
paths['githubcache'] = path.resolve('
|
|
17
|
+
paths['githubcache'] = path.resolve('.cache', 'github-cache');
|
|
18
18
|
|
|
19
19
|
module.exports = {
|
|
20
20
|
/**
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
module.exports = function createExternalSpecsList(config) {
|
|
16
|
-
if (!config
|
|
16
|
+
if (!config?.specs?.length || !Array.isArray(config.specs)) {
|
|
17
17
|
console.warn('❌ Invalid config format. Expected an object with a specs array.');
|
|
18
18
|
return '<p>No external specifications found.</p>';
|
|
19
19
|
}
|