Skip to content

Commit

Permalink
update-drafts: clean up completed specs
Browse files Browse the repository at this point in the history
This works even if the specification has been superseded.
  • Loading branch information
ddbeck committed Nov 13, 2024
1 parent edcd078 commit 170750b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
53 changes: 0 additions & 53 deletions features/draft/spec/css-grid-2.yml

This file was deleted.

29 changes: 27 additions & 2 deletions scripts/update-drafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { fileURLToPath } from "node:url";
import Path from "path";
import webSpecs from "web-specs" assert { type: "json" };
import winston from "winston";
import { Document } from "yaml";
import { Document, parse } from "yaml";
import yargs from "yargs";

import { features } from "../index.js";
import { FeatureData } from "../types.js";

type WebSpecsSpec = (typeof webSpecs)[number];

Expand Down Expand Up @@ -270,6 +270,31 @@ async function main() {
await fs.writeFile(destination, proposedFile);
logger.info(`${destination}: updated`);
}

// Clean up completed specs
const assignedKeys = Object.values(features).flatMap(
(f) => f.compat_features ?? [],
);
for (const spec of webSpecs) {
const id = formatIdentifier(spec.shortname);
const destination = `features/draft/spec/${id}.yml`;

if (!fsSync.existsSync(destination)) {
continue;
}

const source = fsSync.readFileSync(destination, { encoding: "utf-8" });
const draft = parse(source) as FeatureData;

if (
(draft.compat_features ?? []).some((key) => !assignedKeys.includes(key))
) {
continue;
}

fsSync.rmSync(destination);
logger.warn(`${destination}: deleted (all keys accounted for)`);
}
}

if (process.argv[1] === fileURLToPath(import.meta.url)) {
Expand Down

0 comments on commit 170750b

Please sign in to comment.