spec-up-t 1.0.19 → 1.0.20
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 +26 -71
- package/package.json +1 -1
- package/src/create-versions-index.js +24 -29
- package/src/freeze.js +49 -13
- package/templates/template.html +78 -0
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ module.exports = function(options = {}) {
|
|
|
28
28
|
const findPkgDir = require('find-pkg-dir');
|
|
29
29
|
const modulePath = findPkgDir(__dirname);
|
|
30
30
|
let config = fs.readJsonSync('./output/specs-generated.json');
|
|
31
|
+
let template = fs.readFileSync(path.join(modulePath, 'templates/template.html'), 'utf8');
|
|
31
32
|
let assets = fs.readJsonSync(modulePath + '/src/asset-map.json');
|
|
32
33
|
let externalReferences;
|
|
33
34
|
let references = [];
|
|
@@ -235,6 +236,11 @@ module.exports = function(options = {}) {
|
|
|
235
236
|
noticeTitles = {};
|
|
236
237
|
specGroups = {};
|
|
237
238
|
console.log('\n SPEC-UP-T: Rendering: ' + spec.title + "\n");
|
|
239
|
+
|
|
240
|
+
function interpolate(template, variables) {
|
|
241
|
+
return template.replace(/\${(.*?)}/g, (match, p1) => variables[p1.trim()]);
|
|
242
|
+
}
|
|
243
|
+
|
|
238
244
|
return new Promise(async (resolve, reject) => {
|
|
239
245
|
Promise.all((spec.markdown_paths || ['spec.md']).map(_path => {
|
|
240
246
|
return fs.readFile(spec.spec_directory + _path, 'utf8').catch(e => reject(e))
|
|
@@ -247,77 +253,26 @@ module.exports = function(options = {}) {
|
|
|
247
253
|
doc = applyReplacers(doc);
|
|
248
254
|
md[spec.katex ? "enable" : "disable"](katexRules);
|
|
249
255
|
const render = md.render(doc);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
<header id="header" class="panel-header">
|
|
272
|
-
<span id="toc_toggle" panel-toggle="toc">
|
|
273
|
-
<svg icon><use xlink:href="#svg-nested-list"></use></svg>
|
|
274
|
-
</span>
|
|
275
|
-
<a id="logo" href="${spec.logo_link ? spec.logo_link : '#_'}">
|
|
276
|
-
<img src="${spec.logo}" />
|
|
277
|
-
</a>
|
|
278
|
-
<span issue-count animate panel-toggle="repo_issues">
|
|
279
|
-
<svg icon><use xlink:href="#svg-github"></use></svg>
|
|
280
|
-
</span>
|
|
281
|
-
</header>
|
|
282
|
-
|
|
283
|
-
<article id="content">
|
|
284
|
-
${render}
|
|
285
|
-
</article>
|
|
286
|
-
|
|
287
|
-
</main>
|
|
288
|
-
|
|
289
|
-
<slide-panels id="slidepanels">
|
|
290
|
-
<slide-panel id="repo_issues" options="right">
|
|
291
|
-
<header class="panel-header">
|
|
292
|
-
<span>
|
|
293
|
-
<svg icon><use xlink:href="#svg-github"></use></svg>
|
|
294
|
-
<span issue-count></span>
|
|
295
|
-
</span>
|
|
296
|
-
<span class="repo-issue-toggle" panel-toggle="repo_issues">✕</span>
|
|
297
|
-
</header>
|
|
298
|
-
<ul id="repo_issue_list"></ul>
|
|
299
|
-
</slide-panel>
|
|
300
|
-
|
|
301
|
-
<slide-panel id="toc">
|
|
302
|
-
<header class="panel-header">
|
|
303
|
-
<span>Table of Contents</span>
|
|
304
|
-
<span panel-toggle="toc">✕</span>
|
|
305
|
-
</header>
|
|
306
|
-
<div id="toc_list">
|
|
307
|
-
${toc}
|
|
308
|
-
</div>
|
|
309
|
-
<div class="snapshots"><a href="versions">Snapshots</a></div>
|
|
310
|
-
</slide-panel>
|
|
311
|
-
|
|
312
|
-
</slide-panels>
|
|
313
|
-
<div style="display: none;">
|
|
314
|
-
${externalReferences}
|
|
315
|
-
</div>
|
|
316
|
-
</body>
|
|
317
|
-
<script>window.specConfig = ${JSON.stringify(spec)}</script>
|
|
318
|
-
${assets.body}
|
|
319
|
-
</html>
|
|
320
|
-
`, function(err, data){
|
|
256
|
+
|
|
257
|
+
const templateInterpolated = interpolate(template, {
|
|
258
|
+
title: spec.title,
|
|
259
|
+
toc: toc,
|
|
260
|
+
render: render,
|
|
261
|
+
assetsHead: assets.head,
|
|
262
|
+
assetsBody: assets.body,
|
|
263
|
+
assetsSvg: assets.svg,
|
|
264
|
+
features: Object.keys(features).join(' '),
|
|
265
|
+
externalReferences: JSON.stringify(externalReferences),
|
|
266
|
+
xrefsData: xrefsData,
|
|
267
|
+
specLogo: spec.logo,
|
|
268
|
+
specLogoLink: spec.logo_link,
|
|
269
|
+
spec: JSON.stringify(spec)
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
fs.writeFile(path.join(spec.destination, 'index.html'),
|
|
273
|
+
templateInterpolated, 'utf8'
|
|
274
|
+
|
|
275
|
+
, function (err, data) {
|
|
321
276
|
if (err) {
|
|
322
277
|
reject(err);
|
|
323
278
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
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": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file create-versions-index.js
|
|
3
|
-
* @description This script reads the configuration from specs.json, checks for the existence of a versions directory, creates it if it doesn't exist, and generates an index.html file listing all
|
|
3
|
+
* @description This script reads the configuration from specs.json, checks for the existence of a versions directory, creates it if it doesn't exist, and generates an index.html file listing all version directories in the directory.
|
|
4
4
|
*
|
|
5
5
|
* @requires fs-extra - File system operations with extra methods.
|
|
6
6
|
* @requires path - Utilities for working with file and directory paths.
|
|
@@ -30,18 +30,12 @@ function createVersionsIndex() {
|
|
|
30
30
|
fs.mkdirSync(versionsDir, { recursive: true });
|
|
31
31
|
console.log('Directory created:', versionsDir);
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
// Get all directories in the destination directory
|
|
35
|
+
const dirs = fs.readdirSync(versionsDir).filter(file => fs.statSync(path.join(versionsDir, file)).isDirectory());
|
|
33
36
|
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
if (err) {
|
|
37
|
-
return console.error('Unable to scan directory:', err);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Filter to include only .html files
|
|
41
|
-
const htmlFiles = files.filter(file => file.endsWith('.html'));
|
|
42
|
-
|
|
43
|
-
// Generate HTML content
|
|
44
|
-
let htmlContent = `
|
|
37
|
+
// Generate HTML content
|
|
38
|
+
let htmlContent = `
|
|
45
39
|
<!DOCTYPE html>
|
|
46
40
|
<html lang="en">
|
|
47
41
|
<head>
|
|
@@ -65,28 +59,29 @@ function createVersionsIndex() {
|
|
|
65
59
|
<li class="list-group-item"><a href="../index.html">Current version</a></li>
|
|
66
60
|
`;
|
|
67
61
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}
|
|
62
|
+
if (dirs.length === 0) {
|
|
63
|
+
htmlContent += ` <li class="list-group-item">No versions available</li>\n`;
|
|
64
|
+
} else {
|
|
65
|
+
dirs.forEach(dir => {
|
|
66
|
+
htmlContent += ` <li class="list-group-item"><a href="${dir}/index.html">Version ${dir}</a></li>\n`;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
htmlContent += `
|
|
79
71
|
</ul>
|
|
80
72
|
</body>
|
|
81
73
|
</html>
|
|
82
74
|
`;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
console.
|
|
89
|
-
}
|
|
75
|
+
|
|
76
|
+
// Write the HTML content to the index file asynchronously
|
|
77
|
+
const indexPath = path.join(versionsDir, 'index.html');
|
|
78
|
+
fs.writeFile(indexPath, htmlContent, (err) => {
|
|
79
|
+
if (err) {
|
|
80
|
+
console.error(`\n SPEC-UP-T: Error writing index file: ${err}\n`);
|
|
81
|
+
} else {
|
|
82
|
+
console.log(`\n SPEC-UP-T: Index file created at ${indexPath}\n`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
90
85
|
}
|
|
91
86
|
|
|
92
87
|
// Export the function
|
package/src/freeze.js
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file freeze.js
|
|
3
|
+
* @description This script reads the output path from a specs.json file, finds the highest versioned directory in the destination path, and copies the index.html file to a new versioned directory with an incremented version number.
|
|
4
|
+
*
|
|
5
|
+
* @requires fs-extra - Module for file system operations with additional features.
|
|
6
|
+
* @requires path - Module for handling and transforming file paths.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Assuming specs.json contains:
|
|
10
|
+
* // {
|
|
11
|
+
* // "specs": [
|
|
12
|
+
* // {
|
|
13
|
+
* // "output_path": "path/to/output"
|
|
14
|
+
* // }
|
|
15
|
+
* // ]
|
|
16
|
+
* // }
|
|
17
|
+
*
|
|
18
|
+
* // And the directory structure is:
|
|
19
|
+
* // path/to/output/versions/v1/index.html
|
|
20
|
+
* // path/to/output/versions/v2/index.html
|
|
21
|
+
*
|
|
22
|
+
* // Running this script will create:
|
|
23
|
+
* // path/to/output/versions/v3/index.html
|
|
24
|
+
*
|
|
25
|
+
* @version 1.0.0
|
|
26
|
+
* @license MIT
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const fs = require('fs-extra'); // Import the fs-extra module for file system operations
|
|
30
|
+
const path = require('path'); // Import the path module for handling file paths
|
|
3
31
|
|
|
4
32
|
// Read and parse the specs.json file
|
|
5
33
|
const config = fs.readJsonSync('specs.json');
|
|
@@ -18,21 +46,21 @@ if (!fs.existsSync(destDir)) {
|
|
|
18
46
|
fs.mkdirSync(destDir, { recursive: true });
|
|
19
47
|
}
|
|
20
48
|
|
|
21
|
-
// Get all
|
|
22
|
-
const
|
|
49
|
+
// Get all directories in the destination directory
|
|
50
|
+
const dirs = fs.readdirSync(destDir).filter(file => fs.statSync(path.join(destDir, file)).isDirectory());
|
|
23
51
|
|
|
24
52
|
// Initialize the highest version number to 0
|
|
25
53
|
let highestVersion = 0;
|
|
26
54
|
|
|
27
|
-
// Define the pattern to match versioned
|
|
28
|
-
const versionPattern = /^
|
|
55
|
+
// Define the pattern to match versioned directories
|
|
56
|
+
const versionPattern = /^v(\d+)$/;
|
|
29
57
|
|
|
30
|
-
// Iterate over each
|
|
31
|
-
|
|
32
|
-
// Check if the
|
|
33
|
-
const match =
|
|
58
|
+
// Iterate over each directory in the destination directory
|
|
59
|
+
dirs.forEach(dir => {
|
|
60
|
+
// Check if the directory matches the version pattern
|
|
61
|
+
const match = dir.match(versionPattern);
|
|
34
62
|
if (match) {
|
|
35
|
-
// Extract the version number from the
|
|
63
|
+
// Extract the version number from the directory name
|
|
36
64
|
const version = parseInt(match[1], 10);
|
|
37
65
|
// Update the highest version number if the current version is higher
|
|
38
66
|
if (version > highestVersion) {
|
|
@@ -44,8 +72,16 @@ files.forEach(file => {
|
|
|
44
72
|
// Calculate the new version number
|
|
45
73
|
const newVersion = highestVersion + 1;
|
|
46
74
|
|
|
47
|
-
// Define the
|
|
48
|
-
const
|
|
75
|
+
// Define the new version directory path
|
|
76
|
+
const newVersionDir = path.join(destDir, `v${newVersion}`);
|
|
77
|
+
|
|
78
|
+
// Ensure the new version directory exists, create it if it doesn't
|
|
79
|
+
if (!fs.existsSync(newVersionDir)) {
|
|
80
|
+
fs.mkdirSync(newVersionDir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Define the destination file path within the new version directory
|
|
84
|
+
const destFile = path.join(newVersionDir, 'index.html');
|
|
49
85
|
|
|
50
86
|
// Copy the source file to the destination file
|
|
51
87
|
fs.copyFileSync(sourceFile, destFile);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
8
|
+
|
|
9
|
+
<title>${title}</title>
|
|
10
|
+
|
|
11
|
+
<link href="https://fonts.googleapis.com/css2?family=Heebo:wght@300;400&display=swap" rel="stylesheet">
|
|
12
|
+
|
|
13
|
+
${assetsHead}
|
|
14
|
+
${xrefsData}
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body features="${features}">
|
|
18
|
+
|
|
19
|
+
${assetsSvg}
|
|
20
|
+
|
|
21
|
+
<main>
|
|
22
|
+
|
|
23
|
+
<header id="header" class="panel-header">
|
|
24
|
+
<span id="toc_toggle" panel-toggle="toc">
|
|
25
|
+
<svg icon>
|
|
26
|
+
<use xlink:href="#svg-nested-list"></use>
|
|
27
|
+
</svg>
|
|
28
|
+
</span>
|
|
29
|
+
<a id="logo" href="${spec.LogoLink ? specLogoLink : '#_'}">
|
|
30
|
+
<img src="${specLogo}" />
|
|
31
|
+
</a>
|
|
32
|
+
<span issue-count animate panel-toggle="repo_issues">
|
|
33
|
+
<svg icon>
|
|
34
|
+
<use xlink:href="#svg-github"></use>
|
|
35
|
+
</svg>
|
|
36
|
+
</span>
|
|
37
|
+
</header>
|
|
38
|
+
|
|
39
|
+
<article id="content">
|
|
40
|
+
${render}
|
|
41
|
+
</article>
|
|
42
|
+
|
|
43
|
+
</main>
|
|
44
|
+
|
|
45
|
+
<slide-panels id="slidepanels">
|
|
46
|
+
<slide-panel id="repo_issues" options="right">
|
|
47
|
+
<header class="panel-header">
|
|
48
|
+
<span>
|
|
49
|
+
<svg icon>
|
|
50
|
+
<use xlink:href="#svg-github"></use>
|
|
51
|
+
</svg>
|
|
52
|
+
<span issue-count></span>
|
|
53
|
+
</span>
|
|
54
|
+
<span class="repo-issue-toggle" panel-toggle="repo_issues">✕</span>
|
|
55
|
+
</header>
|
|
56
|
+
<ul id="repo_issue_list"></ul>
|
|
57
|
+
</slide-panel>
|
|
58
|
+
|
|
59
|
+
<slide-panel id="toc">
|
|
60
|
+
<header class="panel-header">
|
|
61
|
+
<span>Table of Contents</span>
|
|
62
|
+
<span panel-toggle="toc">✕</span>
|
|
63
|
+
</header>
|
|
64
|
+
<div id="toc_list">
|
|
65
|
+
${toc}
|
|
66
|
+
</div>
|
|
67
|
+
<div class="snapshots"><a href="versions">Snapshots</a></div>
|
|
68
|
+
</slide-panel>
|
|
69
|
+
|
|
70
|
+
</slide-panels>
|
|
71
|
+
<div style="display: none;">
|
|
72
|
+
${externalReferences}
|
|
73
|
+
</div>
|
|
74
|
+
</body>
|
|
75
|
+
<script>window.specConfig = ${ spec }</script>
|
|
76
|
+
${assetsBody}
|
|
77
|
+
|
|
78
|
+
</html>
|