spec-up-t 0.11.39 → 0.11.40

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/index.js CHANGED
@@ -16,12 +16,15 @@ module.exports = function(options = {}) {
16
16
  const { createTermRelations } = require('./src/create-term-relations.js');
17
17
  createTermRelations();
18
18
 
19
+ const { insertTermIndex } = require('./src/insert-term-index.js');
20
+ insertTermIndex();
21
+
19
22
  const gulp = require('gulp');
20
23
  const fs = require('fs-extra');
21
24
  const path = require('path');
22
25
  const findPkgDir = require('find-pkg-dir');
23
26
  const modulePath = findPkgDir(__dirname);
24
- let config = fs.readJsonSync('./specs.json');
27
+ let config = fs.readJsonSync('./output/specs-generated.json');
25
28
  let assets = fs.readJsonSync(modulePath + '/src/asset-map.json');
26
29
  let externalReferences;
27
30
  let references = [];
@@ -49,7 +52,7 @@ module.exports = function(options = {}) {
49
52
  xrefsData = '<script>' + fs.readFileSync(inputPath, 'utf8') + '</script>';
50
53
  }
51
54
  } catch (error) {
52
- console.error(error);
55
+ console.error("\n SPEC-UP-T: " + error + "\n");
53
56
  }
54
57
 
55
58
  function applyReplacers(doc) {
@@ -228,7 +231,7 @@ module.exports = function(options = {}) {
228
231
  try {
229
232
  noticeTitles = {};
230
233
  specGroups = {};
231
- console.log('Rendering: ' + spec.title);
234
+ console.log('\n SPEC-UP-T: Rendering: ' + spec.title + "\n");
232
235
  return new Promise(async (resolve, reject) => {
233
236
  Promise.all((spec.markdown_paths || ['spec.md']).map(_path => {
234
237
  return fs.readFile(spec.spec_directory + _path, 'utf8').catch(e => reject(e))
@@ -325,7 +328,7 @@ module.exports = function(options = {}) {
325
328
  });
326
329
  }
327
330
  catch(e) {
328
- console.error(e);
331
+ console.error("\n SPEC-UP-T: " + e + "\n");
329
332
  }
330
333
  }
331
334
 
@@ -397,7 +400,7 @@ module.exports = function(options = {}) {
397
400
 
398
401
  }
399
402
  catch(e) {
400
- console.error(e);
403
+ console.error("\n SPEC-UP-T: " + e + "\n");
401
404
  }
402
405
 
403
406
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "0.11.39",
3
+ "version": "0.11.40",
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/references.js CHANGED
@@ -16,7 +16,7 @@ function validateReferences(references, definitions, render) {
16
16
  }
17
17
  );
18
18
  if (unresolvedRefs.length > 0 ) {
19
- console.log('Unresolved References: ', unresolvedRefs)
19
+ console.log('\n SPEC-UP-T: Unresolved References: ', unresolvedRefs + "\n")
20
20
  }
21
21
 
22
22
  const danglingDefs = [];
@@ -27,7 +27,7 @@ function validateReferences(references, definitions, render) {
27
27
  }
28
28
  })
29
29
  if(danglingDefs.length > 0) {
30
- console.log('Dangling Definitions: ', danglingDefs)
30
+ console.log('\n SPEC-UP-T: Dangling Definitions: ', danglingDefs + "\n")
31
31
  }
32
32
  }
33
33
 
@@ -55,7 +55,7 @@ async function fetchExternalSpecs(spec){
55
55
  results = results.map((r, index) => (r.status === 200 ? { [Object.keys(spec.external_specs[index])[0]]: r.data } : null)).filter(r_1 => r_1);
56
56
  return results.map(r_2 => createNewDLWithTerms(Object.keys(r_2)[0], Object.values(r_2)[0]));
57
57
  } catch (e) {
58
- return console.log(e);
58
+ return console.log("\n SPEC-UP-T: " + e + "\n");
59
59
  }
60
60
  }
61
61
 
package/src/create-pdf.js CHANGED
@@ -38,8 +38,8 @@ const path = require('path');
38
38
  // Close the browser instance
39
39
  await browser.close();
40
40
 
41
- console.log('PDF generated successfully! Find the PDF in the same directory as the index.html file.');
41
+ console.log('\n SPEC-UP-T: PDF generated successfully! Find the PDF in the same directory as the index.html file.' + "\n");
42
42
  } catch (error) {
43
- console.error('Error generating PDF:', error);
43
+ console.error('SPEC-UP-T: Error generating PDF:', error + "\n");
44
44
  }
45
45
  })();
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Creates a term index by reading specifications from a JSON file and generating a list of file paths.
3
+ * The list of file paths is then written to a JSON file in the project root directory.
4
+ *
5
+ * Steps:
6
+ * 1. Reads the configuration from 'specs.json'.
7
+ * 2. Extracts the directories containing the specifications and terms.
8
+ * 3. Lists all file names in the specified terms directory.
9
+ * 4. Joins each file name with the terms directory path.
10
+ * 5. Creates an 'output' directory in the project root if it does not exist.
11
+ * 6. Writes the list of file paths to 'term-index.json' in the project root.
12
+ *
13
+ * @requires fs-extra - File system operations with extra methods.
14
+ * @requires path - Utilities for working with file and directory paths.
15
+ * @file src/create-term-index.js
16
+ * @author Kor Dwarshuis
17
+ * @version 1.0.0
18
+ * @since 2024-09-02
19
+ */
20
+
21
+ function createTermIndex() {
22
+ const fs = require('fs-extra');
23
+ const path = require('path');
24
+ const config = fs.readJsonSync('specs.json');
25
+ const specDirectories = config.specs.map(spec => spec.spec_directory);
26
+ const specTermDirectoryName = config.specs.map(spec => spec.spec_terms_directory);
27
+ const outputPathJSON = './term-index.json';
28
+ const files = fs.readdirSync(path.join(specDirectories[0], specTermDirectoryName[0]));
29
+
30
+ const filePaths = files.map(file => specTermDirectoryName[0] + '/' + file);
31
+
32
+ if (!fs.existsSync('output')) {
33
+ fs.mkdirSync('output');
34
+ }
35
+
36
+ fs.writeJsonSync(outputPathJSON, filePaths, { spaces: 2 });
37
+ }
38
+
39
+ module.exports = {
40
+ createTermIndex
41
+ }
@@ -7,7 +7,8 @@
7
7
 
8
8
  const fs = require('fs-extra');
9
9
  const config = fs.readJsonSync('specs.json');
10
- const specDirectories = config.specs.map(spec => spec.spec_directory + '/' + spec.spec_terms_directory);
10
+
11
+ const specTermDirectoryName = config.specs.map(spec => spec.spec_directory + '/' + spec.spec_terms_directory);
11
12
 
12
13
 
13
14
  // Create a path for the output file in the project root
@@ -35,8 +36,7 @@ function createTermRelations() {
35
36
  allDefs.defs = new Set();
36
37
 
37
38
  // Go through all directories that contain files with a term and definition
38
- console.log('All “spec_directory” found in specs.json: ', specDirectories);
39
- specDirectories.forEach(specDirectory => {
39
+ specTermDirectoryName.forEach(specDirectory => {
40
40
  // read directory
41
41
  fs.readdirSync(specDirectory).forEach(file => {
42
42
  // read file
@@ -15,7 +15,7 @@ function processMarkdownFiles(directory) {
15
15
  // Read the contents of the directory
16
16
  fs.readdir(directory, { withFileTypes: true }, (err, items) => {
17
17
  if (err) {
18
- console.error(`Error reading directory: ${err}`);
18
+ console.error(`\n SPEC-UP-T: Error reading directory: ${err}` + "\n");
19
19
  return;
20
20
  }
21
21
 
@@ -29,7 +29,7 @@ function processMarkdownFiles(directory) {
29
29
  // If the item is a markdown file, process it
30
30
  fs.readFile(itemPath, 'utf8', (err, data) => {
31
31
  if (err) {
32
- console.error(`Error reading file ${item.name}: ${err}`);
32
+ console.error(`\n SPEC-UP-T: Error reading file ${item.name}: ${err}` + "\n");
33
33
  return;
34
34
  }
35
35
 
@@ -40,9 +40,9 @@ function processMarkdownFiles(directory) {
40
40
  // Write the modified content back to the file
41
41
  fs.writeFile(itemPath, data, 'utf8', err => {
42
42
  if (err) {
43
- console.error(`Error writing file ${item.name}: ${err}`);
43
+ console.error(`\n SPEC-UP-T: Error writing file ${item.name}: ${err}` + "\n");
44
44
  } else {
45
- console.log(`Added blank line to ${item.name}`);
45
+ console.log(`\n SPEC-UP-T: Added blank line to ${item.name}` + "\n");
46
46
  }
47
47
  });
48
48
  }
@@ -51,7 +51,7 @@ function getXrefsData() {
51
51
  try {
52
52
 
53
53
  if (match.repoUrl === undefined) {
54
- console.log('match.repoUrl is undefined');
54
+ console.log('\n SPEC-UP-T: match.repoUrl is undefined' + "\n");
55
55
  return;
56
56
  }
57
57
 
@@ -68,7 +68,7 @@ function getXrefsData() {
68
68
  // Check for rate limit before proceeding
69
69
  if (response.status === 403 && response.headers.get('X-RateLimit-Remaining') === '0') {
70
70
  const resetTime = new Date(response.headers.get('X-RateLimit-Reset') * 1000);
71
- console.error(`Github API rate limit exceeded. Try again after ${resetTime}`);
71
+ console.error(`\n SPEC-UP-T: Github API rate limit exceeded. Try again after ${resetTime}` + "\n");
72
72
  return;
73
73
  }
74
74
 
@@ -77,14 +77,14 @@ function getXrefsData() {
77
77
  throw new Error(`HTTP error! status: ${response.status}`);
78
78
  }
79
79
 
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`);
80
+ console.log(`\n SPEC-UP-T: Github API request for:\n Term ${match.term},\n Name: ${match.externalSpec}\n Owner ${match.owner}\n Repo ${match.repo}\n was successful` + "\n");
81
81
 
82
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
83
83
  const data = await response.json();
84
84
 
85
85
  // Check if there are any commits
86
86
  if (data.length === 0) {
87
- console.log(`No commit hash found for the term “${match.term}”`);
87
+ console.log(`\n SPEC-UP-T: No commit hash found for the term “${match.term}”` + "\n");
88
88
 
89
89
  return;
90
90
  }
@@ -94,7 +94,7 @@ function getXrefsData() {
94
94
  // Assign the fetched commit hash to the variable commitHash
95
95
  let commitHash = commits.map(commit => commit.sha);
96
96
 
97
- console.log(`\nCommit hash found for the term “${match.term}”: `, commitHash);
97
+ console.log(`\n SPEC-UP-T: Commit hash found for the term “${match.term}”: `, commitHash + "\n");
98
98
 
99
99
 
100
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.
@@ -108,20 +108,20 @@ function getXrefsData() {
108
108
  // Check if the term is in the JSON file
109
109
  if (xref.term === match.term) {
110
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
- `)
111
+ console.log(`\n SPEC-UP-T: This external reference:\n Term: ${match.term}\n Name: ${match.externalSpec}\n Owner: ${match.owner}\n Repo: ${match.repo}\nis already referenced.
112
+ ` + "\n")
113
113
 
114
114
  // Give the commitHash from the JSON file to the commitHash variable
115
115
  commitHash = xref.commitHash;
116
116
  }
117
117
  });
118
118
  } else {
119
- console.log(`File not found at this point: ${outputPathJSON}. Don't worry, it will be created later.`);
119
+ console.log(`\n SPEC-UP-T: File not found at this point: ${outputPathJSON}. Don't worry, it will be created later.` + "\n");
120
120
  }
121
121
 
122
122
  return commitHash;
123
123
  } catch (error) {
124
- console.error(`Failed to fetch commit hash for the term “${match.term}”:`, error);
124
+ console.error(`\n SPEC-UP-T: Failed to fetch commit hash for the term “${match.term}”:`, error + "\n");
125
125
  }
126
126
  }
127
127
 
@@ -132,21 +132,20 @@ function getXrefsData() {
132
132
  }
133
133
 
134
134
  // Go through all directories that contain files with a term and definition
135
- console.log("All “spec_directory”'s found in specs.json: ", specTermsDirectories);
136
135
  specTermsDirectories.forEach(specDirectory => {
137
- console.log(`Current spec_directory: `, specDirectory);
136
+ console.log(`\n SPEC-UP-T: Current spec_directory: `, specDirectory + "\n");
138
137
  // read directory
139
138
  fs.readdirSync(specDirectory).forEach(file => {
140
139
  // read file
141
140
  if (file.endsWith('.md')) {
142
- console.log(`Markdown file referenced in spec_directory: `, file);
141
+ console.log(`\n SPEC-UP-T: Markdown file referenced in spec_directory: `, file + "\n");
143
142
  const markdown = fs.readFileSync(`${specDirectory}/${file}`, 'utf8');
144
143
  // create regex that finds “[[xref:.*]]”
145
144
  const regex = /\[\[xref:.*?\]\]/g;
146
145
  if (regex.test(markdown)) {
147
146
  const xrefs = markdown.match(regex);
148
147
  xrefs.forEach(xref => {
149
- console.log(`Xref found in ${file}: `, xref);
148
+ console.log(`\n SPEC-UP-T: Xref found in ${file}: `, xref + "\n");
150
149
  // example of xref: [xref: test-1, Aal]
151
150
  allXrefs.xrefs.add(xref);
152
151
  });
@@ -220,7 +219,7 @@ function getXrefsData() {
220
219
  // Step 6: add the owner and repo to the xref object
221
220
  allXrefs.xrefs.forEach(xref => {
222
221
  if (xref.repoUrl === undefined) {
223
- console.log('match.repoUrl is undefined');
222
+ console.log('\n SPEC-UP-T: match.repoUrl is undefined' + "\n");
224
223
  return;
225
224
  }
226
225
 
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Inserts term index into the specification.
3
+ *
4
+ * This function inserts the entries in term-index.json
5
+ * term directories, and updates the specification with the term index.
6
+ *
7
+ * @function
8
+ * @name insertTermIndex
9
+ * @returns {void}
10
+ * @file src/insert-term-index.js
11
+ * @author Kor Dwarshuis
12
+ * @version 1.0.0
13
+ * @since 2024-09-02
14
+ */
15
+
16
+ function insertTermIndex() {
17
+ const fs = require('fs-extra');
18
+ const path = require('path');
19
+ const config = fs.readJsonSync('./specs.json');
20
+ const terms = fs.readJsonSync('./term-index.json');
21
+ const outputPathJSON = path.join('output', 'specs-generated.json');
22
+ let specGenerated = config;
23
+ let markdownPaths = specGenerated.specs[0].markdown_paths;
24
+
25
+ const index = markdownPaths.indexOf('terms-and-definitions-intro.md');
26
+ if (index !== -1) {
27
+ // Insert the items of the "terms" array after the found index
28
+ markdownPaths.splice(index + 1, 0, ...terms);
29
+ }
30
+
31
+ // Save the updated specGenerated object back to the JSON file
32
+ fs.writeJsonSync(outputPathJSON, specGenerated, { spaces: 2 });
33
+
34
+ // Create directory named “output” in the project root if it does not yet exist
35
+ if (!fs.existsSync('output')) {
36
+ fs.mkdirSync('output');
37
+ }
38
+
39
+ fs.writeJsonSync(outputPathJSON, specGenerated, { spaces: 2 });
40
+ }
41
+
42
+ module.exports = {
43
+ insertTermIndex
44
+ }
@@ -20,7 +20,7 @@ function checkKeysSync(object, expectedKeys, parentKey = '') {
20
20
  }
21
21
  } else if (typeof object === 'object') {
22
22
  if (!(key in object)) {
23
- console.error(` Error: Missing key '${key}' in ${parentKey}\n We cannot guarantee that Spec-Up-T will work properly.\n Here is an example specs.json file:\n https://github.com/blockchainbird/spec-up-t-starter-pack/blob/main/spec-up-t-starterpack/specs.json`);
23
+ console.error(`\n SPEC-UP-T: Error: Missing key '${key}' in ${parentKey}\n We cannot guarantee that Spec-Up-T will work properly.\n Here is an example specs.json file:\n https://github.com/blockchainbird/spec-up-t-starter-pack/blob/main/spec-up-t-starterpack/specs.json` + "\n");
24
24
  errorFound = true;
25
25
  pauseForEnterSync(); // Pause synchronously
26
26
  }
@@ -67,7 +67,7 @@ function runJsonKeyValidatorSync() {
67
67
  };
68
68
 
69
69
  for (let [index, spec] of data.specs.entries()) {
70
- console.log(` Checking spec #${index + 1}`);
70
+ console.log(`\n SPEC-UP-T: Checking spec #${index + 1}` + "\n");
71
71
  checkKeysSync(spec, expectedKeys.specs, `specs[${index}]`);
72
72
 
73
73
  if (spec.source) {
@@ -84,7 +84,7 @@ function runJsonKeyValidatorSync() {
84
84
  }
85
85
 
86
86
  if (!errorFound) {
87
- console.log(' All keys are present. No errors found. Continue…');
87
+ console.log('\n SPEC-UP-T: All keys are present. No errors found. Continuing…' + "\n");
88
88
  }
89
89
  }
90
90