spec-up-t 1.2.2 → 1.2.4

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 (49) hide show
  1. package/.sonarlint/connectedMode.json +5 -0
  2. package/assets/compiled/body.js +31 -31
  3. package/assets/compiled/head.css +5 -5
  4. package/assets/compiled/head.js +3 -3
  5. package/assets/css/adjust-font-size.css +6 -11
  6. package/assets/css/backToTop.css +0 -1
  7. package/assets/css/index.css +1 -2
  8. package/assets/css/pdf-styles.css +23 -27
  9. package/assets/css/repo-issues.css +0 -6
  10. package/assets/css/search.css +0 -1
  11. package/assets/css/sidebar-toc.css +13 -12
  12. package/assets/css/terms-and-definitions.css +43 -37
  13. package/assets/js/add-href-to-snapshot-link.js +2 -1
  14. package/assets/js/addAnchorsToTerms.js +0 -1
  15. package/assets/js/adjust-font-size.js +0 -9
  16. package/assets/js/create-alphabet-index.js +1 -1
  17. package/assets/js/custom-elements.js +13 -18
  18. package/assets/js/declare-markdown-it.js +1 -1
  19. package/assets/js/highlightMenuItems.js +3 -3
  20. package/assets/js/index.js +1 -5
  21. package/assets/js/insert-trefs.js +2 -2
  22. package/assets/js/modal.js +3 -3
  23. package/assets/js/search.js +3 -3
  24. package/assets/js/utils.js +2 -3
  25. package/index.js +5 -15
  26. package/package.json +2 -2
  27. package/src/add-remove-xref-source.js +0 -2
  28. package/src/collect-external-references.js +187 -179
  29. package/src/collectExternalReferences/fetchTermsFromIndex.js +2 -1
  30. package/src/create-external-specs-list.js +1 -1
  31. package/src/fix-markdown-files.js +152 -90
  32. package/src/health-check/external-specs-checker.js +173 -94
  33. package/src/health-check/output-gitignore-checker.js +327 -191
  34. package/src/health-check/specs-configuration-checker.js +288 -210
  35. package/src/health-check/term-references-checker.js +200 -123
  36. package/src/health-check/tref-term-checker.js +264 -179
  37. package/src/health-check.js +51 -35
  38. package/src/init.js +0 -3
  39. package/src/install-from-boilerplate/boilerplate/gitignore +2 -1
  40. package/src/install-from-boilerplate/config-system-files.js +9 -1
  41. package/src/install-from-boilerplate/copy-system-files.js +1 -1
  42. package/src/install-from-boilerplate/menu.sh +17 -3
  43. package/src/markdown-it-extensions.js +199 -106
  44. package/src/references.js +1 -2
  45. package/src/utils/doesUrlExist.js +7 -5
  46. package/templates/template.html +1 -2
  47. package/assets/js/insert-xrefs.js +0 -370
  48. package/src/create-term-relations.js +0 -131
  49. package/src/prepare-tref.js +0 -174
@@ -1,174 +0,0 @@
1
- /**
2
- * @file prepare-tref.js
3
- * @description This module provides functionality to process markdown files in a directory recursively,
4
- * searching for specific `[[tref:]]` references, and replacing them with detailed information
5
- * fetched from a local JSON file (`xtrefs-data.json`). The information includes metadata such as
6
- * owner, repository, commit hash, and content. If no matching reference is found, a placeholder
7
- * message is written to the file.
8
- *
9
- * The module includes:
10
- * - A helper function `getLocalXTrefContent` to retrieve reference data from the JSON file.
11
- * - A main function `prepareTref` to process directories and markdown files, replacing tref references.
12
- *
13
- * This is useful for dynamically enriching markdown documentation with external reference details.
14
- *
15
- * @requires fs - Node.js file system module for reading and writing files.
16
- * @requires path - Node.js path module for handling file paths.
17
- * @requires dedent - A utility for removing indentation from multi-line strings.
18
- *
19
- * @module prepareTref
20
- */
21
-
22
- const fs = require('fs');
23
- const path = require('path');
24
- const dedent = require('dedent');
25
- const { shouldProcessFile } = require('./utils/file-filter');
26
-
27
- function getLocalXTrefContent(externalSpec, term) {
28
- const filePath = path.join('output', 'xtrefs-data.json');
29
-
30
- try {
31
- const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
32
- const xtrefs = data.xtrefs;
33
-
34
- for (const xtref of xtrefs) {
35
- if (xtref.externalSpec === externalSpec && xtref.term === term) {
36
- // Validate that required properties exist
37
- if (!xtref.content || !xtref.owner || !xtref.repo || !xtref.repoUrl) {
38
- console.warn(`Warning: Incomplete data for ${externalSpec}, ${term}`);
39
- }
40
-
41
- return {
42
- content: xtref.content || "No content available",
43
- commitHash: xtref.commitHash || "Not available",
44
- owner: xtref.owner || "Unknown",
45
- repo: xtref.repo || "Unknown",
46
- repoUrl: xtref.repoUrl || "#",
47
- avatarUrl: xtref.avatarUrl || ""
48
- };
49
- }
50
- }
51
- } catch (err) {
52
- console.error(`Error reading xtrefs-data.json: ${err}`);
53
- }
54
-
55
- return {
56
- content: `Term '${term}' not found in external specification '${externalSpec}'`,
57
- commitHash: "Not available",
58
- owner: "Unknown",
59
- repo: "Unknown",
60
- repoUrl: "#",
61
- avatarUrl: ""
62
- };
63
- }
64
-
65
- // Function to process markdown files in a directory recursively
66
- function prepareTref(directory) {
67
- // Helper function to process a directory
68
- function processDirectory(directory) {
69
- try {
70
- // Read the contents of the directory synchronously
71
- const items = fs.readdirSync(directory, { withFileTypes: true });
72
-
73
- // Loop through each item in the directory
74
- items.forEach(item => {
75
- const itemPath = path.join(directory, item.name);
76
- if (item.isDirectory()) {
77
- // If the item is a directory, call processDirectory recursively
78
- processDirectory(itemPath);
79
- } else if (item.isFile() && shouldProcessFile(item.name)) {
80
- try {
81
- // Read the file synchronously
82
- let data = fs.readFileSync(itemPath, 'utf8');
83
-
84
- // Split the content into lines
85
- let lines = data.split('\n');
86
-
87
- // Variable to store content after the span or tref line
88
- let contentAfterSpan = '';
89
- const spanMarker = '<span style="display: none;">End of included external content. Add your optional custom content below.</span>';
90
- const spanIndex = data.indexOf(spanMarker);
91
-
92
- if (spanIndex !== -1) {
93
- // If span marker exists, take content after it
94
- contentAfterSpan = data.substring(spanIndex + spanMarker.length);
95
- } else {
96
- // If span marker doesn't exist, find the tref line and keep everything after it
97
- let trefLineIndex = -1;
98
- for (let i = 0; i < lines.length; i++) {
99
- if (lines[i].startsWith('[[tref:')) {
100
- trefLineIndex = i;
101
- break;
102
- }
103
- }
104
- if (trefLineIndex !== -1 && trefLineIndex < lines.length - 1) {
105
- contentAfterSpan = lines.slice(trefLineIndex + 1).join('\n');
106
- }
107
- }
108
-
109
- for (let i = 0; i < lines.length; i++) {
110
- if (lines[i].startsWith('[[tref:')) {
111
- const tref = /\[\[tref:(.*?)\]\]/;
112
- const match = lines[i].match(tref);
113
- let currentTref = lines[i]; // Store the current tref line for error handling
114
-
115
- if (match) {
116
- try {
117
- const result = match[1].split(',').map(term => term.trim());
118
-
119
- if (result.length < 2) {
120
- throw new Error(`Invalid tref format. Expected: [[tref:spec,term]], got: ${match[0]}`);
121
- }
122
-
123
- const localXTrefContent = getLocalXTrefContent(result[0], result[1]);
124
-
125
- // Skip processing if essential data is missing
126
- if (!localXTrefContent) {
127
- console.warn(`Warning: No content found for ${result[0]}, ${result[1]}`);
128
- continue;
129
- }
130
-
131
- const defPart = /\[\[def: ([^,]+),.*?\]\]/g;
132
- if (localXTrefContent.content) {
133
- localXTrefContent.content = localXTrefContent.content.replace(defPart, '');
134
- }
135
-
136
- const readyForWrite = dedent`
137
- ${match[0]}
138
- | Property | Value |
139
- | -------- | ----- |
140
- | Owner | ${localXTrefContent.avatarUrl ? `![avatar](${localXTrefContent.avatarUrl})` : ''} ${localXTrefContent.owner} |
141
- | Repo | [${localXTrefContent.repo}](${localXTrefContent.repoUrl}) |
142
- | Commit hash | ${localXTrefContent.commitHash} |
143
-
144
- ${localXTrefContent.content}
145
- ${spanMarker}
146
-
147
- ${contentAfterSpan}
148
-
149
- `;
150
-
151
- fs.writeFileSync(itemPath, readyForWrite, 'utf8');
152
- } catch (err) {
153
- console.error(`Error processing tref: ${err}`);
154
- fs.writeFileSync(itemPath, currentTref + '\n\n' + '\n\nError processing reference: ' + err.message, 'utf8');
155
- }
156
- }
157
- }
158
- }
159
- } catch (err) {
160
- console.error(`Error processing file ${itemPath}: ${err}`);
161
- }
162
- }
163
- });
164
- } catch (err) {
165
- console.error(`❌ Error reading directory: ${err}`);
166
- }
167
- }
168
-
169
- processDirectory(directory);
170
- }
171
-
172
- module.exports = {
173
- prepareTref
174
- };