diff --git a/.prettierignore b/.prettierignore index cfc7104a84c..de6d84b76fb 100644 --- a/.prettierignore +++ b/.prettierignore @@ -15,3 +15,4 @@ !/scripts/feature-init.ts !/scripts/find-troublesome-ancestors.ts !/scripts/release.ts +!/scripts/update-drafts.ts diff --git a/scripts/update-drafts.ts b/scripts/update-drafts.ts index fa5e22f5923..b3a38762df1 100644 --- a/scripts/update-drafts.ts +++ b/scripts/update-drafts.ts @@ -1,10 +1,10 @@ import { Compat } from "compute-baseline/browser-compat-data"; import fs from "node:fs/promises"; import { fileURLToPath } from "node:url"; -import {Document} from "yaml"; -import webSpecs from 'web-specs' assert { type: 'json' }; +import { Document } from "yaml"; +import webSpecs from "web-specs" assert { type: "json" }; -import { features } from '../index.js'; +import { features } from "../index.js"; function* getPages(spec): Generator { yield spec.url; @@ -19,15 +19,15 @@ function* getPages(spec): Generator { function normalize(page: string) { const url = new URL(page); // Remove any fragment. - url.hash = ''; + url.hash = ""; // Collapse HTML and ECMA-262 multipage into a single canonical page. - const multipageIndex = url.pathname.indexOf('/multipage/'); + const multipageIndex = url.pathname.indexOf("/multipage/"); if (multipageIndex !== -1) { url.pathname = url.pathname.substring(0, multipageIndex + 1); } // Strip levels from CSS specs. - if (url.hostname.startsWith('drafts.')) { - url.pathname = url.pathname.replace(/-\d+\/$/, '/'); + if (url.hostname.startsWith("drafts.")) { + url.pathname = url.pathname.replace(/-\d+\/$/, "/"); } return String(url); } @@ -36,14 +36,14 @@ async function main() { const compat = new Compat(); // Build a map of used BCD keys to feature. - const webFeatures = new Map(); + const webFeatures = new Map(); Object.values(features).map((data) => { - if(data.compat_features){ - for(const compatFeature of data.compat_features){ - webFeatures.set(compatFeature, data.name); + if (data.compat_features) { + for (const compatFeature of data.compat_features) { + webFeatures.set(compatFeature, data.name); + } } - } - }) + }); // Build a map from URLs to spec. const pageToSpec = new Map(); @@ -56,7 +56,6 @@ async function main() { // Iterate BCD and group compat features by spec. const specToCompatFeatures = new Map>(); for (const feature of compat.walk()) { - // Skip deprecated and non-standard features. if (feature.deprecated || !feature.standard_track) { continue; @@ -83,20 +82,19 @@ async function main() { } for (const [spec, compatFeatures] of specToCompatFeatures.entries()) { - // Separate out features that are already part of web-features. - const usedFeatures = new Map>(); - for (const key of compatFeatures) { - if(webFeatures.has(key)){ - const feature = webFeatures.get(key); - if(usedFeatures.has(feature)){ - usedFeatures.get(feature).add(key); - } else { - usedFeatures.set(feature, new Set([key])); - } - compatFeatures.delete(key); - } - } + const usedFeatures = new Map>(); + for (const key of compatFeatures) { + if (webFeatures.has(key)) { + const feature = webFeatures.get(key); + if (usedFeatures.has(feature)) { + usedFeatures.get(feature).add(key); + } else { + usedFeatures.set(feature, new Set([key])); + } + compatFeatures.delete(key); + } + } // Write out draft feature per spec. const id = spec.shortname; @@ -104,19 +102,18 @@ async function main() { const feature = new Document({ draft_date: new Date().toISOString().substring(0, 10), name: spec.title, - description: 'TODO', + description: "TODO", spec: spec.nightly?.url ?? spec.url, compat_features: Array.from(compatFeatures).sort(), }); - if(usedFeatures.size > 0) { + if (usedFeatures.size > 0) { let usedFeaturesComment = ` The following features in the spec are already part of web-features:\n`; - for(const [feature, keys] of usedFeatures.entries()){ + for (const [feature, keys] of usedFeatures.entries()) { usedFeaturesComment += ` - ${feature}:\n - ${Array.from(keys).join("\n - ")}\n`; } - feature.comment = usedFeaturesComment.trimEnd(); - + feature.comment = usedFeaturesComment.trimEnd(); } await fs.writeFile(`features/draft/spec/${id}.yml`, feature.toString()); }