Skip to content

Commit 9aa7798

Browse files
committed
Remove magic
1 parent 8a91389 commit 9aa7798

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

.github/workflows/update-core-deps.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
15-
- name: Update MDN Data
16-
working-directory: ./inputfiles
17-
run: |
18-
curl -fL 'https://developer.mozilla.org/en-US/metadata.json' \
19-
| jq '{ data: [ .[]
20-
| select(
21-
(.mdn_url | ascii_downcase
22-
| (startswith("/en-us/docs/web/api/") or startswith("/en-us/docs/webassembly/reference/javascript_interface/")))
23-
)
24-
| { mdn_url, pageType, summary } ] }' \
25-
> mdn.json
2615

27-
- uses: actions/setup-node@v5
16+
- uses: actions/setup-node@v4
2817
with:
2918
node-version: "lts/*"
3019
cache: npm
31-
3220
# Use ncu to detect major version changes
3321
- run: npm i -g npm-check-updates
3422
- run: ncu -u @mdn* @webref*
@@ -38,6 +26,8 @@ jobs:
3826
# This prevents annoying change when contributors run `npm i` on their local machine.
3927
# Example: https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1463
4028
- run: npm i
29+
- name: Update MDN Data
30+
run: node scripts/generateMDN
4131
- id: build
4232
run: npm run generate
4333
continue-on-error: true

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"scripts": {
1515
"build": "tsc && node ./lib/build.js",
1616
"baseline-accept": "cpx \"generated\\**\" baselines\\",
17-
"lint": "eslint --max-warnings 0 src deploy/*.js && tsc -p deploy/jsconfig.json",
18-
"lint-fix": "eslint --max-warnings 0 src deploy/*.js --fix",
17+
"lint": "eslint --max-warnings 0 src deploy/*.js scripts/*.js && tsc -p deploy/jsconfig.json",
18+
"lint-fix": "eslint --max-warnings 0 src deploy/*.js scripts/* --fix",
1919
"test": "npm run build && npm run lint && node ./lib/test.js && node ./unittests/index.js",
2020
"changelog": "tsc && node ./lib/changelog.js",
2121
"ts-changelog": "node ./deploy/versionChangelog.js",

scripts/generateMDN.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// fetch and filter MDN metadata
2+
import fs from "fs";
3+
4+
const url = "https://developer.mozilla.org/en-US/metadata.json";
5+
6+
async function fetchAndFilterMDN() {
7+
try {
8+
const res = await fetch(url);
9+
if (!res.ok) throw new Error(`Fetch failed: ${res.statusText}`);
10+
11+
const data = await res.json();
12+
13+
// Filter and map the data
14+
const filtered = Object.values(data)
15+
.filter(entry => {
16+
const path = entry.mdn_url.toLowerCase();
17+
return (
18+
path.startsWith("/en-us/docs/web/api/") ||
19+
path.startsWith("/en-us/docs/webassembly/reference/javascript_interface/")
20+
);
21+
})
22+
.map(({ mdn_url, pageType, summary }) => ({
23+
mdn_url,
24+
pageType,
25+
summary
26+
}));
27+
28+
// Save to file
29+
fs.writeFileSync("./inputfiles/mdn.json", JSON.stringify({ data: filtered }, null, 2));
30+
console.log("mdn.json created!");
31+
} catch (err) {
32+
console.error("Error:", err);
33+
process.exit(1);
34+
}
35+
}
36+
37+
fetchAndFilterMDN();

0 commit comments

Comments
 (0)