spec-up-t 1.0.58 → 1.0.60

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.58",
3
+ "version": "1.0.60",
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": {
@@ -24,47 +24,54 @@ function processMarkdownFiles(directory) {
24
24
  let lines = data.split('\n');
25
25
  let modified = false;
26
26
 
27
- // Iterate through the lines
27
+ // Handle specific functionality for `[[def:` lines
28
28
  for (let i = 0; i < lines.length; i++) {
29
- // Check if the line starts with [[def:
30
29
  if (lines[i].startsWith('[[def:')) {
31
- // Check if the next line is not a blank line
30
+ // Ensure a blank line immediately follows `[[def:` lines
32
31
  if (i + 1 < lines.length && lines[i + 1].trim() !== '') {
33
- // Insert a blank line
34
- lines.splice(i + 1, 0, '');
32
+ lines.splice(i + 1, 0, ''); // Insert blank line
35
33
  modified = true;
36
34
  }
37
35
  }
38
36
  }
39
37
 
40
- // Ensure there is an empty line between paragraphs
41
- for (let i = 0; i < lines.length - 1; i++) {
42
- if (lines[i].trim() !== '' && lines[i + 1].trim() !== '') {
43
- lines.splice(i + 1, 0, '');
44
- modified = true;
45
- }
46
- }
38
+ // Ensure there is exactly one blank line between paragraphs
39
+ let newLines = [];
40
+ let previousLineWasEmpty = false;
47
41
 
48
- // Prepend `~ ` to lines that do not start with `[[def:` and are not blank lines, and do not already start with `~ `
49
42
  for (let i = 0; i < lines.length; i++) {
50
- if (!lines[i].startsWith('[[def:') && lines[i].trim() !== '' && !lines[i].startsWith('~ ')) {
51
- lines[i] = `~ ${lines[i]}`;
52
- modified = true;
43
+ const isCurrentLineEmpty = lines[i].trim() === '';
44
+
45
+ if (!isCurrentLineEmpty) {
46
+ newLines.push(lines[i]); // Add non-empty lines
47
+ previousLineWasEmpty = false;
48
+ } else if (!previousLineWasEmpty) {
49
+ newLines.push(''); // Add exactly one blank line
50
+ previousLineWasEmpty = true;
51
+ } else {
52
+ modified = true; // Skip additional blank lines
53
53
  }
54
54
  }
55
55
 
56
- // Join the lines back into a single string
57
- if (modified) {
58
- data = lines.join('\n');
56
+ // Prepend `~ ` to lines that do not start with `[[def:` and are not blank, and do not already start with `~ `
57
+ for (let i = 0; i < newLines.length; i++) {
58
+ if (!newLines[i].startsWith('[[def:') && newLines[i].trim() !== '' && !newLines[i].startsWith('~ ')) {
59
+ newLines[i] = `~ ${newLines[i]}`;
60
+ modified = true;
61
+ }
59
62
  }
60
63
 
61
64
  // Ensure there is exactly one blank line at the end of the file
62
- let trimmedData = data.trimEnd() + '\n';
63
- if (data !== trimmedData) {
64
- data = trimmedData;
65
+ if (newLines[newLines.length - 1] !== '') {
66
+ newLines.push('');
65
67
  modified = true;
66
68
  }
67
69
 
70
+ // Join the lines back into a single string
71
+ if (modified) {
72
+ data = newLines.join('\n');
73
+ }
74
+
68
75
  // Write the modified content back to the file synchronously if there were any changes
69
76
  if (modified) {
70
77
  fs.writeFileSync(itemPath, data, 'utf8');
@@ -86,4 +93,4 @@ function processMarkdownFiles(directory) {
86
93
 
87
94
  module.exports = {
88
95
  processMarkdownFiles
89
- };
96
+ };
@@ -86,15 +86,20 @@ function getXrefsData(GITHUB_API_TOKEN) {
86
86
 
87
87
  // Function to extend xref objects with additional information, such as repository URL and directory information.
88
88
  function extendXrefs(config, xrefs) {
89
+ if (config.specs[0].external_specs_repos) {
90
+ console.log("\n SPEC-UP-T: PLEASE NOTE: Your specs.json file is outdated (not your fault, we changed something). Use this one: https://github.com/trustoverip/spec-up-t-starter-pack/blob/main/spec-up-t-starterpack/specs.json or e-mail kor@dwarshuis.com for help. \n");
91
+ return;
92
+ }
93
+
89
94
  xrefs.forEach(xref => {
90
95
  config.specs.forEach(spec => {
91
- // Loop through "external_specs_repos" to find the repository URL for each xref
96
+ // Loop through "external_specs" to find the repository URL for each xref
92
97
  xref.repoUrl = null;
93
98
  xref.terms_dir = null;
94
99
  xref.owner = null;
95
100
  xref.repo = null;
96
101
 
97
- spec.external_specs_repos.forEach(repo => {
102
+ spec.external_specs.forEach(repo => {
98
103
  if (repo.external_spec === xref.externalSpec) {
99
104
  xref.repoUrl = repo.url;
100
105
  xref.terms_dir = repo.terms_dir;
@@ -61,8 +61,7 @@ function runJsonKeyValidatorSync() {
61
61
  "logo",
62
62
  "logo_link",
63
63
  "source",
64
- "external_specs",
65
- "external_specs_repos",
64
+ "external_specs"
66
65
  // "assets" // Commented out: We no longer check for 'assets' in the specs object
67
66
  ],
68
67
  source: [
@@ -70,7 +69,8 @@ function runJsonKeyValidatorSync() {
70
69
  "account",
71
70
  "repo"
72
71
  ],
73
- external_specs_repos: [
72
+ external_specs: [
73
+ "gh-page",
74
74
  "external_spec",
75
75
  "url",
76
76
  "terms_dir"
@@ -95,9 +95,9 @@ function runJsonKeyValidatorSync() {
95
95
  checkKeysSync(spec.source, expectedKeys.source, `specs[${index}].source`);
96
96
  }
97
97
 
98
- // Check for keys inside the 'external_specs_repos' array, if present
99
- if (spec.external_specs_repos) {
100
- checkKeysSync(spec.external_specs_repos, expectedKeys.external_specs_repos, `specs[${index}].external_specs_repos`);
98
+ // Check for keys inside the 'external_specs' array, if present
99
+ if (spec.external_specs) {
100
+ checkKeysSync(spec.external_specs, expectedKeys.external_specs, `specs[${index}].external_specs`);
101
101
  }
102
102
 
103
103
  // The assets check is no longer necessary and has been commented out
package/src/references.js CHANGED
@@ -35,8 +35,8 @@ function findExternalSpecByKey(config, key) {
35
35
  for (const spec of config.specs) {
36
36
  if (spec.external_specs) {
37
37
  for (const externalSpec of spec.external_specs) {
38
- if (externalSpec[key]) {
39
- return externalSpec[key];
38
+ if (externalSpec.external_spec === key) {
39
+ return externalSpec;
40
40
  }
41
41
  }
42
42
  }
@@ -44,21 +44,33 @@ function findExternalSpecByKey(config, key) {
44
44
  return null;
45
45
  }
46
46
 
47
- async function fetchExternalSpecs(spec){
47
+ async function fetchExternalSpecs(spec) {
48
48
  try {
49
49
  let results = await Promise.all(
50
50
  spec.external_specs.map(s => {
51
- const url = Object.values(s)[0];
51
+ const url = s["gh-page"]; // Access the "gh-page" URL directly
52
52
  return axios.get(url);
53
53
  })
54
54
  );
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
- return results.map(r_2 => createNewDLWithTerms(Object.keys(r_2)[0], Object.values(r_2)[0]));
55
+
56
+ results = results
57
+ .map((r, index) =>
58
+ r.status === 200
59
+ ? { [spec.external_specs[index].external_spec]: r.data }
60
+ : null
61
+ )
62
+ .filter(r => r); // Remove null values
63
+
64
+ return results.map(r =>
65
+ createNewDLWithTerms(Object.keys(r)[0], Object.values(r)[0])
66
+ );
57
67
  } catch (e) {
58
- return console.log("\n SPEC-UP-T: " + e + "\n");
68
+ console.log("\n SPEC-UP-T: " + e + "\n");
69
+ return []; // Return an empty array in case of errors
59
70
  }
60
71
  }
61
72
 
73
+
62
74
  function createNewDLWithTerms(title, html) {
63
75
  const dom = new JSDOM(html);
64
76
  const document = dom.window.document;