Skip to content

Commit db2f311

Browse files
committed
add workflow that checks for resource updates and remove auto updating resources
1 parent 7374f54 commit db2f311

File tree

5 files changed

+131
-108
lines changed

5 files changed

+131
-108
lines changed

Diff for: .github/workflows/check-for-resources-update.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Check for utils resources update
2+
on:
3+
schedule:
4+
- cron: 0 0 * * 0
5+
6+
jobs:
7+
check-for-resources-update:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v3
12+
- name: Install Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 18
16+
- name: Install Packages
17+
run: npm install
18+
- name: Update
19+
run: npm run update-resources
20+
- name: Check changes
21+
run: |
22+
git add --all && \
23+
git diff-index --cached HEAD --stat --exit-code

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"preversion": "npm test && git add .",
2121
"version": "env-cmd -e version npm run update && npm run lint -- --fix && git add .",
2222
"update": "node ./tools/update.js",
23+
"update-resources": "node ./tools/update-resources.js",
2324
"docs:watch": "vitepress dev docs",
2425
"predocs:build": "npm run update",
2526
"docs:build": "vitepress build docs"

Diff for: tools/update-html-resources.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const jsdom = require('jsdom')
5+
const { httpGet } = require('./lib/http')
6+
7+
main()
8+
9+
async function main() {
10+
const [bcdJson, obsoleteHtml] = await Promise.all([
11+
httpGet('https://unpkg.com/@mdn/browser-compat-data/data.json'),
12+
httpGet('https://html.spec.whatwg.org/multipage/obsolete.html')
13+
])
14+
const bcd = JSON.parse(bcdJson)
15+
16+
updateDeprecatedHTMLElements()
17+
updateHTMLElements()
18+
updateSVGElements()
19+
20+
// ------------------------------------------------------------------------------
21+
// Update deprecated-html-elements.json
22+
// ------------------------------------------------------------------------------
23+
function updateDeprecatedHTMLElements() {
24+
const DEPRECATED_HTML_ELEMENTS_PATH = require.resolve(
25+
'../lib/utils/deprecated-html-elements.json'
26+
)
27+
const elements = new Set()
28+
29+
const domDl = jsdom.JSDOM.fragment(obsoleteHtml).querySelector(
30+
'[id="non-conforming-features"] ~ dl'
31+
)
32+
for (const code of domDl.querySelectorAll('dt code')) {
33+
const name = code.textContent.trim()
34+
if (name) elements.add(name)
35+
}
36+
37+
if (elements.size === 0) {
38+
throw new Error('No deprecated HTML elements found')
39+
}
40+
41+
fs.writeFileSync(
42+
DEPRECATED_HTML_ELEMENTS_PATH,
43+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
44+
'utf8'
45+
)
46+
}
47+
48+
// ------------------------------------------------------------------------------
49+
// Update html-elements.json
50+
// ------------------------------------------------------------------------------
51+
function updateHTMLElements() {
52+
const HTML_ELEMENTS_PATH = require.resolve(
53+
'../lib/utils/html-elements.json'
54+
)
55+
const elements = new Set()
56+
const deprecatedHtmlElements = new Set(
57+
require('../lib/utils/deprecated-html-elements.json')
58+
)
59+
60+
for (const [name, element] of Object.entries(bcd.html.elements)) {
61+
if (deprecatedHtmlElements.has(name)) {
62+
continue
63+
}
64+
if (element.__compat.status.deprecated) {
65+
continue
66+
}
67+
elements.add(name)
68+
}
69+
70+
if (elements.size === 0) {
71+
throw new Error('No HTML elements found')
72+
}
73+
74+
fs.writeFileSync(
75+
HTML_ELEMENTS_PATH,
76+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
77+
'utf8'
78+
)
79+
}
80+
81+
// ------------------------------------------------------------------------------
82+
// Update svg-elements.json
83+
// ------------------------------------------------------------------------------
84+
function updateSVGElements() {
85+
const SVG_ELEMENTS_PATH = require.resolve('../lib/utils/svg-elements.json')
86+
const elements = new Set()
87+
88+
for (const [name, element] of Object.entries(bcd.svg.elements)) {
89+
if (element.__compat.status.deprecated) {
90+
continue
91+
}
92+
elements.add(name)
93+
}
94+
95+
if (elements.size === 0) {
96+
throw new Error('No SVG elements found')
97+
}
98+
99+
fs.writeFileSync(
100+
SVG_ELEMENTS_PATH,
101+
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
102+
'utf8'
103+
)
104+
}
105+
}

Diff for: tools/update-resources.js

+2-103
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,4 @@
11
'use strict'
22

3-
const fs = require('fs')
4-
const jsdom = require('jsdom')
5-
const { httpGet } = require('./lib/http')
6-
7-
main()
8-
9-
async function main() {
10-
const [bcdJson, obsoleteHtml] = await Promise.all([
11-
httpGet('https://unpkg.com/@mdn/browser-compat-data/data.json'),
12-
httpGet('https://html.spec.whatwg.org/multipage/obsolete.html')
13-
])
14-
const bcd = JSON.parse(bcdJson)
15-
16-
updateDeprecatedHTMLElements()
17-
updateHTMLElements()
18-
updateSVGElements()
19-
20-
// ------------------------------------------------------------------------------
21-
// Update deprecated-html-elements.json
22-
// ------------------------------------------------------------------------------
23-
function updateDeprecatedHTMLElements() {
24-
const DEPRECATED_HTML_ELEMENTS_PATH = require.resolve(
25-
'../lib/utils/deprecated-html-elements.json'
26-
)
27-
const elements = new Set()
28-
29-
const domDl = jsdom.JSDOM.fragment(obsoleteHtml).querySelector(
30-
'[id="non-conforming-features"] ~ dl'
31-
)
32-
for (const code of domDl.querySelectorAll('dt code')) {
33-
const name = code.textContent.trim()
34-
if (name) elements.add(name)
35-
}
36-
37-
if (elements.size === 0) {
38-
throw new Error('No deprecated HTML elements found')
39-
}
40-
41-
fs.writeFileSync(
42-
DEPRECATED_HTML_ELEMENTS_PATH,
43-
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
44-
'utf8'
45-
)
46-
}
47-
48-
// ------------------------------------------------------------------------------
49-
// Update html-elements.json
50-
// ------------------------------------------------------------------------------
51-
function updateHTMLElements() {
52-
const HTML_ELEMENTS_PATH = require.resolve(
53-
'../lib/utils/html-elements.json'
54-
)
55-
const elements = new Set()
56-
const deprecatedHtmlElements = new Set(
57-
require('../lib/utils/deprecated-html-elements.json')
58-
)
59-
60-
for (const [name, element] of Object.entries(bcd.html.elements)) {
61-
if (deprecatedHtmlElements.has(name)) {
62-
continue
63-
}
64-
if (element.__compat.status.deprecated) {
65-
continue
66-
}
67-
elements.add(name)
68-
}
69-
70-
if (elements.size === 0) {
71-
throw new Error('No HTML elements found')
72-
}
73-
74-
fs.writeFileSync(
75-
HTML_ELEMENTS_PATH,
76-
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
77-
'utf8'
78-
)
79-
}
80-
81-
// ------------------------------------------------------------------------------
82-
// Update svg-elements.json
83-
// ------------------------------------------------------------------------------
84-
function updateSVGElements() {
85-
const SVG_ELEMENTS_PATH = require.resolve('../lib/utils/svg-elements.json')
86-
const elements = new Set()
87-
88-
for (const [name, element] of Object.entries(bcd.svg.elements)) {
89-
if (element.__compat.status.deprecated) {
90-
continue
91-
}
92-
elements.add(name)
93-
}
94-
95-
if (elements.size === 0) {
96-
throw new Error('No SVG elements found')
97-
}
98-
99-
fs.writeFileSync(
100-
SVG_ELEMENTS_PATH,
101-
`${JSON.stringify([...elements].sort(), null, 2)}\n`,
102-
'utf8'
103-
)
104-
}
105-
}
3+
require('./update-vue3-export-names')
4+
require('./update-html-resources')

Diff for: tools/update.js

-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,3 @@ require('./update-lib-flat-configs')
1111
require('./update-lib-index')
1212
require('./update-docs')
1313
require('./update-docs-rules-index')
14-
15-
if (process.env.IN_VERSION_SCRIPT) {
16-
require('./update-vue3-export-names')
17-
require('./update-resources')
18-
}

0 commit comments

Comments
 (0)