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.
Files changed (61) hide show
  1. package/.sonarlint/connectedMode.json +5 -0
  2. package/assets/compiled/body.js +35 -32
  3. package/assets/compiled/head.css +7 -5
  4. package/assets/compiled/head.js +3 -3
  5. package/assets/css/add-bootstrap-classes-to-images.css +34 -0
  6. package/assets/css/adjust-font-size.css +6 -11
  7. package/assets/css/backToTop.css +0 -1
  8. package/assets/css/image-full-size.css +44 -0
  9. package/assets/css/index.css +1 -2
  10. package/assets/css/pdf-styles.css +23 -27
  11. package/assets/css/repo-issues.css +0 -6
  12. package/assets/css/search.css +0 -1
  13. package/assets/css/sidebar-toc.css +13 -12
  14. package/assets/css/terms-and-definitions.css +43 -37
  15. package/assets/js/add-bootstrap-classes-to-images.js +98 -0
  16. package/assets/js/add-href-to-snapshot-link.js +2 -1
  17. package/assets/js/addAnchorsToTerms.js +0 -1
  18. package/assets/js/adjust-font-size.js +0 -9
  19. package/assets/js/create-alphabet-index.js +12 -3
  20. package/assets/js/create-term-filter.js +12 -0
  21. package/assets/js/custom-elements.js +13 -18
  22. package/assets/js/declare-markdown-it.js +1 -1
  23. package/assets/js/hide-show-utility-container.js +17 -0
  24. package/assets/js/highlightMenuItems.js +3 -3
  25. package/assets/js/image-full-size.js +76 -0
  26. package/assets/js/index.js +1 -5
  27. package/assets/js/insert-trefs.js +2 -2
  28. package/assets/js/modal.js +3 -3
  29. package/assets/js/search.js +15 -3
  30. package/assets/js/utils.js +2 -3
  31. package/index.js +7 -17
  32. package/package.json +2 -2
  33. package/src/README.md +3 -3
  34. package/src/add-remove-xref-source.js +0 -2
  35. package/src/asset-map.json +5 -0
  36. package/src/collect-external-references.js +187 -179
  37. package/src/collectExternalReferences/fetchTermsFromIndex.js +2 -1
  38. package/src/config/paths.js +2 -2
  39. package/src/create-external-specs-list.js +1 -1
  40. package/src/create-term-index.js +126 -22
  41. package/src/fix-markdown-files.js +152 -90
  42. package/src/health-check/external-specs-checker.js +173 -94
  43. package/src/health-check/output-gitignore-checker.js +327 -191
  44. package/src/health-check/specs-configuration-checker.js +288 -210
  45. package/src/health-check/term-references-checker.js +200 -123
  46. package/src/health-check/tref-term-checker.js +264 -179
  47. package/src/health-check.js +52 -36
  48. package/src/init.js +1 -4
  49. package/src/insert-term-index.js +5 -5
  50. package/src/install-from-boilerplate/add-scripts-keys.js +3 -1
  51. package/src/install-from-boilerplate/boilerplate/gitignore +2 -1
  52. package/src/install-from-boilerplate/config-system-files.js +9 -1
  53. package/src/install-from-boilerplate/copy-system-files.js +1 -1
  54. package/src/markdown-it-extensions.js +199 -106
  55. package/src/references.js +1 -2
  56. package/src/utils/doesUrlExist.js +7 -5
  57. package/src/utils/fetch.js +14 -14
  58. package/templates/template.html +1 -2
  59. package/assets/js/insert-xrefs.js +0 -370
  60. package/src/create-term-relations.js +0 -131
  61. package/src/prepare-tref.js +0 -174
@@ -26,152 +26,229 @@ function extractSpecNameFromTref(firstLine) {
26
26
  }
27
27
 
28
28
  /**
29
- * Check if all markdown files in spec terms directories have valid tref references
29
+ * Validates the existence of specs.json and returns its parsed content
30
30
  * @param {string} projectRoot - Root directory of the project
31
- * @returns {Promise<Array>} - Array of check results
31
+ * @param {Array} results - Results array to populate
32
+ * @returns {Object|null} - Parsed specs.json or null if not found
32
33
  */
33
- async function checkTermReferences(projectRoot) {
34
- const results = [];
34
+ function getSpecsConfig(projectRoot, results) {
35
+ const specsPath = path.join(projectRoot, 'specs.json');
36
+
37
+ if (!fs.existsSync(specsPath)) {
38
+ results.push({
39
+ name: 'Find specs.json file',
40
+ success: false,
41
+ details: 'specs.json file not found in project root'
42
+ });
43
+ return null;
44
+ }
35
45
 
36
46
  try {
37
- const specsPath = path.join(projectRoot, 'specs.json');
38
-
39
- // Check if specs.json exists
40
- if (!fs.existsSync(specsPath)) {
41
- return [{
42
- name: 'Find specs.json file',
43
- success: false,
44
- details: 'specs.json file not found in project root'
45
- }];
46
- }
47
-
48
- // Read specs.json
49
47
  const specsContent = fs.readFileSync(specsPath, 'utf8');
50
- const specs = JSON.parse(specsContent);
51
-
52
- // Find all external specs
53
- const externalSpecs = [];
54
- let allSpecDirectories = [];
55
-
56
- if (specs.specs && Array.isArray(specs.specs)) {
57
- // Collect all external specs
58
- specs.specs.forEach(spec => {
59
- if (spec.external_specs && Array.isArray(spec.external_specs)) {
60
- spec.external_specs.forEach(extSpec => {
61
- if (extSpec.external_spec) {
62
- externalSpecs.push(extSpec.external_spec);
63
- }
64
- });
65
- }
66
-
67
- // Collect term directories
68
- if (spec.spec_directory && spec.spec_terms_directory) {
69
- const termsDir = path.join(
70
- projectRoot,
71
- spec.spec_directory,
72
- spec.spec_terms_directory
73
- );
74
- allSpecDirectories.push(termsDir);
48
+ return JSON.parse(specsContent);
49
+ } catch (error) {
50
+ results.push({
51
+ name: 'Parse specs.json file',
52
+ success: false,
53
+ details: `Error parsing specs.json: ${error.message}`
54
+ });
55
+ return null;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Extracts external specs and term directories from specs configuration
61
+ * @param {Object} specs - Specs configuration object
62
+ * @param {string} projectRoot - Root directory of the project
63
+ * @returns {Object} - Object containing external specs and term directories
64
+ */
65
+ function extractSpecsInfo(specs, projectRoot) {
66
+ const externalSpecs = [];
67
+ const allSpecDirectories = [];
68
+
69
+ if (!specs.specs || !Array.isArray(specs.specs)) {
70
+ return { externalSpecs, allSpecDirectories };
71
+ }
72
+
73
+ specs.specs.forEach(spec => {
74
+ // Collect external specs
75
+ if (spec.external_specs && Array.isArray(spec.external_specs)) {
76
+ spec.external_specs.forEach(extSpec => {
77
+ if (extSpec.external_spec) {
78
+ externalSpecs.push(extSpec.external_spec);
75
79
  }
76
80
  });
77
81
  }
78
82
 
79
- if (externalSpecs.length === 0) {
80
- results.push({
81
- name: 'Find external specs',
82
- success: false,
83
- details: 'No external_spec entries found in specs.json'
84
- });
85
- } else {
86
- results.push({
87
- name: 'Find external specs',
88
- success: true,
89
- details: `Found ${externalSpecs.length} external specs: ${externalSpecs.join(', ')}`
90
- });
83
+ // Collect term directories
84
+ if (spec.spec_directory && spec.spec_terms_directory) {
85
+ const termsDir = path.join(
86
+ projectRoot,
87
+ spec.spec_directory,
88
+ spec.spec_terms_directory
89
+ );
90
+ allSpecDirectories.push(termsDir);
91
+ }
92
+ });
93
+
94
+ return { externalSpecs, allSpecDirectories };
95
+ }
96
+
97
+ /**
98
+ * Reports status of found external specs
99
+ * @param {Array} externalSpecs - List of external specs
100
+ * @param {Array} results - Results array to populate
101
+ */
102
+ function reportExternalSpecs(externalSpecs, results) {
103
+ if (externalSpecs.length === 0) {
104
+ results.push({
105
+ name: 'Find external specs',
106
+ success: false,
107
+ details: 'No external_spec entries found in specs.json'
108
+ });
109
+ return false;
110
+ }
111
+
112
+ results.push({
113
+ name: 'Find external specs',
114
+ success: true,
115
+ details: `Found ${externalSpecs.length} external specs: ${externalSpecs.join(', ')}`
116
+ });
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Reports status of found spec term directories
122
+ * @param {Array} allSpecDirectories - List of spec term directories
123
+ * @param {Array} results - Results array to populate
124
+ * @returns {boolean} - Whether any directories were found
125
+ */
126
+ function reportSpecDirectories(allSpecDirectories, results) {
127
+ if (allSpecDirectories.length === 0) {
128
+ results.push({
129
+ name: 'Find spec terms directories',
130
+ success: false,
131
+ details: 'No spec_directory/spec_terms_directory entries found in specs.json'
132
+ });
133
+ return false;
134
+ }
135
+
136
+ results.push({
137
+ name: 'Find spec terms directories',
138
+ success: true,
139
+ details: `Found ${allSpecDirectories.length} spec terms directories`
140
+ });
141
+ return true;
142
+ }
143
+
144
+ /**
145
+ * Gets markdown files from a terms directory
146
+ * @param {string} termsDir - Path to terms directory
147
+ * @param {Array} results - Results array to populate
148
+ * @returns {Array} - List of markdown file paths or empty array if none found
149
+ */
150
+ function getMarkdownFiles(termsDir, results) {
151
+ if (!fs.existsSync(termsDir)) {
152
+ results.push({
153
+ name: `Check terms directory: ${termsDir}`,
154
+ success: false,
155
+ details: `Terms directory does not exist: ${termsDir}`
156
+ });
157
+ return [];
158
+ }
159
+
160
+ const markdownFiles = fs.readdirSync(termsDir)
161
+ .filter(file => path.extname(file) === '.md')
162
+ .map(file => path.join(termsDir, file));
163
+
164
+ if (markdownFiles.length === 0) {
165
+ results.push({
166
+ name: `Find markdown files in <code>${termsDir}</code>`,
167
+ success: false,
168
+ details: `No markdown files found in terms directory: ${termsDir}`
169
+ });
170
+ return [];
171
+ }
172
+
173
+ results.push({
174
+ name: `Find markdown files in <code>${termsDir}</code>`,
175
+ success: true,
176
+ details: `Found ${markdownFiles.length} markdown files`
177
+ });
178
+
179
+ return markdownFiles;
180
+ }
181
+
182
+ /**
183
+ * Validates a markdown file's tref references
184
+ * @param {string} mdFile - Path to markdown file
185
+ * @param {Array} externalSpecs - List of external specs
186
+ * @param {Array} results - Results array to populate
187
+ */
188
+ function validateMarkdownFile(mdFile, externalSpecs, results) {
189
+ try {
190
+ const content = fs.readFileSync(mdFile, 'utf8');
191
+ const firstLine = content.split('\n')[0];
192
+
193
+ if (!firstLine.includes('[[tref:')) {
194
+ return; // Skip this file
91
195
  }
92
196
 
93
- if (allSpecDirectories.length === 0) {
197
+ const specName = extractSpecNameFromTref(firstLine);
198
+ if (!specName) {
94
199
  results.push({
95
- name: 'Find spec terms directories',
200
+ name: `Check tref in ${path.basename(mdFile)}`,
96
201
  success: false,
97
- details: 'No spec_directory/spec_terms_directory entries found in specs.json'
202
+ details: `Could not extract spec name from tref tag in first line: "${firstLine}"`
98
203
  });
99
- return results;
204
+ return;
100
205
  }
101
206
 
207
+ const isValid = externalSpecs.includes(specName);
102
208
  results.push({
103
- name: 'Find spec terms directories',
104
- success: true,
105
- details: `Found ${allSpecDirectories.length} spec terms directories`
209
+ name: `Check tref spec "${specName}" in <code>${path.basename(mdFile)}</code>`,
210
+ success: isValid,
211
+ details: isValid
212
+ ? `Valid external spec reference: ${specName}`
213
+ : `Invalid external spec reference: "${specName}" is not defined in external_specs`
214
+ });
215
+ } catch (error) {
216
+ results.push({
217
+ name: `Check file ${path.basename(mdFile)}`,
218
+ success: false,
219
+ details: `Error reading or processing file: ${error.message}`
106
220
  });
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Check if all markdown files in spec terms directories have valid tref references
226
+ * @param {string} projectRoot - Root directory of the project
227
+ * @returns {Promise<Array>} - Array of check results
228
+ */
229
+ async function checkTermReferences(projectRoot) {
230
+ const results = [];
231
+
232
+ try {
233
+ const specs = getSpecsConfig(projectRoot, results);
234
+ if (!specs) {
235
+ return results;
236
+ }
237
+
238
+ const { externalSpecs, allSpecDirectories } = extractSpecsInfo(specs, projectRoot);
239
+
240
+ const hasDirectories = reportSpecDirectories(allSpecDirectories, results);
241
+
242
+ if (!hasDirectories) {
243
+ return results;
244
+ }
107
245
 
108
246
  // Process all markdown files in all terms directories
109
247
  for (const termsDir of allSpecDirectories) {
110
- if (!fs.existsSync(termsDir)) {
111
- results.push({
112
- name: `Check terms directory: ${termsDir}`,
113
- success: false,
114
- details: `Terms directory does not exist: ${termsDir}`
115
- });
116
- continue;
117
- }
248
+ const markdownFiles = getMarkdownFiles(termsDir, results);
118
249
 
119
- // Find all markdown files in the terms directory
120
- const markdownFiles = fs.readdirSync(termsDir)
121
- .filter(file => path.extname(file) === '.md')
122
- .map(file => path.join(termsDir, file));
123
-
124
- if (markdownFiles.length === 0) {
125
- results.push({
126
- name: `Find markdown files in <code>${termsDir}</code>`,
127
- success: false,
128
- details: `No markdown files found in terms directory: ${termsDir}`
129
- });
130
- continue;
131
- }
132
-
133
- results.push({
134
- name: `Find markdown files in <code>${termsDir}</code>`,
135
- success: true,
136
- details: `Found ${markdownFiles.length} markdown files`
137
- });
138
-
139
- // Check each markdown file
140
250
  for (const mdFile of markdownFiles) {
141
- try {
142
- const content = fs.readFileSync(mdFile, 'utf8');
143
- const firstLine = content.split('\n')[0];
144
-
145
- if (!firstLine.includes('[[tref:')) {
146
- // Skip this file as it doesn't contain a tref tag in the first line
147
- continue;
148
- }
149
-
150
- const specName = extractSpecNameFromTref(firstLine);
151
- if (!specName) {
152
- results.push({
153
- name: `Check tref in ${path.basename(mdFile)}`,
154
- success: false,
155
- details: `Could not extract spec name from tref tag in first line: "${firstLine}"`
156
- });
157
- continue;
158
- }
159
-
160
- const isValid = externalSpecs.includes(specName);
161
- results.push({
162
- name: `Check tref spec "${specName}" in <code>${path.basename(mdFile)}</code>`,
163
- success: isValid,
164
- details: isValid
165
- ? `Valid external spec reference: ${specName}`
166
- : `Invalid external spec reference: "${specName}" is not defined in external_specs`
167
- });
168
- } catch (error) {
169
- results.push({
170
- name: `Check file ${path.basename(mdFile)}`,
171
- success: false,
172
- details: `Error reading or processing file: ${error.message}`
173
- });
174
- }
251
+ validateMarkdownFile(mdFile, externalSpecs, results);
175
252
  }
176
253
  }
177
254