spec-up-t 1.0.1 → 1.0.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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": {
@@ -285,37 +285,47 @@ function getXrefsData() {
285
285
 
286
286
  // Write function that removes an entry from xrefs-data.json and xrefs-data.js based on the term and externalSpec
287
287
  function removeXref(term, externalSpec) {
288
- // Read the JSON file
289
- let currentXrefs = fs.readJsonSync(outputPathJSON);
288
+ let messages = [];
290
289
 
291
- // Check if the term and externalSpec exist
292
- const entryExists = currentXrefs.xrefs.some(xref => xref.term === term && xref.externalSpec === externalSpec);
290
+ try {
291
+ // Read the JSON file
292
+ let currentXrefs = fs.readJsonSync(outputPathJSON);
293
293
 
294
- if (!entryExists) {
295
- console.log(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" not found.\n`);
296
- return;
297
- }
294
+ // Check if the term and externalSpec exist
295
+ const entryExists = currentXrefs.xrefs.some(xref => xref.term === term && xref.externalSpec === externalSpec);
298
296
 
299
- // Remove the entry from the JSON file
300
- currentXrefs.xrefs = currentXrefs.xrefs.filter(xref => {
301
- return !(xref.term === term && xref.externalSpec === externalSpec);
302
- });
297
+ if (!entryExists) {
298
+ messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" not found.\n`);
299
+ return messages;
300
+ }
303
301
 
304
- // Convert the JSON object back to a JSON string
305
- const currentXrefsStr = JSON.stringify(currentXrefs, null, 2);
302
+ // Remove the entry from the JSON file
303
+ currentXrefs.xrefs = currentXrefs.xrefs.filter(xref => {
304
+ return !(xref.term === term && xref.externalSpec === externalSpec);
305
+ });
306
306
 
307
- // Write the JSON code to a .json file
308
- fs.writeFileSync(outputPathJSON, currentXrefsStr, 'utf8');
307
+ // Convert the JSON object back to a JSON string
308
+ const currentXrefsStr = JSON.stringify(currentXrefs, null, 2);
309
309
 
310
- // Create the JS code for the assignment
311
- const stringReadyForFileWrite = `const allXrefs = ${currentXrefsStr};`;
310
+ // Write the JSON code to a .json file
311
+ fs.writeFileSync(outputPathJSON, currentXrefsStr, 'utf8');
312
312
 
313
- // Write the JS code to a .js file
314
- fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
313
+ // Create the JS code for the assignment
314
+ const stringReadyForFileWrite = `const allXrefs = ${currentXrefsStr};`;
315
315
 
316
- console.log(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" removed.\n`);
316
+ // Write the JS code to a .js file
317
+ fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
318
+
319
+ messages.push(`\n SPEC-UP-T: Entry with term "${term}" and externalSpec "${externalSpec}" removed.\n`);
320
+ } catch (error) {
321
+ messages.push(`\n SPEC-UP-T: An error occurred - ${error.message}\n`);
322
+ }
323
+
324
+ // TODO: messages are not used at the moment, since they apparently are not returned to the calling script. Fix this.
325
+ return messages;
317
326
  }
318
327
 
328
+
319
329
  module.exports = {
320
330
  getXrefsData,
321
331
  removeXref