Skip to content

Commit 0990015

Browse files
committed
Move mdn html elements extraction to a workflow cron job.
1 parent 6e8f50d commit 0990015

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

.github/workflows/update-html.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: update-html
2+
run-name: Update dash html components attributes
3+
on:
4+
schedule:
5+
- cron: 10 0 1 * *
6+
workflow_dispatch:
7+
inputs:
8+
name:
9+
description: Name of the run
10+
required: false
11+
type: string
12+
13+
jobs:
14+
update-attributes:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
ref: dev
20+
- uses: actions/setup-node@v3
21+
- name: Extract elements
22+
working-directory: ./components/dash-html-components
23+
run: |
24+
npm ci
25+
npm run extract
26+
- name: Create Pull Request
27+
uses: peter-evans/create-pull-request@v5
28+
with:
29+
commit-message: Update Dash HTML elements & attributes.
30+
body: Automated HTML attributes update.

components/dash-html-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"scripts": {
1616
"clean": "rm -rf src/* && mkdir -p src/components",
1717
"prebuild": "cd scripts && sh generate-all.sh && cd -",
18+
"extract": "cd scripts && sh extract-all.sh",
1819
"lint": "eslint src scripts",
1920
"build:js": "webpack --mode production",
2021
"build:backends": "dash-generate-components ./src/components dash_html_components -p package-info.json && cp dash_html_components_base/** dash_html_components && dash-generate-components ./src/components dash_html_components -p package-info.json --r-prefix 'html' --r-suggests 'dash,dashCoreComponents' --jl-prefix 'html' && black dash_html_components",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
set -e
3+
4+
SCRIPT_DIR=`dirname $0`
5+
6+
node $SCRIPT_DIR/extract-attributes.js
7+
node $SCRIPT_DIR/extract-elements.js

components/dash-html-components/scripts/extract-elements.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const request = require('request');
66

77
const refUrl = 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element';
88
const dataPath = './data/elements.txt';
9-
const expectedElCount = 125;
109

1110
/**
1211
* From the MDN HTML elements reference, extract a list of elements.
@@ -69,28 +68,6 @@ request(refUrl, (error, response, html) => {
6968
}
7069
const $ = cheerio.load(html);
7170
const elements = extractElements($);
72-
if (elements.length !== expectedElCount) {
73-
try {
74-
const prevEls = fs.readFileSync(dataPath, 'utf8').split('\n');
75-
const added = elements.filter(n => prevEls.indexOf(n) === -1);
76-
const removed = prevEls.filter(n => elements.indexOf(n) === -1);
77-
78-
console.error(
79-
'Found new elements not seen before: [' + added.join(',') +
80-
'] and did not find expected elements: [' + removed.join(',') + ']'
81-
);
82-
}
83-
catch(e) {
84-
console.log('no previous elements found');
85-
console.log(e);
86-
}
87-
console.error(
88-
'Unexpected number of elements extracted from ' + refUrl +
89-
' - Found ' + elements.length + ' but expected ' + expectedElCount +
90-
' Check the output and edit expectedElCount if this is intended.'
91-
);
92-
process.exit(-1);
93-
}
9471
const out = elements.join('\n');
9572

9673
fs.writeFileSync(dataPath, out);

components/dash-html-components/scripts/generate-all.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ set -e
33

44
SCRIPT_DIR=`dirname $0`
55

6-
node $SCRIPT_DIR/extract-attributes.js
7-
node $SCRIPT_DIR/extract-elements.js
86
node $SCRIPT_DIR/generate-components.js $SCRIPT_DIR/data/elements.txt
97
node $SCRIPT_DIR/generate-index.js

0 commit comments

Comments
 (0)