spec-up-t 1.1.14 → 1.1.15
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 +83 -59
- package/package.json +2 -2
- package/src/collect-external-references.js +2 -2
- package/src/init.js +0 -1
package/index.js
CHANGED
|
@@ -252,77 +252,91 @@ module.exports = async function (options = {}) {
|
|
|
252
252
|
return template.replace(/\${(.*?)}/g, (match, p1) => variables[p1.trim()]);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
255
|
+
const docs = await Promise.all(
|
|
256
|
+
(spec.markdown_paths || ['spec.md']).map(_path =>
|
|
257
|
+
fs.readFile(spec.spec_directory + _path, 'utf8')
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const features = (({ source, logo }) => ({ source, logo }))(spec);
|
|
262
|
+
if (spec.external_specs && !externalReferences) {
|
|
263
|
+
externalReferences = await fetchExternalSpecs(spec);
|
|
264
|
+
}
|
|
263
265
|
|
|
264
266
|
// Find the index of the terms-and-definitions-intro.md file
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
const termsIndex = (spec.markdown_paths || ['spec.md']).indexOf('terms-and-definitions-intro.md');
|
|
268
|
+
if (termsIndex !== -1) {
|
|
267
269
|
// Append the HTML string to the content of terms-and-definitions-intro.md. This string is used to create a div that is used to insert an alphabet index, and a div that is used as the starting point of the terminology index. The newlines are essential for the correct rendering of the markdown.
|
|
268
|
-
|
|
269
|
-
|
|
270
|
+
docs[termsIndex] += '\n\n<div id="terminology-section-utility-container"></div>\n\n<div id="terminology-section-start-h7vc6omi2hr2880"></div>\n\n<hr>\n\n';
|
|
271
|
+
}
|
|
270
272
|
|
|
271
|
-
|
|
273
|
+
let doc = docs.join("\n");
|
|
272
274
|
|
|
273
275
|
// `doc` is markdown
|
|
274
|
-
|
|
276
|
+
doc = applyReplacers(doc);
|
|
275
277
|
|
|
276
|
-
|
|
278
|
+
md[spec.katex ? "enable" : "disable"](katexRules);
|
|
277
279
|
|
|
278
280
|
// `render` is the rendered HTML
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
fs.writeFile(path.join(spec.destination, 'index.html'),
|
|
300
|
-
templateInterpolated, 'utf8'
|
|
301
|
-
|
|
302
|
-
, function (err, data) {
|
|
303
|
-
if (err) {
|
|
304
|
-
reject(err);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
resolve();
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
validateReferences(references, definitions, render);
|
|
311
|
-
references = [];
|
|
312
|
-
definitions = [];
|
|
313
|
-
});
|
|
281
|
+
const render = md.render(doc);
|
|
282
|
+
|
|
283
|
+
const templateInterpolated = interpolate(template, {
|
|
284
|
+
title: spec.title,
|
|
285
|
+
description: spec.description,
|
|
286
|
+
author: spec.author,
|
|
287
|
+
toc: toc,
|
|
288
|
+
render: render,
|
|
289
|
+
assetsHead: assets.head,
|
|
290
|
+
assetsBody: assets.body,
|
|
291
|
+
assetsSvg: assets.svg,
|
|
292
|
+
features: Object.keys(features).join(' '),
|
|
293
|
+
externalReferences: JSON.stringify(externalReferences),
|
|
294
|
+
xtrefsData: xtrefsData,
|
|
295
|
+
specLogo: spec.logo,
|
|
296
|
+
specFavicon: spec.favicon,
|
|
297
|
+
specLogoLink: spec.logo_link,
|
|
298
|
+
spec: JSON.stringify(spec)
|
|
314
299
|
});
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
console.
|
|
300
|
+
|
|
301
|
+
const outputPath = path.join(spec.destination, 'index.html');
|
|
302
|
+
console.log('ℹ️ Attempting to write to:', outputPath);
|
|
303
|
+
|
|
304
|
+
// Use promisified version instead of callback
|
|
305
|
+
await fs.promises.writeFile(outputPath, templateInterpolated, 'utf8');
|
|
306
|
+
console.log(`✅ Successfully wrote ${outputPath}`);
|
|
307
|
+
|
|
308
|
+
validateReferences(references, definitions, render);
|
|
309
|
+
references = [];
|
|
310
|
+
definitions = [];
|
|
311
|
+
} catch (e) {
|
|
312
|
+
console.error("❌ Render error: " + e.message);
|
|
313
|
+
throw e;
|
|
318
314
|
}
|
|
319
315
|
}
|
|
320
316
|
|
|
321
317
|
config.specs.forEach(spec => {
|
|
322
318
|
spec.spec_directory = normalizePath(spec.spec_directory);
|
|
323
319
|
spec.destination = normalizePath(spec.output_path || spec.spec_directory);
|
|
320
|
+
|
|
321
|
+
if (!fs.existsSync(spec.destination)) {
|
|
322
|
+
try {
|
|
323
|
+
fs.mkdirSync(spec.destination, { recursive: true });
|
|
324
|
+
console.log(`✅ Created directory: ${spec.destination}`);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error(`❌ Failed to create directory ${spec.destination}: ${error.message}`);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
console.log(`ℹ️ Directory already exists: ${spec.destination}`);
|
|
331
|
+
}
|
|
324
332
|
|
|
325
|
-
|
|
333
|
+
try {
|
|
334
|
+
fs.ensureDirSync(spec.destination);
|
|
335
|
+
console.log(`✅ Ensured directory is ready: ${spec.destination}`);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
console.error(`❌ Failed to ensure directory ${spec.destination}: ${error.message}`);
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
326
340
|
|
|
327
341
|
let assetTags = {
|
|
328
342
|
svg: fs.readFileSync(modulePath + '/assets/icons.svg', 'utf8') || ''
|
|
@@ -371,17 +385,27 @@ module.exports = async function (options = {}) {
|
|
|
371
385
|
fs.copySync(path.join(katexDist, 'fonts'), path.join(spec.destination, 'fonts'));
|
|
372
386
|
}
|
|
373
387
|
|
|
388
|
+
// Run render and wait for it
|
|
389
|
+
render(spec, assetTags)
|
|
390
|
+
.then(() => {
|
|
391
|
+
console.log('ℹ️ Render completed for:', spec.destination);
|
|
392
|
+
if (options.nowatch) {
|
|
393
|
+
console.log('ℹ️ Exiting with nowatch');
|
|
394
|
+
process.exit(0);
|
|
395
|
+
}
|
|
396
|
+
})
|
|
397
|
+
.catch((e) => {
|
|
398
|
+
console.error('❌ Render failed:', e.message);
|
|
399
|
+
process.exit(1);
|
|
400
|
+
});
|
|
401
|
+
|
|
374
402
|
if (!options.nowatch) {
|
|
375
403
|
gulp.watch(
|
|
376
404
|
[spec.spec_directory + '**/*', '!' + path.join(spec.destination, 'index.html')],
|
|
377
405
|
render.bind(null, spec, assetTags)
|
|
378
|
-
)
|
|
406
|
+
);
|
|
379
407
|
}
|
|
380
408
|
|
|
381
|
-
render(spec, assetTags).then(() => {
|
|
382
|
-
if (options.nowatch) process.exit(0)
|
|
383
|
-
}).catch(() => process.exit(1));
|
|
384
|
-
|
|
385
409
|
});
|
|
386
410
|
} catch (error) {
|
|
387
411
|
console.error(`Error during initialization or module execution: ${error.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
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": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"diff": "^7.0.0",
|
|
31
31
|
"dotenv": "^16.4.7",
|
|
32
32
|
"find-pkg-dir": "^2.0.0",
|
|
33
|
-
"fs-extra": "^11.
|
|
33
|
+
"fs-extra": "^11.3.0",
|
|
34
34
|
"gulp": "4.0.2",
|
|
35
35
|
"gulp-clean-css": "4.3.0",
|
|
36
36
|
"gulp-concat": "2.6.1",
|
|
@@ -17,7 +17,7 @@ function collectExternalReferences(options = {}) {
|
|
|
17
17
|
const readlineSync = require('readline-sync');
|
|
18
18
|
const config = fs.readJsonSync('specs.json');
|
|
19
19
|
const externalSpecsRepos = config.specs[0].external_specs;
|
|
20
|
-
const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN;
|
|
20
|
+
const GITHUB_API_TOKEN = options.pat || process.env.GITHUB_API_TOKEN;
|
|
21
21
|
|
|
22
22
|
const explanationPAT =
|
|
23
23
|
`❌ No GitHub Personal Access Token (PAT) was found.
|
|
@@ -119,7 +119,7 @@ function collectExternalReferences(options = {}) {
|
|
|
119
119
|
// Function to extend xtref objects with additional information, such as repository URL and directory information.
|
|
120
120
|
function extendXTrefs(config, xtrefs) {
|
|
121
121
|
if (config.specs[0].external_specs_repos) {
|
|
122
|
-
console.log("ℹ️ PLEASE NOTE: Your specs.json file is outdated (not your fault, we changed something). Use this one: https://github.com/trustoverip/spec-up-t
|
|
122
|
+
console.log("ℹ️ PLEASE NOTE: Your specs.json file is outdated (not your fault, we changed something). Use this one: https://github.com/trustoverip/spec-up-t/blob/master/src/install-from-boilerplate/boilerplate/specs.json");
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
|
package/src/init.js
CHANGED
|
@@ -13,7 +13,6 @@ async function initialize() {
|
|
|
13
13
|
|
|
14
14
|
// Place the init script here
|
|
15
15
|
|
|
16
|
-
collectExternalReferences(process.env.GITHUB_API_TOKEN, false);
|
|
17
16
|
// prepareTref(path.join(config.specs[0].spec_directory, config.specs[0].spec_terms_directory));
|
|
18
17
|
|
|
19
18
|
// End of the init script
|