Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add filter argument to update-drafts script #1679

Merged
merged 8 commits into from
Sep 7, 2024

Conversation

jamesnw
Copy link
Collaborator

@jamesnw jamesnw commented Aug 27, 2024

While working through a set of features, it's helpful re-run update-drafts to see progress, but it makes things a bit messy to update all. This allows you to run:

  • npm run update-drafts -- --keys ext to update all drafts with a key that includes ext
  • npm run update-drafts -- --keys ext-blend-minmax to update a specific draft.
  • npm run update-drafts -- --paths features/draft/spec/css-* to update all drafts based on filename.

I opted to not port to yargs, unless there is likelihood for further options.

@ddbeck ddbeck added the tools and infrastructure Project internal tooling, such as linters, GitHub Actions, or repo settings label Aug 27, 2024
@@ -1,3 +1,7 @@
// Updates files in features/draft/spec/* with BCD keys mentioned in specs
// `npm run update-drafts` updates all
// `npm run update-drafts -- [key]` only updates features with a `shortname` that includes `key`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that this matches a key, not a file name? I think that's surprising and slightly inconvenient (e.g., it'd be nice to be able to use shell globbing or xargs to run this).

What do you think of using file names as arguments, then getting the key from the filename (kinda like dist does for yml and dist files)?

Or if you like the idea of providing a partial string (like your ext example), maybe we do need yargs, so we can have something like --by-key and --by-path options.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're correct that it takes a key, so paint-order would match but paint-order.yml or features/draft/spec/css-transforms-2.yml would not.

I agree that file paths would make sense to support, I can update to do that (and will go ahead and add yargs).

@jamesnw jamesnw requested a review from ddbeck August 28, 2024 18:29
Comment on lines +15 to +26
const argv = yargs(process.argv.slice(2))
.scriptName("update-drafts")
.usage("$0", "Update draft features with BCD keys mentioned in specs.")
.option("keys", {
type: "array",
describe: "Keys to match",
})
.option("paths", {
type: "array",
describe: "Draft feature files to update",
}).argv;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So CLIs are always more complicated than I imagine. 😅

This behaves very strangely if both options are set. I think it's applying both filters, such that nothing gets to match? I'm not sure.

I think the right thing to do here is to make sure the options don't layer on top of each other (or set some kind of flag like --matches=id, --matches=path, and then all positional arguments must be one type). But this is starting to get complicated and holding up useful work.

How about this: would you like to revert the changes after my review, add a # TODO: linking back here and one of us can take that up in a follow up PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a simple change to make it an AND- for instance, npx tsx scripts/update-drafts.ts --keys css --paths features/draft/spec/ba* will update all CSS specs AND badging.yml and battery-status.yml.

If this doesn't seem correct, I'll revert and TODO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there! See my comment below.

@jamesnw jamesnw requested a review from ddbeck August 30, 2024 03:10
Copy link
Collaborator

@ddbeck ddbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, pending one fix. Thank you!

for (const spec of webSpecs) {

let selectedSpecs = webSpecs;
let selectedKeys = filterKeys;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this almost works now! If you don't supply keys though, this value being undefined fails.

Suggested change
let selectedKeys = filterKeys;
let selectedKeys = filterKeys ?? [];

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks!

Comment on lines +15 to +26
const argv = yargs(process.argv.slice(2))
.scriptName("update-drafts")
.usage("$0", "Update draft features with BCD keys mentioned in specs.")
.option("keys", {
type: "array",
describe: "Keys to match",
})
.option("paths", {
type: "array",
describe: "Draft feature files to update",
}).argv;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there! See my comment below.

@jamesnw jamesnw requested a review from ddbeck September 7, 2024 17:38
@ddbeck ddbeck merged commit 87db5b8 into web-platform-dx:main Sep 7, 2024
3 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
tools and infrastructure Project internal tooling, such as linters, GitHub Actions, or repo settings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants