Skip to content

Commit 37b8a4f

Browse files
authored
Merge pull request #113 from iterative/add-alias-commands
2 parents 2bb4003 + 65af21a commit 37b8a4f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

.github/workflows/update-commands.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Check
2525
run: |
2626
if [[ `git status packages/gatsby-theme-iterative/config/prismjs --porcelain` ]]; then
27-
cml pr create packages/gatsby-theme-iterative/config/prismjs --title "Update tool commands"
27+
cml pr create packages/gatsby-theme-iterative/config/prismjs --title "Update tool commands" --message "update tool commands"
2828
else
2929
echo "No changes!"
3030
fi

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)