spec-up-t 1.3.1 → 1.4.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.
Files changed (130) hide show
  1. package/.github/copilot-instructions.md +13 -0
  2. package/assets/compiled/body.js +17 -11
  3. package/assets/compiled/head.css +6 -4
  4. package/assets/css/collapse-definitions.css +0 -1
  5. package/assets/css/create-pdf.css +4 -2
  6. package/assets/css/create-term-filter.css +4 -4
  7. package/assets/css/definition-buttons-container.css +60 -0
  8. package/assets/css/insert-trefs.css +7 -0
  9. package/assets/css/sidebar-toc.css +2 -1
  10. package/assets/css/terms-and-definitions.css +73 -22
  11. package/assets/js/add-href-to-snapshot-link.js +16 -9
  12. package/assets/js/addAnchorsToTerms.js +1 -1
  13. package/assets/js/charts.js +10 -0
  14. package/assets/js/collapse-definitions.js +13 -2
  15. package/assets/js/collapse-meta-info.js +11 -9
  16. package/assets/js/definition-button-container-utils.js +82 -0
  17. package/assets/js/edit-term-buttons.js +77 -20
  18. package/assets/js/github-issues.js +35 -0
  19. package/assets/js/github-repo-info.js +144 -0
  20. package/assets/js/highlight-heading-plus-sibling-nodes.test.js +18 -0
  21. package/assets/js/insert-trefs.js +62 -13
  22. package/assets/js/mermaid-diagrams.js +11 -0
  23. package/assets/js/terminology-section-utility-container/README.md +107 -0
  24. package/assets/js/terminology-section-utility-container/create-alphabet-index.js +17 -0
  25. package/assets/js/{create-term-filter.js → terminology-section-utility-container/create-term-filter.js} +11 -44
  26. package/assets/js/terminology-section-utility-container/hide-show-utility-container.js +21 -0
  27. package/assets/js/terminology-section-utility-container/search.js +203 -0
  28. package/assets/js/terminology-section-utility-container.js +203 -0
  29. package/assets/js/tooltips.js +283 -0
  30. package/config/asset-map.json +24 -16
  31. package/index.js +57 -390
  32. package/package.json +5 -2
  33. package/src/add-remove-xref-source.js +20 -21
  34. package/src/collect-external-references.js +8 -337
  35. package/src/collect-external-references.test.js +440 -33
  36. package/src/configure.js +8 -109
  37. package/src/create-docx.js +7 -6
  38. package/src/create-pdf.js +15 -14
  39. package/src/freeze-spec-data.js +46 -0
  40. package/src/git-info.test.js +76 -0
  41. package/src/health-check/destination-gitignore-checker.js +5 -3
  42. package/src/health-check/external-specs-checker.js +5 -4
  43. package/src/health-check/specs-configuration-checker.js +2 -1
  44. package/src/health-check/term-references-checker.js +5 -3
  45. package/src/health-check/terms-intro-checker.js +2 -1
  46. package/src/health-check/tref-term-checker.js +8 -7
  47. package/src/health-check.js +8 -7
  48. package/src/init.js +3 -2
  49. package/src/install-from-boilerplate/add-gitignore-entries.js +3 -2
  50. package/src/install-from-boilerplate/add-scripts-keys.js +5 -4
  51. package/src/install-from-boilerplate/boilerplate/README.md +1 -1
  52. package/src/install-from-boilerplate/boilerplate/spec/example-markup-in-markdown.md +1 -1
  53. package/src/install-from-boilerplate/boilerplate/spec/spec-head.md +1 -1
  54. package/src/install-from-boilerplate/boilerplate/specs.json +2 -1
  55. package/src/install-from-boilerplate/config-scripts-keys.js +3 -3
  56. package/src/install-from-boilerplate/copy-boilerplate.js +2 -1
  57. package/src/install-from-boilerplate/copy-system-files.js +4 -3
  58. package/src/install-from-boilerplate/custom-update.js +12 -1
  59. package/src/install-from-boilerplate/help.txt +1 -1
  60. package/src/install-from-boilerplate/menu.sh +6 -6
  61. package/src/json-key-validator.js +17 -11
  62. package/src/markdown-it/README.md +207 -0
  63. package/src/markdown-it/definition-lists.js +397 -0
  64. package/src/markdown-it/index.js +83 -0
  65. package/src/markdown-it/link-enhancement.js +98 -0
  66. package/src/markdown-it/plugins.js +118 -0
  67. package/src/markdown-it/table-enhancement.js +97 -0
  68. package/src/markdown-it/template-tag-syntax.js +152 -0
  69. package/src/parsers/index.js +16 -0
  70. package/src/parsers/spec-parser.js +152 -0
  71. package/src/parsers/spec-parser.test.js +109 -0
  72. package/src/parsers/template-tag-parser.js +277 -0
  73. package/src/parsers/template-tag-parser.test.js +107 -0
  74. package/src/pipeline/configuration/configure-starterpack.js +200 -0
  75. package/src/{create-external-specs-list.js → pipeline/configuration/create-external-specs-list.js} +13 -12
  76. package/src/{create-term-index.js → pipeline/configuration/create-term-index.js} +19 -18
  77. package/src/{create-versions-index.js → pipeline/configuration/create-versions-index.js} +4 -3
  78. package/src/{insert-term-index.js → pipeline/configuration/insert-term-index.js} +2 -2
  79. package/src/pipeline/configuration/prepare-spec-configuration.js +70 -0
  80. package/src/pipeline/parsing/apply-markdown-it-extensions.js +35 -0
  81. package/src/pipeline/parsing/create-markdown-parser.js +94 -0
  82. package/src/pipeline/parsing/create-markdown-parser.test.js +49 -0
  83. package/src/{html-dom-processor.js → pipeline/postprocessing/definition-list-postprocessor.js} +69 -10
  84. package/src/{escape-handler.js → pipeline/preprocessing/escape-processor.js} +3 -1
  85. package/src/{fix-markdown-files.js → pipeline/preprocessing/normalize-terminology-markdown.js} +41 -31
  86. package/src/pipeline/references/collect-external-references.js +307 -0
  87. package/src/pipeline/references/external-references-service.js +231 -0
  88. package/src/pipeline/references/fetch-terms-from-index.js +198 -0
  89. package/src/pipeline/references/match-term.js +34 -0
  90. package/src/{collectExternalReferences/matchTerm.test.js → pipeline/references/match-term.test.js} +8 -2
  91. package/src/pipeline/references/process-xtrefs-data.js +94 -0
  92. package/src/pipeline/references/xtref-utils.js +166 -0
  93. package/src/pipeline/rendering/render-spec-document.js +146 -0
  94. package/src/pipeline/rendering/render-utils.js +154 -0
  95. package/src/utils/LOGGER.md +81 -0
  96. package/src/utils/{doesUrlExist.js → does-url-exist.js} +4 -3
  97. package/src/utils/fetch.js +5 -4
  98. package/src/utils/file-opener.js +3 -2
  99. package/src/utils/git-info.js +77 -0
  100. package/src/utils/logger.js +74 -0
  101. package/src/utils/regex-patterns.js +471 -0
  102. package/src/utils/regex-patterns.test.js +281 -0
  103. package/templates/template.html +56 -21
  104. package/assets/js/create-alphabet-index.js +0 -60
  105. package/assets/js/hide-show-utility-container.js +0 -16
  106. package/assets/js/index.js +0 -87
  107. package/assets/js/search.js +0 -365
  108. package/src/collectExternalReferences/fetchTermsFromIndex.js +0 -284
  109. package/src/collectExternalReferences/matchTerm.js +0 -32
  110. package/src/collectExternalReferences/processXTrefsData.js +0 -108
  111. package/src/freeze.js +0 -90
  112. package/src/markdown-it-extensions.js +0 -395
  113. package/src/references.js +0 -114
  114. /package/assets/css/{bootstrap.min.css → embedded-libraries/bootstrap.min.css} +0 -0
  115. /package/assets/css/{prism.css → embedded-libraries/prism.css} +0 -0
  116. /package/assets/css/{prism.dark.css → embedded-libraries/prism.dark.css} +0 -0
  117. /package/assets/css/{prism.default.css → embedded-libraries/prism.default.css} +0 -0
  118. /package/assets/js/{bootstrap.bundle.min.js → embedded-libraries/bootstrap.bundle.min.js} +0 -0
  119. /package/assets/js/{chart.js → embedded-libraries/chart.js} +0 -0
  120. /package/assets/js/{diff.min.js → embedded-libraries/diff.min.js} +0 -0
  121. /package/assets/js/{font-awesome.js → embedded-libraries/font-awesome.js} +0 -0
  122. /package/assets/js/{mermaid.js → embedded-libraries/mermaid.js} +0 -0
  123. /package/assets/js/{notyf.js → embedded-libraries/notyf.js} +0 -0
  124. /package/assets/js/{popper.js → embedded-libraries/popper.js} +0 -0
  125. /package/assets/js/{prism.dark.js → embedded-libraries/prism.dark.js} +0 -0
  126. /package/assets/js/{prism.default.js → embedded-libraries/prism.default.js} +0 -0
  127. /package/assets/js/{prism.js → embedded-libraries/prism.js} +0 -0
  128. /package/assets/js/{tippy.js → embedded-libraries/tippy.js} +0 -0
  129. /package/src/{escape-mechanism.js → pipeline/preprocessing/escape-placeholder-utils.js} +0 -0
  130. /package/src/utils/{isLineWithDefinition.js → is-line-with-definition.js} +0 -0
@@ -1,12 +1,13 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const Logger = require('./utils/logger');
3
4
 
4
5
  // Resolve the path to specs.json in the root directory
5
6
  const JSON_FILE = path.resolve(process.cwd(), 'specs.json');
6
7
 
7
8
  // Check if the JSON file exists
8
9
  if (!fs.existsSync(JSON_FILE)) {
9
- console.error(`Error: ${JSON_FILE} does not exist.`);
10
+ Logger.error(`Error: ${JSON_FILE} does not exist.`);
10
11
  process.exit(1);
11
12
  }
12
13
 
@@ -30,7 +31,7 @@ function askMode() {
30
31
  } else if (mode === 'view' || mode === 'v') {
31
32
  showReferences();
32
33
  } else {
33
- console.log('Invalid option. Please enter add, remove, or view.');
34
+ Logger.warn('Invalid option. Please enter add, remove, or view.');
34
35
  askMode();
35
36
  }
36
37
  });
@@ -84,15 +85,15 @@ function askRemoveEntry() {
84
85
  // Function to show current external references
85
86
  function showReferences() {
86
87
  const data = JSON.parse(fs.readFileSync(JSON_FILE, 'utf8'));
87
- console.log('Current external references (xref):');
88
+ Logger.info('Current external references (xref):');
88
89
 
89
90
  data.specs[0].external_specs.forEach(spec => {
90
- console.log('--- External Reference: ---');
91
- console.log(`Short name: ${spec.external_spec}`);
92
- console.log(`GitHub Page: ${spec.gh_page}`);
93
- console.log(`URL: ${spec.url}`);
94
- console.log(`Terms Directory: ${spec.terms_dir}`);
95
- console.log('\n');
91
+ Logger.separator();
92
+ Logger.highlight(`Short name: ${spec.external_spec}`);
93
+ Logger.info(`GitHub Page: ${spec.gh_page}`);
94
+ Logger.info(`URL: ${spec.url}`);
95
+ Logger.info(`Terms Directory: ${spec.terms_dir}`);
96
+ Logger.separator();
96
97
  });
97
98
  rl.close();
98
99
  }
@@ -103,7 +104,7 @@ function updateJSON() {
103
104
  const data = JSON.parse(fs.readFileSync(JSON_FILE, 'utf8'));
104
105
 
105
106
  if (!data.specs || !Array.isArray(data.specs) || !data.specs[0].external_specs) {
106
- console.error('Error: Invalid JSON structure. "specs[0].external_specs" is missing.');
107
+ Logger.error('Error: Invalid JSON structure. "specs[0].external_specs" is missing.');
107
108
  process.exit(1);
108
109
  }
109
110
 
@@ -115,19 +116,17 @@ function updateJSON() {
115
116
  );
116
117
 
117
118
  if (exists) {
118
- console.log(
119
- `Entry with external_spec "${inputs.external_spec}" already exists. No changes made.`
120
- );
119
+ Logger.warn(`Entry with external_spec "${inputs.external_spec}" already exists. No changes made.`);
121
120
  return;
122
121
  }
123
122
 
124
123
  // Add the new entry if it doesn't exist
125
124
  externalSpecs.push(inputs);
126
125
 
127
- fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
128
- console.log(`Updated successfully.`);
126
+ fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
127
+ Logger.success(`Updated successfully.`);
129
128
  } catch (error) {
130
- console.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
129
+ Logger.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
131
130
  process.exit(1);
132
131
  }
133
132
  }
@@ -138,7 +137,7 @@ function removeEntry(externalSpec) {
138
137
  const data = JSON.parse(fs.readFileSync(JSON_FILE, 'utf8'));
139
138
 
140
139
  if (!data.specs || !Array.isArray(data.specs) || !data.specs[0].external_specs) {
141
- console.error('Error: Invalid JSON structure. "specs[0].external_specs" is missing.');
140
+ Logger.error('Error: Invalid JSON structure. "specs[0].external_specs" is missing.');
142
141
  process.exit(1);
143
142
  }
144
143
 
@@ -150,17 +149,17 @@ function removeEntry(externalSpec) {
150
149
  );
151
150
 
152
151
  if (filteredSpecs.length === externalSpecs.length) {
153
- console.log(`No entry found with external_spec "${externalSpec}".`);
152
+ Logger.warn(`No entry found with external_spec "${externalSpec}".`);
154
153
  return;
155
154
  }
156
155
 
157
156
  // Update the JSON structure
158
157
  data.specs[0].external_specs = filteredSpecs;
159
158
 
160
- fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
161
- console.log(`Removed entry successfully.`);
159
+ fs.writeFileSync(JSON_FILE, JSON.stringify(data, null, 2), 'utf8');
160
+ Logger.success(`Removed entry successfully.`);
162
161
  } catch (error) {
163
- console.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
162
+ Logger.error(`Error: Failed to update ${JSON_FILE}.`, error.message);
164
163
  process.exit(1);
165
164
  }
166
165
  }
@@ -1,343 +1,14 @@
1
1
  /**
2
- * @file Collects and processes external reference information for cross-specification linking.
3
- *
4
- * This script fetches the latest commit hash of term files from GitHub repositories
5
- * configured in specs.json, then generates both JavaScript and JSON files containing
6
- * cross-reference (xref/tref) data for use in specifications.
7
- *
8
- * Example of the output:
9
- *
10
- * const allXTrefs = {
11
- "xtrefs": [
12
- {
13
- "externalSpec": "toip1",
14
- "term": "SSI",
15
- "repoUrl": "https://github.com/henkvancann/ctwg-main-glossary",
16
- "terms_dir": "spec/terms-definitions",
17
- "owner": "henkvancann",
18
- "repo": "ctwg-main-glossary",
19
- "site": null,
20
- "commitHash": "not found",
21
- "content": "This term was not found in the external repository."
22
- },
23
- {
24
- "externalSpec": "vlei1",
25
- "term": "vlei-ecosystem-governance-framework",
26
- "repoUrl": "https://github.com/henkvancann/vlei-glossary",
27
- "terms_dir": "spec/terms-definitions",
28
- "owner": "henkvancann",
29
- "repo": "vlei-glossary",
30
- "avatarUrl": "https://avatars.githubusercontent.com/u/479356?v=4",
31
- "site": null,
32
- "commitHash": "5e36b16e58984eeaccae22116a2bf058ab01a0e9",
33
- "content": "[[def: vlei-ecosystem-governance-framework, vlei ecosystem governance framework]]\n\n~ The Verifiable LEI (vLEI) Ecosystem [[ref: governance-framework]] Information Trust Policies. It's a **document** that defines the … etc"
34
- }
35
- ]
36
- };
37
- *
38
- * @author Kor Dwarshuis
39
- * @version 1.0.0
40
- * @since 2024-06-09
2
+ * @file Compatibility wrapper forwarding to the pipeline-based reference modules.
3
+ *
4
+ * External callers historically required this path, so we re-export the relocated
5
+ * implementations to preserve the public API while keeping the new directory layout.
41
6
  */
42
7
 
43
- require('dotenv').config();
44
- const { shouldProcessFile } = require('./utils/file-filter');
45
- const path = require('path');
46
- const fs = require('fs-extra');
47
- const readlineSync = require('readline-sync');
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
- */
56
- function isXTrefInMarkdown(xtref, markdownContent) {
57
- // Escape special regex characters in externalSpec and term
58
- const escapedSpec = xtref.externalSpec.replace(/[.*+?^${}()|[\]\\-]/g, '\\$&');
59
- const escapedTerm = xtref.term.replace(/[.*+?^${}()|[\]\\-]/g, '\\$&');
60
-
61
- // Check for both the term and with any alias (accounting for spaces)
62
- const regexTerm = new RegExp(`\\[\\[(?:x|t)ref:\\s*${escapedSpec},\\s*${escapedTerm}(?:,\\s*[^\\]]+)?\\]\\]`, 'g');
63
- return regexTerm.test(markdownContent);
64
- }
65
-
66
- /**
67
- * Helper function to process an XTref string and return an object.
68
- *
69
- * @param {string} xtref - The xtref string to process
70
- * @returns {Object} An object with externalSpec, term, and optional alias properties
71
- */
72
- function processXTref(xtref) {
73
- const parts = xtref
74
- .replace(/\[\[(?:xref|tref):/, '')
75
- .replace(/\]\]/, '')
76
- .trim()
77
- .split(/,/);
78
-
79
- const xtrefObject = {
80
- externalSpec: parts[0].trim(),
81
- term: parts[1].trim()
82
- };
83
-
84
- // Add alias if provided (third parameter)
85
- if (parts.length > 2 && parts[2].trim()) {
86
- xtrefObject.alias = parts[2].trim();
87
- }
88
-
89
- return xtrefObject;
90
- }
91
-
92
- /**
93
- * Adds new xtrefs found in markdown content to the existing collection
94
- *
95
- * @param {string} allMarkdownContent - The content to search for XTrefs
96
- * @param {Object} allXTrefs - An object with an array property "xtrefs" to which new entries will be added
97
- * @returns {Object} The updated allXTrefs object
98
- */
99
- function addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs) {
100
- const regex = /\[\[(?:xref|tref):.*?\]\]/g;
101
- if (regex.test(allMarkdownContent)) {
102
- const xtrefs = allMarkdownContent.match(regex);
103
- xtrefs.forEach(xtref => {
104
- const newXTrefObj = processXTref(xtref);
105
- if (!allXTrefs?.xtrefs?.some(existingXTref =>
106
- existingXTref.term === newXTrefObj.term &&
107
- existingXTref.externalSpec === newXTrefObj.externalSpec)) {
108
- allXTrefs.xtrefs.push(newXTrefObj);
109
- }
110
- });
111
- }
112
- return allXTrefs;
113
- }
114
-
115
- /**
116
- * Extends xtref objects with additional information like repository URL and directory information
117
- *
118
- * @param {Object} config - The configuration object from specs.json
119
- * @param {Array} xtrefs - Array of xtref objects to extend
120
- */
121
- function extendXTrefs(config, xtrefs) {
122
- if (config.specs[0].external_specs_repos) {
123
- 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");
124
- return;
125
- }
126
-
127
- xtrefs.forEach(xtref => {
128
- config.specs.forEach(spec => {
129
- // Loop through "external_specs" to find the repository URL for each xtref
130
- xtref.repoUrl = null;
131
- xtref.terms_dir = null;
132
- xtref.owner = null;
133
- xtref.repo = null;
134
-
135
- spec.external_specs.forEach(repo => {
136
- if (repo.external_spec === xtref.externalSpec) {
137
- xtref.repoUrl = repo.url;
138
- xtref.terms_dir = repo.terms_dir;
139
- const urlParts = new URL(xtref.repoUrl).pathname.split('/');
140
- xtref.owner = urlParts[1];
141
- xtref.repo = urlParts[2];
142
- xtref.avatarUrl = repo.avatar_url;
143
- xtref.ghPageUrl = repo.gh_page; // Add GitHub Pages URL
144
- }
145
- });
146
-
147
- // Loop through "external_specs" to find the site URL for each xtref
148
- xtref.site = null;
149
- spec?.external_specs?.forEach(externalSpec => {
150
- const key = Object.keys(externalSpec)[0];
151
- if (key === xtref.externalSpec) {
152
- xtref.site = externalSpec[key];
153
- }
154
- });
155
- });
156
- });
157
- }
158
-
159
- /**
160
- * Processes the main functionality after initial validation checks
161
- *
162
- * @param {Object} config - The configuration object from specs.json
163
- * @param {string} GITHUB_API_TOKEN - The GitHub API token
164
- */
165
- function processExternalReferences(config, GITHUB_API_TOKEN) {
166
- const { processXTrefsData } = require('./collectExternalReferences/processXTrefsData.js');
167
- const { doesUrlExist } = require('./utils/doesUrlExist.js');
168
- const externalSpecsRepos = config.specs[0].external_specs;
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 = '.cache';
203
- if (!fs.existsSync(outputDir)) {
204
- fs.mkdirSync(outputDir);
205
- }
206
-
207
- // Ensure that the 'xtrefs-history' in outputDir 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
- // Initialize an object to store all xtrefs.
219
- let allXTrefs = { xtrefs: [] };
220
-
221
- // If the output JSON file exists, load its data.
222
- if (fs.existsSync(outputPathJSON)) {
223
- const existingXTrefs = fs.readJsonSync(outputPathJSON);
224
- if (existingXTrefs?.xtrefs) {
225
- allXTrefs = existingXTrefs;
226
- }
227
- }
228
-
229
- // Collect all markdown content
230
- let allMarkdownContent = '';
231
-
232
- // Read all main repo Markdown files from a list of directories and concatenate their content into a single string.
233
- specTermsDirectories.forEach(specDirectory => {
234
- fs.readdirSync(specDirectory).forEach(file => {
235
- if (shouldProcessFile(file)) {
236
- const filePath = path.join(specDirectory, file);
237
- const markdown = fs.readFileSync(filePath, 'utf8');
238
- allMarkdownContent += markdown;
239
- }
240
- });
241
- });
242
-
243
- // Remove existing entries if not in the combined markdown content
244
- allXTrefs.xtrefs = allXTrefs.xtrefs.filter(existingXTref => {
245
- return isXTrefInMarkdown(existingXTref, allMarkdownContent);
246
- });
247
-
248
- addNewXTrefsFromMarkdown(allMarkdownContent, allXTrefs);
249
-
250
- // Example at this point:
251
- // allXTrefs.xtrefs: [
252
- // { externalSpec: 'kmg-1', term: 'authentic-chained-data-container' },
253
- // ]
254
-
255
- // Extend each xref with additional data and fetch commit information from GitHub.
256
- extendXTrefs(config, allXTrefs.xtrefs);
257
-
258
- // Example at this point:
259
- // allXTrefs.xtrefs: [
260
- // {
261
- // externalSpec: 'kmg-1',
262
- // term: 'authentic-chained-data-container',
263
- // repoUrl: 'https://github.com/henkvancann/keri-main-glossary',
264
- // terms_dir: 'spec/terms-definitions',
265
- // owner: 'henkvancann',
266
- // repo: 'keri-main-glossary',
267
- // site: null
268
- // }
269
- // ]
270
-
271
- processXTrefsData(allXTrefs, GITHUB_API_TOKEN, outputPathJSON, outputPathJS, outputPathJSTimeStamped);
272
- }
273
-
274
- /**
275
- * Collects external references from markdown files and processes them into usable data files.
276
- *
277
- * @function collectExternalReferences
278
- * @param {Object} options - Configuration options
279
- * @param {string} [options.pat] - GitHub Personal Access Token (overrides environment variable)
280
- * @returns {void}
281
- *
282
- * @description
283
- * This function performs several key operations:
284
- * 1. Optionally uses GitHub PAT for better API performance and higher rate limits
285
- * 2. Checks validity of repository URLs
286
- * 3. Extracts xref/tref patterns from markdown content
287
- * 4. Extends references with repository metadata
288
- * 5. Processes references to fetch commit information
289
- * 6. Generates output files in both JS and JSON formats
290
- *
291
- * Note: The function will run without a GitHub token but may encounter rate limits.
292
- * For better performance, provide a GitHub Personal Access Token via environment
293
- * variable or the options parameter.
294
- *
295
- * @example
296
- * // Basic usage
297
- * collectExternalReferences();
298
- *
299
- * // With explicit PAT
300
- * collectExternalReferences({ pat: 'github_pat_xxxxxxxxxxxx' });
301
- */
302
- function collectExternalReferences(options = {}) {
303
- const config = fs.readJsonSync('specs.json');
304
- const externalSpecsRepos = config.specs[0].external_specs;
305
- const GITHUB_API_TOKEN = options.pat || process.env.GITHUB_API_TOKEN;
306
-
307
- const explanationNoExternalReferences =
308
- `❌ No external references were found in the specs.json file.
309
-
310
- There is no point in continuing without external references, so we stop here.
311
-
312
- Please add external references to the specs.json file that you will find at the root of your project.
313
-
314
- `;
315
-
316
- // First do some checks
317
- // Show informational message if no token is available
318
- if (!GITHUB_API_TOKEN) {
319
- console.log('ℹ️ No GitHub Personal Access Token (PAT) found. Running without authentication (may hit rate limits).');
320
- console.log('💡 For better performance, set up a PAT: https://blockchainbird.github.io/spec-up-t-website/docs/getting-started/github-token\n');
321
- }
322
-
323
- if (externalSpecsRepos.length === 0) {
324
- // Check if the URLs for the external specs repositories are valid, and prompt the user to abort if they are not.
325
- console.log(explanationNoExternalReferences);
326
- const userInput = readlineSync.question('Press any key');
327
-
328
- // React to user pressing any key
329
- if (userInput.trim() !== '') {
330
- console.log('ℹ️ Stopping...');
331
- return;
332
- }
333
- } else {
334
- processExternalReferences(config, GITHUB_API_TOKEN);
335
- }
336
- }
8
+ const pipelineModule = require('./pipeline/references/collect-external-references');
9
+ const xtrefUtils = require('./pipeline/references/xtref-utils');
337
10
 
338
11
  module.exports = {
339
- collectExternalReferences,
340
- isXTrefInMarkdown,
341
- addNewXTrefsFromMarkdown,
342
- processXTref
12
+ ...pipelineModule,
13
+ ...xtrefUtils
343
14
  };