Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
!/scripts/feature-init.ts
!/scripts/find-troublesome-ancestors.ts
!/scripts/release.ts
!/scripts/update-drafts.ts
61 changes: 29 additions & 32 deletions scripts/update-drafts.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
yield spec.url;
Expand All @@ -19,15 +19,15 @@ function* getPages(spec): Generator<string> {
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);
}
Expand All @@ -36,14 +36,14 @@ async function main() {
const compat = new Compat();

// Build a map of used BCD keys to feature.
const webFeatures = new Map<string,string>();
const webFeatures = new Map<string, string>();
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<string, object>();
Expand All @@ -56,7 +56,6 @@ async function main() {
// Iterate BCD and group compat features by spec.
const specToCompatFeatures = new Map<object, Set<string>>();
for (const feature of compat.walk()) {

// Skip deprecated and non-standard features.
if (feature.deprecated || !feature.standard_track) {
continue;
Expand All @@ -83,40 +82,38 @@ async function main() {
}

for (const [spec, compatFeatures] of specToCompatFeatures.entries()) {

// Separate out features that are already part of web-features.
const usedFeatures = new Map<string,Set<String>>();
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<string, Set<String>>();
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;

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());
}
Expand Down