Skip to content

Commit

Permalink
Rewrite the simpler scripts
Browse files Browse the repository at this point in the history
The output of generateImplementedProperties.mjs is much nicer now. It was needlessly complex before.
  • Loading branch information
domenic committed Sep 7, 2024
1 parent 65c6ed6 commit b7af48e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 162 deletions.
11 changes: 2 additions & 9 deletions lib/allProperties.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict';

// autogenerated - 9/7/2024

/*
*
* https://www.w3.org/Style/CSS/all-properties.en.html
*/
// autogenerated - 2024-09-07
// https://www.w3.org/Style/CSS/all-properties.en.html

module.exports = new Set([
'-webkit-line-clamp',
Expand Down Expand Up @@ -126,7 +121,6 @@ module.exports = new Set([
'caret',
'caret-color',
'caret-shape',
'chains',
'clear',
'clip',
'clip-path',
Expand Down Expand Up @@ -180,7 +174,6 @@ module.exports = new Set([
'float',
'flood-color',
'flood-opacity',
'flow',
'flow-from',
'flow-into',
'font',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"resolve": "^1.22.1"
},
"scripts": {
"download": "node ./scripts/download_latest_properties.js && eslint lib/allProperties.js --fix",
"download": "node ./scripts/downloadLatestProperties.mjs && eslint lib/allProperties.js --fix",
"generate": "run-p generate:*",
"generate:implemented_properties": "node ./scripts/generate_implemented_properties.js",
"generate:implemented_properties": "node ./scripts/generateImplementedProperties.mjs",
"generate:properties": "node ./scripts/generate_properties.js",
"lint": "npm run generate && eslint --max-warnings 0",
"lint:fix": "eslint --fix --max-warnings 0",
Expand Down
52 changes: 52 additions & 0 deletions scripts/downloadLatestProperties.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// The W3C CSSWG provides a JSON list of all CSS properties and their status in the standard.
// See the documentation at https://www.w3.org/Style/CSS/all-properties.en.html.
//
// This script downloads that file and uses it to write an appropriately-filtered Set of property
// names to a file.

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const url = 'https://www.w3.org/Style/CSS/all-properties.en.json';
const outputFile = resolve('../lib/allProperties.js');
const unwantedStatuses = new Set(['NOTE', 'ED', 'FPWD']);

console.log('Downloading CSS properties...');

const res = await fetch(url);
if (res.status !== 200) {
throw new Error('Bad status code: ' + res.status);
}

const rawCSSProperties = await res.json();

const propertyNames = new Set();
for (const cssProp of rawCSSProperties) {
// Filter out properties from too-new statuses.
// Also, '--*' needs additional logic to this module, so filter it out for now.
if (unwantedStatuses.has(cssProp.status) || cssProp.property === '--*') {
continue;
}

propertyNames.add(cssProp.property);
}

const propertyNamesJSON = JSON.stringify(Array.from(propertyNames), undefined, 2);
const dateToday = new Date();
const dateTodayFormatted = dateToday.toISOString().split('T')[0];

const output = `
'use strict';
// autogenerated - ${dateTodayFormatted}
// https://www.w3.org/Style/CSS/all-properties.en.html
module.exports = new Set(${propertyNamesJSON});
`;

fs.writeFileSync(outputFile, output);

// TODO: remove when we can drop Node.js 18 support and use import.meta.dirname.
function resolve(relativePath) {
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
}
90 changes: 0 additions & 90 deletions scripts/download_latest_properties.js

This file was deleted.

30 changes: 30 additions & 0 deletions scripts/generateImplementedProperties.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { camelToDashed } from '../lib/parsers.js';

const dashedProperties = fs
.readdirSync(resolve('../lib/properties'))
.filter((propertyFile) => path.extname(propertyFile) === '.js')
.map((propertyFile) => camelToDashed(path.basename(propertyFile, '.js')));

const outputFile = resolve('../lib/implementedProperties.js');

const propertyNamesJSON = JSON.stringify(dashedProperties, undefined, 2);
const dateToday = new Date();
const dateTodayFormatted = dateToday.toISOString().split('T')[0];

const output = `
'use strict';
// autogenerated - ${dateTodayFormatted}
// https://www.w3.org/Style/CSS/all-properties.en.html
module.exports = new Set(${propertyNamesJSON});
`;

fs.writeFileSync(outputFile, output);

// TODO: remove when we can drop Node.js 18 support and use import.meta.dirname.
function resolve(relativePath) {
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
}
61 changes: 0 additions & 61 deletions scripts/generate_implemented_properties.js

This file was deleted.

0 comments on commit b7af48e

Please sign in to comment.