Skip to content

Commit 85bd847

Browse files
committed
refactor: Convert w3c download script to esm
1 parent 7c5280b commit 85bd847

File tree

4 files changed

+30
-122
lines changed

4 files changed

+30
-122
lines changed

package-lock.json

Lines changed: 0 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"bump": "npm version patch && npm publish && git push && git push --tags",
9-
"download-w3c-data": "node scripts/download-w3c-data",
9+
"download-w3c-data": "node scripts/download-w3c-data.mjs",
1010
"generate": "node scripts/generate",
1111
"lint": "eslint index.js scripts/*.js",
1212
"test": "echo \"Error: no test specified\" && exit 1"
@@ -47,7 +47,6 @@
4747
},
4848
"homepage": "https://github.com/known-css/known-css-properties#readme",
4949
"devDependencies": {
50-
"axios": "0.27.2",
5150
"eslint": "8.56.0",
5251
"globby": "13.2.2",
5352
"lodash.sortby": "4.7.0",

scripts/download-w3c-data.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/download-w3c-data.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import fs from 'fs/promises';
2+
import path from 'path';
3+
import uniq from 'lodash.uniq';
4+
5+
const outputFilepath = path.join(process.cwd(), 'source/w3c.json');
6+
const url = 'https://www.w3.org/Style/CSS/all-properties.en.json';
7+
const validStatuses = ['REC', 'CR', 'LC', 'WD', 'FPWD', 'ED'];
8+
9+
function isEntryValid ({ property, status }) {
10+
return !property.startsWith('--') && validStatuses.includes(status);
11+
}
12+
13+
async function saveData(properties) {
14+
return fs.writeFile(outputFilepath, JSON.stringify({ properties }, null, 2));
15+
}
16+
17+
async function downloadData() {
18+
const res = await fetch(url);
19+
return res.json();
20+
}
21+
22+
(async () => {
23+
const response = await downloadData();
24+
25+
const allProperties = response.filter(isEntryValid).map(({ property }) => property);
26+
const properties = uniq(allProperties);
27+
28+
await saveData(properties);
29+
})()

0 commit comments

Comments
 (0)