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
4 changes: 1 addition & 3 deletions features/draft/html-elements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ To help out, pick a feature and do the following:
its own feature or if it should be grouped with other features.
- Review `baseline_low_date`, does it look plausible? If not, remove features
from `compat_features` until the date and browser versions seem plausible. Run
`npm run dist features/draft/html-elements/tag.yml` to regenerate dist. If
this throws an error, most likely BCD needs to be updated first to provide
better data.
`npm run dist features/draft/html-elements` to regenerate dist.
- Write a description for the feature.
- Move the file into the main features/ directory and submit a PR with your
changes.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"schema-defs:write": "npm run schema-defs -- --out ./schemas/defs.schema.json",
"test": "npm run test:caniuse -- --quiet && npm run test:schema && npm run test:specs && npm run test:format && npm run test:dist && npm run test --workspaces",
"test:caniuse": "tsx scripts/caniuse.ts",
"test:dist": "tsx scripts/dist.ts --check features/**/*.yml.dist",
"test:dist": "tsx scripts/dist.ts --check",
"test:schema": "tsx scripts/schema.ts",
"test:specs": "tsx scripts/specs.ts",
"test:format": "prettier --check .",
Expand Down
26 changes: 20 additions & 6 deletions scripts/dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import { isDeepStrictEqual } from "node:util";
import winston from "winston";
import YAML, { Document } from "yaml";
import yargs from "yargs";
import { fdir } from "fdir";

const argv = yargs(process.argv.slice(2))
.scriptName("dist")
.usage("$0 [filenames..]", "Generate .yml.dist from .yml", (yargs) =>
yargs.positional("filenames", {
describe: "YAML files to check/update.",
.usage("$0 [paths..]", "Generate .yml.dist from .yml", (yargs) =>
yargs.positional("paths", {
describe: "Directories or files to check/update.",
default: ["features"],
}),
)
.demandOption("filenames")
.option("check", {
boolean: true,
default: false,
Expand Down Expand Up @@ -208,16 +209,29 @@ function warnOnNeedlessOverrides(id, overridden, generated) {
}

function main() {
const filePaths = argv.paths.flatMap((fileOrDirectory) => {
if (fs.statSync(fileOrDirectory).isDirectory()) {
// Expand directory to any existing .dist file within.
// TODO: Change this to .yml when all features have dist files.
return new fdir()
.withBasePath()
.filter((fp) => fp.endsWith(".dist"))
.crawl(fileOrDirectory)
.sync();
}
return fileOrDirectory;
});

// Map from .yml to .yml.dist to filter out duplicates.
const sourceToDist = new Map<string, string>(
argv.filenames.map((filePath: string) => {
filePaths.map((filePath: string) => {
const ext = path.extname(filePath);
if (![".dist", ".yml"].includes(ext)) {
throw new Error(
`Cannot generate dist for ${filePath}, only YAML input is supported`,
);
}
// Start from the source even if dist is given
// Start from the source even if dist is given.
if (filePath.endsWith(".dist")) {
const candidateFilePath = filePath.substring(0, filePath.length - 5);

Expand Down