diff --git a/lib/allProperties.js b/lib/allProperties.js index d9fffb3..6347745 100644 --- a/lib/allProperties.js +++ b/lib/allProperties.js @@ -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', @@ -126,7 +121,6 @@ module.exports = new Set([ 'caret', 'caret-color', 'caret-shape', - 'chains', 'clear', 'clip', 'clip-path', @@ -180,7 +174,6 @@ module.exports = new Set([ 'float', 'flood-color', 'flood-opacity', - 'flow', 'flow-from', 'flow-into', 'font', diff --git a/package.json b/package.json index 40b01c9..59881d2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/downloadLatestProperties.mjs b/scripts/downloadLatestProperties.mjs new file mode 100644 index 0000000..703c42c --- /dev/null +++ b/scripts/downloadLatestProperties.mjs @@ -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); +} diff --git a/scripts/download_latest_properties.js b/scripts/download_latest_properties.js deleted file mode 100644 index d63fa2b..0000000 --- a/scripts/download_latest_properties.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict'; - -/* - * W3C provides JSON list of all CSS properties and their status in the standard - * - * documentation: https://www.w3.org/Style/CSS/all-properties.en.html - * JSON url: ( https://www.w3.org/Style/CSS/all-properties.en.json ) - * - * Download that file, filter out duplicates and filter the properties based on the wanted standard level - * - * ED - Editors' Draft (not a W3C Technical Report) - * FPWD - First Public Working Draft - * WD - Working Draft - * LC - Last Call Working Draft - * CR - Candidate Recommendation - * PR - Proposed Recommendation - * REC - Recommendation - * NOTE - Working Group Note - */ - -var fs = require('fs'); -var path = require('path'); - -const { camelToDashed } = require('../lib/parsers'); - -var url = 'https://www.w3.org/Style/CSS/all-properties.en.json'; - -function toCamelCase(propName) { - return propName.replace(/-([a-z])/g, function (g) { - return g[1].toUpperCase(); - }); -} - -async function main() { - console.log('Downloading CSS properties...'); - - const res = await fetch(url); - if (res.status !== 200) { - throw new Error('Bad status code: ' + res.status); - } - - const allCSSProperties = await res.json(); - - // Filter out all properties newer than Working Draft - var workingDraftAndOlderProperties = allCSSProperties.filter(function (cssProp) { - // TODO: --* css Needs additional logic to this module, so filter it out for now - return cssProp.status !== 'ED' && cssProp.status !== 'FPWD' && cssProp.property !== '--*'; - }); - - // Remove duplicates, there can be many properties in different states of standard - // and add only property names to the list - var CSSpropertyNames = []; - workingDraftAndOlderProperties.forEach(function (cssProp) { - const camelCaseName = toCamelCase(cssProp.property); - - if (CSSpropertyNames.indexOf(camelCaseName) === -1) { - CSSpropertyNames.push(camelCaseName); - } - }); - - var out_file = fs.createWriteStream(path.resolve(__dirname, './../lib/allProperties.js'), { - encoding: 'utf-8', - }); - - var date_today = new Date(); - out_file.write( - "'use strict';\n\n// autogenerated - " + - (date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) + - '\n\n' - ); - out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n'); - out_file.write( - 'module.exports = new Set(' + - JSON.stringify(CSSpropertyNames.map(camelToDashed), null, 2) + - ');\n' - ); - - out_file.end(function (err) { - if (err) { - throw err; - } - - console.log('Generated ' + Object.keys(CSSpropertyNames).length + ' properties.'); - }); -} - -main().catch((e) => { - console.error(e.stack); - process.exit(1); -}); diff --git a/scripts/generateImplementedProperties.mjs b/scripts/generateImplementedProperties.mjs new file mode 100644 index 0000000..54a3a1d --- /dev/null +++ b/scripts/generateImplementedProperties.mjs @@ -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); +} diff --git a/scripts/generate_implemented_properties.js b/scripts/generate_implemented_properties.js deleted file mode 100644 index 2407fd9..0000000 --- a/scripts/generate_implemented_properties.js +++ /dev/null @@ -1,61 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const t = require('@babel/types'); -const generate = require('@babel/generator').default; -const camelToDashed = require('../lib/parsers').camelToDashed; - -const dashedProperties = fs - .readdirSync(path.resolve(__dirname, '../lib/properties')) - .filter((propertyFile) => propertyFile.substr(-3) === '.js') - .map((propertyFile) => camelToDashed(propertyFile.replace('.js', ''))); - -const out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/implementedProperties.js'), { - encoding: 'utf-8', -}); -var date_today = new Date(); -out_file.write( - "'use strict';\n\n// autogenerated - " + - (date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) + - '\n\n' -); -out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n'); - -const statements = []; -statements.push( - t.variableDeclaration('var', [ - t.variableDeclarator( - t.identifier('implementedProperties'), - t.newExpression(t.identifier('Set'), []) - ), - ]) -); - -dashedProperties.forEach((property) => { - statements.push( - t.expressionStatement( - t.callExpression( - t.memberExpression(t.identifier('implementedProperties'), t.identifier('add')), - [t.stringLiteral(property)] - ) - ) - ); -}); - -statements.push( - t.expressionStatement( - t.assignmentExpression( - '=', - t.memberExpression(t.identifier('module'), t.identifier('exports')), - t.identifier('implementedProperties') - ) - ) -); - -out_file.write(generate(t.program(statements)).code + '\n'); -out_file.end(function (err) { - if (err) { - throw err; - } -});