Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | #!/usr/bin/env node
/**
* Interactive Spec-Up-T menu. Works on Windows, macOS, and Linux (Node.js only).
*/
const { spawnSync } = require('node:child_process');
const readlineSync = require('readline-sync');
const DOCS_URL = 'https://trustoverip.github.io/spec-up-t-website/';
const OPTIONS = [
{ label: 'Add content', action: doAddContent },
{ label: 'Render specification', action: () => runNpm('render') },
{ label: 'Export to PDF', action: () => runNpm('topdf') },
{ label: 'Export to DOCX', action: () => runNpm('todocx') },
{ label: 'Collect external references', action: () => runNpm('collectExternalReferences') },
{ label: 'Add, remove or view xref source', action: () => runNpm('addremovexrefsource') },
{ label: 'Configure', action: () => runNpm('configure') },
{ label: 'Run health check', action: () => runNpm('healthCheck') },
{ label: 'Open documentation website', action: doHelp },
{ label: 'Freeze specification', action: () => runNpm('freeze') },
];
function sleep(ms) {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
}
function runNpm(script) {
console.clear();
spawnSync('npm', ['run', script], { stdio: 'inherit', shell: true });
}
function showProgress() {
for (let i = 0; i < 3; i++) {
process.stdout.write('.');
sleep(200);
}
console.log('');
}
function openDocsUrl() {
if (process.platform === 'win32') {
spawnSync('cmd', ['/c', 'start', '', DOCS_URL], { stdio: 'ignore' });
} else if (process.platform === 'darwin') {
spawnSync('open', [DOCS_URL], { stdio: 'ignore' });
} else {
spawnSync('xdg-open', [DOCS_URL], { stdio: 'ignore' });
}
}
function doAddContent() {
console.clear();
console.log(
'\n\n\n ********************\n\n\n' +
' You can start adding your content to the markdown files in the "spec" directory.\n\n' +
' You can do this by editing local files in an editor or by going to your repository on GitHub.\n\n' +
' More info: https://trustoverip.github.io/spec-up-t-website/docs/various-roles/content-authors-guide/introduction\n\n\n' +
' ********************'
);
}
function doHelp() {
console.clear();
console.log(
`\n\n\n You will be redirected to the documentation website\n\n (${DOCS_URL}).`
);
sleep(2000);
openDocsUrl();
}
function displayIntro() {
console.clear();
console.log(`
,---. . . --.--
\`---.,---.,---.,---. | |,---. |
|| ||---'| ---| || |--- |
\`---'|---'\`---'\`---' \`---'|---' \`
| |
Please choose one of the following options:
[0] Add content
[1] Render specification
[2] Export to PDF
[3] Export to DOCX
[4] Collect external references
[5] Add, remove or view xref source
[6] Configure
[7] Run health check
[8] Open documentation website
[9] Freeze specification
[Q] Quit
An xref is a reference to another repository.
`);
}
function goodbye() {
console.clear();
console.log(`
************************************
Goodbye! You chose to exit.
************************************
`);
}
function remindMenu() {
console.log(`\n\n\nℹ️ Type 'npm run menu' to return to the main menu.\n`);
}
function handleChoice(choice) {
const index = Number(choice);
if (Number.isInteger(index) && index >= 0 && index < OPTIONS.length) {
const option = OPTIONS[index];
console.log(`\n\n ************************************`);
console.log(` ${option.label}`);
console.log(` ************************************\n\n`);
showProgress();
option.action();
} else {
goodbye();
}
remindMenu();
}
function main(args = process.argv.slice(2)) {
const arg = args[0];
if (arg !== undefined && /^[0-9]$/.test(arg)) {
handleChoice(arg);
return;
}
displayIntro();
const choice = readlineSync.keyIn(' Enter your choice: ', {
limit: '$<0-9>qQ',
limitMessage: '',
});
console.log('\n');
if (/^[Qq]$/.test(choice)) {
goodbye();
remindMenu();
return;
}
handleChoice(choice);
}
if (require.main === module) {
main();
}
module.exports = main;
|