spec-up-t 1.0.91 → 1.1.0
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/assets/compiled/body.js +1 -1
- package/assets/compiled/head.css +1 -1
- package/assets/css/index.css +202 -150
- package/index.js +0 -3
- package/package.json +2 -1
- package/src/add-remove-xref-source.js +171 -0
- package/src/{get-xtrefs-data.js → collect-external-references.js} +13 -42
- package/src/collectExternalReferences/fetchTermsFromGitHubRepository.js +237 -0
- package/src/{get-xtrefs-data → collectExternalReferences}/matchTerm.js +4 -3
- package/src/collectExternalReferences/processXTrefsData.js +53 -0
- package/src/config/paths.js +1 -0
- package/src/configure.js +96 -0
- package/src/init.js +2 -8
- package/src/install-from-boilerplate/add-scripts-keys.js +48 -0
- package/src/install-from-boilerplate/boilerplate/.env.example +2 -0
- package/src/install-from-boilerplate/boilerplate/.github/workflows/fetch-and-push-xrefs.yml +42 -0
- package/src/install-from-boilerplate/boilerplate/.github/workflows/render-specs.yml +47 -0
- package/src/install-from-boilerplate/boilerplate/README.md +3 -0
- package/src/install-from-boilerplate/boilerplate/assets/test.json +5 -0
- package/src/install-from-boilerplate/boilerplate/assets/test.text +1 -0
- package/src/install-from-boilerplate/boilerplate/gitignore +10 -0
- package/src/install-from-boilerplate/boilerplate/help.txt +6 -0
- package/src/install-from-boilerplate/boilerplate/main.sh +103 -0
- package/src/install-from-boilerplate/boilerplate/spec/example-markup-in-markdown.md +384 -0
- package/src/install-from-boilerplate/boilerplate/spec/spec-body.md +3 -0
- package/src/install-from-boilerplate/boilerplate/spec/spec-head.md +7 -0
- package/src/install-from-boilerplate/boilerplate/spec/terms-and-definitions-intro.md +5 -0
- package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-1.md +13 -0
- package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-2.md +3 -0
- package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-3.md +3 -0
- package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-4.md +3 -0
- package/src/install-from-boilerplate/boilerplate/specs.json +41 -0
- package/src/install-from-boilerplate/boilerplate/static/favicon.ico +0 -0
- package/src/install-from-boilerplate/boilerplate/static/logo.svg +236 -0
- package/src/install-from-boilerplate/config-scripts-keys.js +16 -0
- package/src/install-from-boilerplate/copy-boilerplate.js +22 -0
- package/src/install-from-boilerplate/install.js +8 -0
- package/src/install-from-boilerplate/postinstall-message.js +15 -0
- package/src/prepare-tref.js +21 -4
- package/src/utils/doesUrlExist.js +18 -10
- package/src/utils/isLineWithDefinition.js +13 -0
- package/src/get-xtrefs-data/matchTerm.1.js +0 -23
- package/src/get-xtrefs-data/searchGitHubCode.1.js +0 -69
- package/src/get-xtrefs-data/searchGitHubCode.2.js +0 -77
- package/src/get-xtrefs-data/searchGitHubCode.3.js +0 -85
- package/src/get-xtrefs-data/searchGitHubCode.4.js +0 -92
- package/src/get-xtrefs-data/searchGitHubCode.5.js +0 -97
- package/src/get-xtrefs-data/searchGitHubCode.6.js +0 -101
- package/src/get-xtrefs-data/searchGitHubCode.js +0 -97
- /package/src/{get-xtrefs-data → collectExternalReferences}/checkRateLimit.js +0 -0
- /package/src/{get-xtrefs-data → collectExternalReferences}/setupFetchHeaders.js +0 -0
package/src/configure.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This script configures the Spec-Up-T Starterpack by prompting the user for input
|
|
3
|
+
* and updating the specs.json file accordingly. It performs the following tasks:
|
|
4
|
+
*
|
|
5
|
+
* 1. Resolves the path to the specs.json file in the root directory.
|
|
6
|
+
* 2. Checks if the specs.json file exists, and exits with an error if it does not.
|
|
7
|
+
* 3. Creates a readline interface to prompt the user for input.
|
|
8
|
+
* 4. Defines a set of questions to gather information from the user.
|
|
9
|
+
*
|
|
10
|
+
* @module configure
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const readline = require('readline');
|
|
16
|
+
|
|
17
|
+
// Resolve the path to specs.json in the root directory
|
|
18
|
+
const JSON_FILE_PATH = path.resolve(process.cwd(), 'specs.json');
|
|
19
|
+
|
|
20
|
+
// Key for accessing specs in the JSON file
|
|
21
|
+
const SPECS_KEY = 'specs';
|
|
22
|
+
|
|
23
|
+
// Check if the JSON file exists
|
|
24
|
+
if (!fs.existsSync(JSON_FILE_PATH)) {
|
|
25
|
+
console.error(`Error: ${JSON_FILE_PATH} does not exist.`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create the readline interface
|
|
30
|
+
const rl = readline.createInterface({
|
|
31
|
+
input: process.stdin,
|
|
32
|
+
output: process.stdout,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Questions for user input
|
|
36
|
+
const questions = [
|
|
37
|
+
{ field: 'title', prompt: 'Enter title: ', default: 'Spec-Up-T Starterpack' },
|
|
38
|
+
{ field: 'description', prompt: 'Enter description: ', default: 'Create technical specifications in markdown. Based on the original Spec-Up, extended with Terminology tooling' },
|
|
39
|
+
{ field: 'author', prompt: 'Enter author: ', default: 'Trust over IP Foundation' },
|
|
40
|
+
{ field: 'account', prompt: 'Enter account: ', default: 'trustoverip' },
|
|
41
|
+
{ field: 'repo', prompt: 'Enter repo: ', default: 'spec-up-t-starter-pack' },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
const userResponses = {};
|
|
45
|
+
|
|
46
|
+
// Function to prompt the user for inputs
|
|
47
|
+
function collectUserInputs(index = 0) {
|
|
48
|
+
if (index === questions.length) {
|
|
49
|
+
rl.close();
|
|
50
|
+
applySpecFieldsToJSON();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const { prompt, default: defaultValue } = questions[index];
|
|
55
|
+
rl.question(`${prompt} (${defaultValue}): `, (answer) => {
|
|
56
|
+
userResponses[questions[index].field] = answer || defaultValue;
|
|
57
|
+
collectUserInputs(index + 1);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Function to update JSON with user-provided spec fields
|
|
62
|
+
function applySpecFieldsToJSON() {
|
|
63
|
+
try {
|
|
64
|
+
const data = JSON.parse(fs.readFileSync(JSON_FILE_PATH, 'utf8'));
|
|
65
|
+
|
|
66
|
+
if (!data[SPECS_KEY] || !Array.isArray(data[SPECS_KEY]) || !data[SPECS_KEY][0]) {
|
|
67
|
+
console.error(`Error: Invalid JSON structure. "${SPECS_KEY}[0]" is missing.`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Ensure the "source" key exists in the JSON object
|
|
72
|
+
if (!data[SPECS_KEY][0].source) {
|
|
73
|
+
data[SPECS_KEY][0].source = {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Iterate over user responses and assign fields accordingly
|
|
77
|
+
Object.entries(userResponses).forEach(([field, value]) => {
|
|
78
|
+
if (['account', 'repo'].includes(field)) {
|
|
79
|
+
// Add these fields to the "source" key
|
|
80
|
+
data[SPECS_KEY][0].source[field] = value;
|
|
81
|
+
} else {
|
|
82
|
+
// Add all other fields to the root of the JSON object
|
|
83
|
+
data[SPECS_KEY][0][field] = value;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(data, null, 2), 'utf8');
|
|
88
|
+
console.log(`Successfully updated ${JSON_FILE_PATH}.`);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`Error: Could not update ${JSON_FILE_PATH}.`, error.message);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Start user input collection
|
|
96
|
+
collectUserInputs();
|
package/src/init.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
1
|
const fs = require('fs-extra');
|
|
3
2
|
const path = require('path');
|
|
4
|
-
const { exec } = require('child_process');
|
|
5
3
|
const outputDir = path.join(process.cwd(), 'output');
|
|
6
4
|
const initFlagPath = path.join(outputDir, 'init.flag');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const updateXTrefs = require('./get-xtrefs-data.js').updateXTrefs;
|
|
10
|
-
const { prepareTref } = require('./prepare-tref');
|
|
5
|
+
const collectExternalReferences = require('./collect-external-references.js').collectExternalReferences;
|
|
11
6
|
|
|
12
7
|
async function initialize() {
|
|
13
8
|
try {
|
|
14
9
|
// Check if the init script has already run
|
|
15
10
|
if (await fs.pathExists(initFlagPath)) {
|
|
16
|
-
console.log('Initialization has already been completed.');
|
|
17
11
|
return;
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
// Place the init script here
|
|
21
15
|
|
|
22
|
-
|
|
16
|
+
collectExternalReferences(process.env.GITHUB_API_TOKEN, false);
|
|
23
17
|
// prepareTref(path.join(config.specs[0].spec_directory, config.specs[0].spec_terms_directory));
|
|
24
18
|
|
|
25
19
|
// End of the init script
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// Function to add scripts to package.json
|
|
5
|
+
function addScriptsKeys(scriptKeys) {
|
|
6
|
+
// Path to the package.json of the project where this script is run
|
|
7
|
+
const packageJsonPath = path.resolve(__dirname, '../../../../', 'package.json');
|
|
8
|
+
// console.log('KORKOR packageJsonPath: ', packageJsonPath);
|
|
9
|
+
|
|
10
|
+
// Read the package.json file
|
|
11
|
+
fs.readFile(packageJsonPath, 'utf8', (err, data) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
console.error('Error reading package.json:', err);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// Parse the package.json content
|
|
19
|
+
const packageJson = JSON.parse(data);
|
|
20
|
+
|
|
21
|
+
// Initialize the scripts section if it doesn't exist
|
|
22
|
+
if (!packageJson.scripts) {
|
|
23
|
+
packageJson.scripts = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Add new scripts without overwriting existing ones
|
|
27
|
+
for (const [key, value] of Object.entries(scriptKeys)) {
|
|
28
|
+
if (!packageJson.scripts[key]) {
|
|
29
|
+
packageJson.scripts[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Write the updated package.json back to disk
|
|
34
|
+
fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8', (err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
console.error('Error writing package.json:', err);
|
|
37
|
+
} else {
|
|
38
|
+
console.log('Scripts added to package.json successfully!');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
} catch (parseError) {
|
|
42
|
+
console.error('Error parsing package.json:', parseError);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Export the function
|
|
48
|
+
module.exports = addScriptsKeys;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
name: fetch and push xrefs
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
# push:
|
|
6
|
+
# branches:
|
|
7
|
+
# - main
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-deploy-spec:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout 🛎️
|
|
17
|
+
uses: actions/checkout@v3
|
|
18
|
+
with:
|
|
19
|
+
persist-credentials: false
|
|
20
|
+
|
|
21
|
+
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
|
|
22
|
+
run: |
|
|
23
|
+
echo "start install"
|
|
24
|
+
npm install
|
|
25
|
+
echo "end install"
|
|
26
|
+
echo "Spec-Up-T version:"
|
|
27
|
+
npm list spec-up-t
|
|
28
|
+
echo "start fetching xrefs"
|
|
29
|
+
node -e "require('spec-up-t/src/get-xrefs-data.js').updateXrefs()"
|
|
30
|
+
rm -rf node_modules
|
|
31
|
+
|
|
32
|
+
- name: Commit and Push Changes
|
|
33
|
+
env:
|
|
34
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
35
|
+
run: |
|
|
36
|
+
git config --local user.email "action@github.com"
|
|
37
|
+
git config --local user.name "GitHub Action"
|
|
38
|
+
git add .
|
|
39
|
+
git commit -m "Update Xrefs data via Github Action" || echo "No changes to commit"
|
|
40
|
+
git push https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }} HEAD:refs/heads/main
|
|
41
|
+
|
|
42
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
name: spec-up-t render
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
# push:
|
|
6
|
+
# branches:
|
|
7
|
+
# - main
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-deploy-spec:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout 🛎️
|
|
17
|
+
uses: actions/checkout@v2
|
|
18
|
+
with:
|
|
19
|
+
persist-credentials: false
|
|
20
|
+
- name: Extract output_path from JSON
|
|
21
|
+
# TODO: .specs[0] is a hack to get the first spec. This should be fixed.
|
|
22
|
+
run: |
|
|
23
|
+
OUTPUT_PATH=$(jq -r '.specs[0].output_path' specs.json)
|
|
24
|
+
echo "OUTPUT_PATH=$OUTPUT_PATH" >> $GITHUB_ENV
|
|
25
|
+
|
|
26
|
+
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
|
|
27
|
+
run: |
|
|
28
|
+
echo "start install"
|
|
29
|
+
npm install
|
|
30
|
+
echo "end install"
|
|
31
|
+
echo "Spec-Up-T version:"
|
|
32
|
+
npm list spec-up-t
|
|
33
|
+
echo "start render"
|
|
34
|
+
node -e "require('spec-up-t')({ nowatch: true })"
|
|
35
|
+
echo "end render"
|
|
36
|
+
rm -rf node_modules
|
|
37
|
+
|
|
38
|
+
# This is a GitHub Action to deploy your static files to GitHub Pages
|
|
39
|
+
- name: Deploy
|
|
40
|
+
uses: peaceiris/actions-gh-pages@v3.7.3
|
|
41
|
+
with:
|
|
42
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
43
|
+
publish_dir: ${{ env.OUTPUT_PATH }} # Use the OUTPUT_PATH environment variable
|
|
44
|
+
allow_empty_commit: true
|
|
45
|
+
force_orphan: true
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Beam me in, Scotty!
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Function to handle the user's choice
|
|
4
|
+
function handle_choice() {
|
|
5
|
+
local options=(
|
|
6
|
+
"Add content" "do_add_content"
|
|
7
|
+
"Render specification" "do_render"
|
|
8
|
+
"Export to PDF" "do_topdf"
|
|
9
|
+
"Collect external references (cache, faster)" "collect_external_references_cache"
|
|
10
|
+
"Collect external references (no cache, slower)" "collect_external_references_no_cache"
|
|
11
|
+
"Add, remove or view xref source" "do_add_remove_xref_source"
|
|
12
|
+
"Configure" "do_configure"
|
|
13
|
+
"Open documentation website" "do_help"
|
|
14
|
+
"Freeze specification" "do_freeze"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if [[ "$choice" =~ ^[0-8]$ ]]; then
|
|
18
|
+
local index=$((choice * 2))
|
|
19
|
+
echo -e "\n\n ************************************"
|
|
20
|
+
echo " ${options[index]}"
|
|
21
|
+
echo -e " ************************************\n\n"
|
|
22
|
+
show_progress
|
|
23
|
+
${options[index + 1]}
|
|
24
|
+
else
|
|
25
|
+
clear
|
|
26
|
+
echo -e "\n\n ************************************"
|
|
27
|
+
echo " Goodbye! You chose to exit."
|
|
28
|
+
echo -e " ************************************\n\n"
|
|
29
|
+
fi
|
|
30
|
+
echo -e "\n\n\n SPEC-UP-T: Type 'npm run menu' to return to the main menu.\n"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Function to display the introduction text
|
|
34
|
+
function display_intro() {
|
|
35
|
+
clear
|
|
36
|
+
cat << EOF
|
|
37
|
+
|
|
38
|
+
,---. . . --.--
|
|
39
|
+
\`---.,---.,---.,---. | |,---. |
|
|
40
|
+
|| ||---'| ---| || |--- |
|
|
41
|
+
\`---'|---'\`---'\`---' \`---'|---' \`
|
|
42
|
+
| |
|
|
43
|
+
|
|
44
|
+
Please choose one of the following options:
|
|
45
|
+
|
|
46
|
+
[0] Add content
|
|
47
|
+
[1] Render specification
|
|
48
|
+
[2] Export to PDF
|
|
49
|
+
[3] Collect external references (cache, faster)
|
|
50
|
+
[4] Collect external references (no cache, slower)
|
|
51
|
+
[5] Add, remove or view xref source
|
|
52
|
+
[6] Configure
|
|
53
|
+
[7] Open documentation website
|
|
54
|
+
[8] Freeze specification
|
|
55
|
+
[Q] Quit
|
|
56
|
+
|
|
57
|
+
An xref is a reference to another repository.
|
|
58
|
+
|
|
59
|
+
EOF
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Function to prompt the user for input
|
|
63
|
+
function prompt_input() {
|
|
64
|
+
read -n 1 -r -p " Enter your choice: " choice
|
|
65
|
+
echo -e "\n"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function do_add_content() {
|
|
69
|
+
clear
|
|
70
|
+
echo -e "\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 ********************"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function do_render() { clear; npm run render; }
|
|
74
|
+
function do_topdf() { clear; npm run topdf; }
|
|
75
|
+
function collect_external_references_cache() { clear; npm run collectExternalReferencesCache; }
|
|
76
|
+
function collect_external_references_no_cache() { clear; npm run collectExternalReferencesNoCache; }
|
|
77
|
+
function do_add_remove_xref_source() { clear; npm run addremovexrefsource; }
|
|
78
|
+
function do_configure() { clear; npm run configure; }
|
|
79
|
+
function do_freeze() { clear; npm run freeze; }
|
|
80
|
+
|
|
81
|
+
function do_help() {
|
|
82
|
+
clear
|
|
83
|
+
echo -e "\n\n\n You will be redirected to the documentation website\n\n (https://trustoverip.github.io/spec-up-t-website/)."
|
|
84
|
+
sleep 2
|
|
85
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
86
|
+
open "https://trustoverip.github.io/spec-up-t-website/"
|
|
87
|
+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
88
|
+
xdg-open "https://trustoverip.github.io/spec-up-t-website/"
|
|
89
|
+
elif [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
|
|
90
|
+
start "https://trustoverip.github.io/spec-up-t-website/"
|
|
91
|
+
else
|
|
92
|
+
echo "Unsupported OS."
|
|
93
|
+
fi
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function show_progress() {
|
|
97
|
+
for i in {1..3}; do printf "."; sleep 0.2; done
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Main script
|
|
101
|
+
display_intro
|
|
102
|
+
prompt_input
|
|
103
|
+
handle_choice
|