Skip to content

Commit 7ddd92d

Browse files
committed
add alias commands
1 parent 24e4797 commit 7ddd92d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/gatsby-theme-iterative/config/prismjs/get-commands.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const fs = require('fs')
2+
const vm = require('node:vm')
3+
24
require('isomorphic-fetch')
35

46
const args = process.argv.slice(2)
@@ -21,6 +23,22 @@ const getUrl = (repo, branch = 'main') => {
2123
return `https://raw.githubusercontent.com/iterative/${repo}/${branch}/content/docs/sidebar.json`
2224
}
2325

26+
const getAliasList = async (repo, branch = 'main', tool) => {
27+
try {
28+
const link = `https://raw.githubusercontent.com/iterative/${repo}/${branch}/content/linked-terms.js`
29+
const res = await fetch(link)
30+
if (res.ok) {
31+
const raw = await res.text()
32+
const data = vm.runInThisContext(raw.replace('module.exports', 'data'))
33+
return data
34+
.filter(item => item.matches.startsWith(`${tool} `))
35+
.map(item => item.matches.replace(`${tool} `, ''))
36+
} else throw new Error('Error with response')
37+
} catch (err) {
38+
return []
39+
}
40+
}
41+
2442
const writeCommandsToFile = async (commands, tool) => {
2543
const file = `${__dirname}/${tool}-commands.js`
2644

@@ -52,6 +70,12 @@ const getCommands = async tool => {
5270
commands.push(label)
5371
})
5472

73+
const alias = await getAliasList(
74+
repoList[tool].repo,
75+
repoList[tool].branch,
76+
tool
77+
)
78+
commands.push(...alias)
5579
commands.sort(sortDashedCommand)
5680

5781
writeCommandsToFile(commands, tool)

0 commit comments

Comments
 (0)