Skip to content

Commit b7af48e

Browse files
committed
Rewrite the simpler scripts
The output of generateImplementedProperties.mjs is much nicer now. It was needlessly complex before.
1 parent 65c6ed6 commit b7af48e

File tree

6 files changed

+86
-162
lines changed

6 files changed

+86
-162
lines changed

lib/allProperties.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
'use strict';
2-
3-
// autogenerated - 9/7/2024
4-
5-
/*
6-
*
7-
* https://www.w3.org/Style/CSS/all-properties.en.html
8-
*/
2+
// autogenerated - 2024-09-07
3+
// https://www.w3.org/Style/CSS/all-properties.en.html
94

105
module.exports = new Set([
116
'-webkit-line-clamp',
@@ -126,7 +121,6 @@ module.exports = new Set([
126121
'caret',
127122
'caret-color',
128123
'caret-shape',
129-
'chains',
130124
'clear',
131125
'clip',
132126
'clip-path',
@@ -180,7 +174,6 @@ module.exports = new Set([
180174
'float',
181175
'flood-color',
182176
'flood-opacity',
183-
'flow',
184177
'flow-from',
185178
'flow-into',
186179
'font',

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"resolve": "^1.22.1"
5454
},
5555
"scripts": {
56-
"download": "node ./scripts/download_latest_properties.js && eslint lib/allProperties.js --fix",
56+
"download": "node ./scripts/downloadLatestProperties.mjs && eslint lib/allProperties.js --fix",
5757
"generate": "run-p generate:*",
58-
"generate:implemented_properties": "node ./scripts/generate_implemented_properties.js",
58+
"generate:implemented_properties": "node ./scripts/generateImplementedProperties.mjs",
5959
"generate:properties": "node ./scripts/generate_properties.js",
6060
"lint": "npm run generate && eslint --max-warnings 0",
6161
"lint:fix": "eslint --fix --max-warnings 0",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// The W3C CSSWG provides a JSON list of all CSS properties and their status in the standard.
2+
// See the documentation at https://www.w3.org/Style/CSS/all-properties.en.html.
3+
//
4+
// This script downloads that file and uses it to write an appropriately-filtered Set of property
5+
// names to a file.
6+
7+
import fs from 'node:fs';
8+
import path from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
const url = 'https://www.w3.org/Style/CSS/all-properties.en.json';
12+
const outputFile = resolve('../lib/allProperties.js');
13+
const unwantedStatuses = new Set(['NOTE', 'ED', 'FPWD']);
14+
15+
console.log('Downloading CSS properties...');
16+
17+
const res = await fetch(url);
18+
if (res.status !== 200) {
19+
throw new Error('Bad status code: ' + res.status);
20+
}
21+
22+
const rawCSSProperties = await res.json();
23+
24+
const propertyNames = new Set();
25+
for (const cssProp of rawCSSProperties) {
26+
// Filter out properties from too-new statuses.
27+
// Also, '--*' needs additional logic to this module, so filter it out for now.
28+
if (unwantedStatuses.has(cssProp.status) || cssProp.property === '--*') {
29+
continue;
30+
}
31+
32+
propertyNames.add(cssProp.property);
33+
}
34+
35+
const propertyNamesJSON = JSON.stringify(Array.from(propertyNames), undefined, 2);
36+
const dateToday = new Date();
37+
const dateTodayFormatted = dateToday.toISOString().split('T')[0];
38+
39+
const output = `
40+
'use strict';
41+
// autogenerated - ${dateTodayFormatted}
42+
// https://www.w3.org/Style/CSS/all-properties.en.html
43+
44+
module.exports = new Set(${propertyNamesJSON});
45+
`;
46+
47+
fs.writeFileSync(outputFile, output);
48+
49+
// TODO: remove when we can drop Node.js 18 support and use import.meta.dirname.
50+
function resolve(relativePath) {
51+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
52+
}

scripts/download_latest_properties.js

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { camelToDashed } from '../lib/parsers.js';
5+
6+
const dashedProperties = fs
7+
.readdirSync(resolve('../lib/properties'))
8+
.filter((propertyFile) => path.extname(propertyFile) === '.js')
9+
.map((propertyFile) => camelToDashed(path.basename(propertyFile, '.js')));
10+
11+
const outputFile = resolve('../lib/implementedProperties.js');
12+
13+
const propertyNamesJSON = JSON.stringify(dashedProperties, undefined, 2);
14+
const dateToday = new Date();
15+
const dateTodayFormatted = dateToday.toISOString().split('T')[0];
16+
17+
const output = `
18+
'use strict';
19+
// autogenerated - ${dateTodayFormatted}
20+
// https://www.w3.org/Style/CSS/all-properties.en.html
21+
22+
module.exports = new Set(${propertyNamesJSON});
23+
`;
24+
25+
fs.writeFileSync(outputFile, output);
26+
27+
// TODO: remove when we can drop Node.js 18 support and use import.meta.dirname.
28+
function resolve(relativePath) {
29+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
30+
}

scripts/generate_implemented_properties.js

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

0 commit comments

Comments
 (0)