spec-up-t 0.11.31 → 0.11.33

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": "0.11.31",
3
+ "version": "0.11.33",
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": {
@@ -20,6 +20,10 @@ const specDirectories = config.specs.map(spec => spec.spec_directory + '/' + spe
20
20
  const outputPathJSON = path.join('output', 'term-relations-data.json');
21
21
  const outputPathJS = path.join('output', 'term-relations-data.js');
22
22
 
23
+ // Create directory named “output” in the project root if it does not yet exist
24
+ if (!fs.existsSync('output')) {
25
+ fs.mkdirSync('output');
26
+ }
23
27
 
24
28
  // Create directory named “output” in the project root if it does not yet exist
25
29
  if (!fs.existsSync(config.specs[0].output_path)) {
@@ -32,6 +32,22 @@ function getXrefsData() {
32
32
 
33
33
  // Function to fetch the latest commit hash of the file
34
34
  async function fetchLatestCommitHash(match) {
35
+ /* Example
36
+ console.log('match: ', match); ->
37
+
38
+ match: {
39
+ externalSpec: 'test-1',
40
+ term: 'Aal',
41
+ repoUrl: 'https://github.com/blockchainbird/spec-up-xref-test-1',
42
+ terms_dir: 'spec/term-definitions',
43
+ owner: 'blockchainbird',
44
+ repo: 'spec-up-xref-test-1',
45
+ site: 'https://blockchainbird.github.io/spec-up-xref-test-1/'
46
+ }
47
+ */
48
+
49
+
50
+
35
51
  try {
36
52
 
37
53
  if (match.repoUrl === undefined) {
@@ -61,7 +77,7 @@ function getXrefsData() {
61
77
  throw new Error(`HTTP error! status: ${response.status}`);
62
78
  }
63
79
 
64
- console.log(`Github API request for the term “${match.term} was successful`);
80
+ console.log(`\nGithub API request for:\n Term ${match.term},\n Name: ${match.externalSpec}\n Owner ${match.owner}\n Repo ${match.repo}\nwas successful`);
65
81
 
66
82
  // Extract JSON data from the response, see https://blockchainbird.github.io/spec-up-t-website/docs/various-roles/developers-guide/#example-of-api-response for example response
67
83
  const data = await response.json();
@@ -73,14 +89,37 @@ function getXrefsData() {
73
89
  return;
74
90
  }
75
91
 
76
- // Process the last ten commits
77
- const commits = data.slice(0, 1); // Get only the last commit
92
+ // Get only the last commit
93
+ const commits = data.slice(0, 1);
94
+ // Assign the fetched commit hash to the variable commitHash
78
95
  const commitHash = commits.map(commit => commit.sha);
79
96
 
80
- console.log(`Commit hash found for the term “${match.term}”: `, commitHash);
81
- return commitHash;
97
+ console.log(`\nCommit hash found for the term “${match.term}”: `, commitHash);
98
+
99
+
100
+ //TODO: Check if a term is in the JSON file and not in the markdown file. If so, remove the term from the JSON file.
101
+
102
+ // Check if the file exists
103
+ if (fs.existsSync(outputPathJSON)) {
104
+ // Read the JSON file
105
+ let currentXrefs = fs.readJsonSync(outputPathJSON);
106
+ // Check if the term is in the JSON file
107
+ currentXrefs.xrefs.forEach(xref => {
108
+ // Check if the term is in the JSON file
109
+ if (xref.term === match.term) {
110
+ // If the term is in the JSON file, get the commit hash from the file and assign it to the variable commitHash. This is done to prevent the commit hash from being overwritten by the fetched commit hash. We want to keep the commit hash that was fetched at the time that the author looked it up.
111
+ console.log(`\nThis external reference:\n Term: ${match.term}\n Name: ${match.externalSpec}\n Owner: ${match.owner}\n Repo: ${match.repo}\nis already referenced.
112
+ `)
113
+
114
+ // Give the commitHash from the JSON file to the commitHash variable
115
+ commitHash = xref.commitHash;
116
+ }
117
+ });
118
+ } else {
119
+ console.error(`File not found: ${outputPathJSON}`);
120
+ }
82
121
 
83
- // return;
122
+ return commitHash;
84
123
  } catch (error) {
85
124
  console.error(`Failed to fetch commit hash for the term “${match.term}”:`, error);
86
125
  }
@@ -245,6 +284,30 @@ function getXrefsData() {
245
284
  });
246
285
  }
247
286
 
287
+ // Write function that removes an entry from xrefs-data.json and xrefs-data.js based on the term and externalSpec
288
+ function removeXref(term, externalSpec) {
289
+ // Read the JSON file
290
+ let currentXrefs = fs.readJsonSync(outputPathJSON);
291
+
292
+ // Remove the entry from the JSON file
293
+ currentXrefs.xrefs = currentXrefs.xrefs.filter(xref => {
294
+ return !(xref.term === term && xref.externalSpec === externalSpec);
295
+ });
296
+
297
+ // Convert the JSON object back to a JSON string
298
+ const currentXrefsStr = JSON.stringify(currentXrefs, null, 2);
299
+
300
+ // Write the JSON code to a .json file
301
+ fs.writeFileSync(outputPathJSON, currentXrefsStr, 'utf8');
302
+
303
+ // Create the JS code for the assignment
304
+ const stringReadyForFileWrite = `const allXrefs = ${currentXrefsStr};`;
305
+
306
+ // Write the JS code to a .js file
307
+ fs.writeFileSync(outputPathJS, stringReadyForFileWrite, 'utf8');
308
+ }
309
+
248
310
  module.exports = {
249
- getXrefsData
311
+ getXrefsData,
312
+ removeXref
250
313
  }