spec-up-t 1.0.73 → 1.0.74
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/package.json +1 -1
- package/src/get-xrefs-data.js +6 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
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": {
|
package/src/get-xrefs-data.js
CHANGED
|
@@ -106,7 +106,7 @@ async function fetchFileContentFromCommit(GITHUB_API_TOKEN, owner, repo, commitH
|
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
function updateXrefs(GITHUB_API_TOKEN) {
|
|
109
|
+
function updateXrefs(GITHUB_API_TOKEN, skipExisting) {
|
|
110
110
|
// Function to extend xref objects with additional information, such as repository URL and directory information.
|
|
111
111
|
function extendXrefs(config, xrefs) {
|
|
112
112
|
if (config.specs[0].external_specs_repos) {
|
|
@@ -211,20 +211,19 @@ function updateXrefs(GITHUB_API_TOKEN) {
|
|
|
211
211
|
|
|
212
212
|
It checks if the xref object already has a commitHash and content.If both are present, it skips fetching the term information from GitHub. This ensures that existing commit hashes are not overwritten.
|
|
213
213
|
*/
|
|
214
|
-
async function fetchAllTermsInfoFromGithub() {
|
|
214
|
+
async function fetchAllTermsInfoFromGithub(skipExisting) {
|
|
215
215
|
for (let xref of allXrefs.xrefs) {
|
|
216
|
-
if (!xref.commitHash || !xref.content) {
|
|
216
|
+
if (!skipExisting || (!xref.commitHash || !xref.content)) {
|
|
217
217
|
const fetchedData = await fetchTermInfoFromGithub(GITHUB_API_TOKEN, xref);
|
|
218
218
|
if (fetchedData) {
|
|
219
219
|
xref.commitHash = fetchedData.commitHash;
|
|
220
220
|
xref.content = fetchedData.content;
|
|
221
221
|
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
222
|
+
} }
|
|
224
223
|
}
|
|
225
224
|
|
|
226
225
|
// Fetch all term information, then write the results to JSON and JS files.
|
|
227
|
-
fetchAllTermsInfoFromGithub().then(() => {
|
|
226
|
+
fetchAllTermsInfoFromGithub(skipExisting).then(() => {
|
|
228
227
|
const allXrefsStr = JSON.stringify(allXrefs, null, 2);
|
|
229
228
|
fs.writeFileSync(outputPathJSON, allXrefsStr, 'utf8');
|
|
230
229
|
const stringReadyForFileWrite = `const allXrefs = ${allXrefsStr};`;
|
|
@@ -238,96 +237,7 @@ function updateXrefs(GITHUB_API_TOKEN) {
|
|
|
238
237
|
});
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
// Function to remove a specific xref from the JSON file, based on term and externalSpec.
|
|
242
|
-
function removeXref(term, externalSpec) {
|
|
243
|
-
let messages = [];
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
// Read the JSON file
|
|
247
|
-
let currentXrefs = fs.readJsonSync(outputPathJSON);
|
|
248
|
-
|
|
249
|
-
// Check if the term and externalSpec exist
|
|
250
|
-
const entryExists = currentXrefs.xrefs.some(xref => xref.term === term && xref.externalSpec === externalSpec);
|
|
251
|
-
|
|
252
|
-
if (!entryExists) {
|
|
253
|
-
messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" not found.\n`);
|
|
254
|
-
return messages;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Remove the entry from the JSON file
|
|
258
|
-
currentXrefs.xrefs = currentXrefs.xrefs.filter(xref => {
|
|
259
|
-
return !(xref.term === term && xref.externalSpec === externalSpec);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Convert the JSON object back to a JSON string
|
|
263
|
-
const currentXrefsStr = JSON.stringify(currentXrefs, null, 2);
|
|
264
|
-
|
|
265
|
-
// Write the JSON code to a .json file
|
|
266
|
-
fs.writeFileSync(outputPathJSON, currentXrefsStr, 'utf8');
|
|
267
|
-
|
|
268
|
-
// Create the JS code for the assignment
|
|
269
|
-
const stringReadyForFileWrite = `const allXrefs = ${currentXrefsStr};`;
|
|
270
|
-
|
|
271
|
-
// Write the JS code to a .js file
|
|
272
|
-
fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
|
|
273
|
-
|
|
274
|
-
messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" removed.\n`);
|
|
275
|
-
|
|
276
|
-
// Run the render function to update the HTML file
|
|
277
|
-
require('../index.js')({ nowatch: true });
|
|
278
|
-
|
|
279
|
-
} catch (error) {
|
|
280
|
-
messages.push(`\n SPEC-UP-T: An error occurred - ${error.message}\n`);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// TODO: messages are not used at the moment, since they apparently are not returned to the calling script. Fix this.
|
|
284
|
-
|
|
285
|
-
return messages;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function addXref(term, externalSpec) {
|
|
289
|
-
let messages = [];
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
// Read the JSON file
|
|
293
|
-
let currentXrefs = fs.readJsonSync(outputPathJSON);
|
|
294
|
-
|
|
295
|
-
// Check if the term and externalSpec exist
|
|
296
|
-
const entryExists = currentXrefs.xrefs.some(xref => xref.term === term && xref.externalSpec === externalSpec);
|
|
297
|
-
|
|
298
|
-
if (entryExists) {
|
|
299
|
-
messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" already exists.\n`);
|
|
300
|
-
return messages;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Add the entry to the JSON file
|
|
304
|
-
currentXrefs.xrefs.push({ term, externalSpec });
|
|
305
|
-
|
|
306
|
-
// Convert the JSON object back to a JSON string
|
|
307
|
-
const currentXrefsStr = JSON.stringify(currentXrefs, null, 2);
|
|
308
|
-
|
|
309
|
-
// Write the JSON code to a .json file
|
|
310
|
-
fs.writeFileSync(outputPathJSON, currentXrefsStr, 'utf8');
|
|
311
|
-
|
|
312
|
-
// Create the JS code for the assignment
|
|
313
|
-
const stringReadyForFileWrite = `const allXrefs = ${currentXrefsStr};`;
|
|
314
|
-
|
|
315
|
-
// Write the JS code to a .js file
|
|
316
|
-
fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
|
|
317
|
-
|
|
318
|
-
messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" added.\n`);
|
|
319
|
-
|
|
320
|
-
// Run the render function to update the HTML file
|
|
321
|
-
require('../index.js')({ nowatch: true });
|
|
322
|
-
|
|
323
|
-
} catch (error) {
|
|
324
|
-
messages.push(`\n SPEC-UP-T: An error occurred - ${error.message}\n`);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
240
|
// Export the updateXrefs and removeXref functions for use in other modules.
|
|
329
241
|
module.exports = {
|
|
330
|
-
updateXrefs
|
|
331
|
-
removeXref,
|
|
332
|
-
addXref
|
|
242
|
+
updateXrefs
|
|
333
243
|
}
|