spec-up-t 0.11.8 → 0.11.9

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
@@ -31,24 +31,19 @@ module.exports = function(options = {}) {
31
31
  }
32
32
  ];
33
33
 
34
- getXrefsData();
35
-
36
- // Get the current working directory
34
+ // Test if xrefs-data.js exists
35
+ // Get the current working directory:
37
36
  const projectRoot = process.cwd();
38
- // Create a path for the output file in the project root
37
+ // Create a path for the output file in the project root:
39
38
  const inputPath = path.join(projectRoot, 'output/xrefs-data.js');
40
- // Read './xrefs-data.js' as a string
41
- let xrefsData;
39
+ let xrefsData = "";
40
+
42
41
  try {
43
42
  if (fs.existsSync(inputPath)) {
44
- xrefsData = fs.readFileSync(inputPath, 'utf8');
45
- xrefsData = '<script>' + xrefsData + '</script>';
46
- } else {
47
- xrefsData = "";
43
+ xrefsData = '<script>' + fs.readFileSync(inputPath, 'utf8') + '</script>';
48
44
  }
49
45
  } catch (error) {
50
46
  console.error(error);
51
- xrefsData = "";
52
47
  }
53
48
 
54
49
  function applyReplacers(doc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
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/specs.json CHANGED
@@ -3,7 +3,7 @@
3
3
  {
4
4
  "title": "Spec-Up ToIP example",
5
5
  "spec_directory": "./spec",
6
- "spec_terms_directory": "term-definitions",
6
+ "spec_terms_directory": "terms-definitions",
7
7
  "output_path": "./docs",
8
8
  "markdown_paths": [
9
9
  "title.md",
@@ -12,10 +12,10 @@
12
12
  "introduction.md",
13
13
  "referenced_glossaries.md",
14
14
  "terms_and_definitions.md",
15
- "term-definitions/term-1.md",
16
- "term-definitions/term-2.md",
17
- "term-definitions/term-3.md",
18
- "term-definitions/term-4.md"
15
+ "terms-definitions/term-1.md",
16
+ "terms-definitions/term-2.md",
17
+ "terms-definitions/term-3.md",
18
+ "terms-definitions/term-4.md"
19
19
  ],
20
20
  "logo": "../logo.svg",
21
21
  "logo_link": "https://github.com/decentralized-identity/spec-up",
@@ -1,150 +0,0 @@
1
- /**
2
- * @file This file:
3
- * This file
4
- - splits terms and definitions into separate files based on the term.
5
- - This is done by creating a file for each term.
6
- - The file name is based on the term. The content of the file is one term plus the definition of the term.
7
- - The file path is added to the specs.json file so it is included in the index.html after render.
8
- - The original glossary file is not changed, but is removed as an entry from the specs.json.
9
- - If not exists the specs.json file is copied to specs.unsplit.json (one time back-up of `specs.json`).
10
- - The `spec.json file will have multiple new entries, one entry per defined term. The file can grow large.
11
- * @author Kor Dwarshuis
12
- * @version 1.0.0
13
- * @since 2024-05-16
14
- */
15
-
16
- //TODO: specs.specs[0] should be replaced with code that loops through all specs
17
-
18
- const fs = require('fs');
19
- const path = require('path');
20
- const fixContent = require('./fix-content.js');
21
-
22
- // Get the current working directory
23
- const projectRoot = process.cwd();
24
-
25
- // if “specs.unsplit.json” does not yet exist, copy “specs.json” to “specs.unsplit.json” so we have a backup
26
- if (!fs.existsSync('specs.unsplit.json')) {
27
- fs.copyFileSync('specs.json', 'specs.unsplit.json');
28
- }
29
-
30
- // Restore original
31
- fs.copyFileSync('specs.unsplit.json', 'specs.json');
32
-
33
- // Load the original specs.json file before changes
34
- const specs = require('../specs.json');
35
-
36
- /* CONFIG */
37
- const config = {
38
- termsFileToBeSplit: 'terms_and_definitions.md', // This is the file that will be split up
39
- termFilesDir: specs.specs[0].spec_terms_directory,
40
- definitionStringHead: '[[def:' // This is the string that indicates the start of a definition and is used as a divider to split up the files
41
- };
42
- /* END CONFIG */
43
-
44
- // Path to directory with the markdown file to be split up
45
- const pathToTermsFileToBeSplit = path.join(projectRoot, "/", specs.specs[0].spec_directory, "/", config.termsFileToBeSplit)
46
-
47
- // Path to directory with the resulting files (one term per file)
48
- const pathToTermFilesDir = path.join(projectRoot, "/", specs.specs[0].spec_directory, "/", config.termFilesDir);
49
-
50
- // First testing, continue or not?
51
- // Test if a directory exists at the pathToTermFilesDir path
52
- console.log(`Only split if ${pathToTermFilesDir} directory does not exist, or has no markdown files. Otherwise, stop.`);
53
- if (!fs.existsSync(pathToTermFilesDir)) {
54
- console.log('Directory does not exist. Ok to proceed');
55
- } else {
56
- console.log('Directory exists');
57
- const files = fs.readdirSync(pathToTermFilesDir);
58
- const mdFilesCount = files.filter(file => file.endsWith('.md')).length;
59
-
60
- //test if number of files with extension “.md” is higher than zero
61
- if (mdFilesCount > 0) {
62
- console.log('There are .md files in the directory. Stopping.');
63
- return;
64
- } else {
65
- console.log('There are no .md files in the directory. Ok to proceed');
66
- }
67
- }
68
-
69
- // Array that holds markdown filenames in the desired order
70
- const arrMarkdownFileNamesAndFileOrder = specs.specs[0].markdown_paths;
71
-
72
- // Position in arrMarkdownFileNamesAndFileOrder where to insert new filenames
73
- let numMarkdownFileNamesAndOrderInsertPosition = arrMarkdownFileNamesAndFileOrder.indexOf(config.termsFileToBeSplit);
74
-
75
- /**
76
- * Inserts the given string into the specified array at the current insert position.
77
- * @param {Array} markdownFileNamesAndFileOrder - The array to insert the string into.
78
- * @param {string} termFileName - The string to be inserted.
79
- */
80
- function insertGlossaryFileNameInSpecsJSON(markdownFileNamesAndFileOrder, termFileName) {
81
- // Insert the new file name (termFileName) at the current insert position (arrMarkdownFileNamesAndOrderInsertPosition), do not remove anything (0)
82
- markdownFileNamesAndFileOrder.splice(numMarkdownFileNamesAndOrderInsertPosition, 0, termFileName);
83
-
84
- // The next file should be added one position further:
85
- numMarkdownFileNamesAndOrderInsertPosition++;
86
- }
87
-
88
- // The original filename that points to the file that holds all terms and definitions, and that is going to be split up, is removed from the array that holds the filenames in the desired order
89
- arrMarkdownFileNamesAndFileOrder.splice(numMarkdownFileNamesAndOrderInsertPosition, 1);
90
-
91
- // Variable that holds the file content, read from disk
92
- const glossaryFileContent = fs.readFileSync(pathToTermsFileToBeSplit, 'utf8');
93
-
94
- // Perform a few basic fixes on the source file
95
- fixContent.fixGlossaryFile(pathToTermsFileToBeSplit);
96
-
97
-
98
- // Remove directory with the splitted files if it exists
99
- if (fs.existsSync(pathToTermFilesDir)) {
100
- fs.rmdirSync(pathToTermFilesDir, { recursive: true });
101
- }
102
-
103
- // Create directory that is going to hold splitted files if it doesn't exist
104
- if (!fs.existsSync(pathToTermFilesDir)) {
105
- fs.mkdirSync(pathToTermFilesDir, { recursive: true });
106
- }
107
-
108
- // Find the terms by looking at the predictable string that indicates the start of a definition
109
- const termsRegex = /\[\[def: (.*?)\]\]/g;
110
-
111
- // Create array with the terms and also meta information about the terms
112
- const matches = [...glossaryFileContent.matchAll(termsRegex)];
113
-
114
- // Extract terms. We don't need the meta info, we only need the term, the second element of the match array
115
- const terms = matches.map(match => match[1]);
116
-
117
- // Create filenames from terms
118
- let fileNames = terms.map(term => {
119
- // if there are comma's take the part before the first comma
120
- let termWithoutComma = term.split(",")[0];
121
-
122
- return `${termWithoutComma.replace(/,/g, '').replace(/\//g, '-').replace(/ /g, '-').toLowerCase()}`;
123
- });
124
-
125
- // Add the filename for the glossary introduction
126
- insertGlossaryFileNameInSpecsJSON(arrMarkdownFileNamesAndFileOrder, "glossaryIntro.md");
127
-
128
- const sections = glossaryFileContent.split(config.definitionStringHead).slice(1); // slice(1) to remove the first part before the first heading
129
-
130
- sections.forEach((section, index) => {
131
- let filename = '';
132
- if (terms[index]) {
133
- filename = `${fileNames[index]}.md`;
134
-
135
- // Write separate files to disk
136
- fs.writeFileSync(
137
- // Where to write to:
138
- path.join(pathToTermFilesDir, "/", filename),
139
- // What to write:
140
- config.definitionStringHead + section
141
- );
142
-
143
- // Add file path to specs
144
- insertGlossaryFileNameInSpecsJSON(arrMarkdownFileNamesAndFileOrder, path.join(config.termFilesDir, '/', filename));
145
- }
146
- });
147
-
148
- // make string from specs for writing to file
149
- const specsString = JSON.stringify(specs);
150
- fs.writeFileSync("./specs.json", specsString);