-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add undist script #2474
Add undist script #2474
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is really useful!
I have one nit where you might want to throw an error.
I'm wondering if the positional argument should be a feature id rather than a path, as this is only useful for features, and not drafts.
Yeah, I had the same feeling but given the dist
script also uses paths I would go for consistency for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. I have a few optional suggestions for you, @jamesnw. But you're welcome to merge at your discretion.
scripts/undist.ts
Outdated
// Accept `-a key1,key2,key3` as well as `-a key1 -a key2 -a key3` | ||
const additions = add.flatMap((addition) => addition.split(",")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both -a key1 key2 key3
and -a key1 -a key2 -a key3
already work. Does a comma-separated version allow for something that the other two forms don't already cover? My inclination is to not support an unusual shell notation, unless there's an explicit use case for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call- removed!
scripts/undist.ts
Outdated
let base = path; | ||
if (path.endsWith(".yml.dist")) { | ||
base = path.slice(0, -9); | ||
} else if (path.endsWith(".yml")) { | ||
base = path.slice(0, -4); | ||
} | ||
return { | ||
yml: `${base}.yml`, | ||
dist: `${base}.yml.dist`, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing node:path
could avoid some magic numbers. Something like this:
let base = path; | |
if (path.endsWith(".yml.dist")) { | |
base = path.slice(0, -9); | |
} else if (path.endsWith(".yml")) { | |
base = path.slice(0, -4); | |
} | |
return { | |
yml: `${base}.yml`, | |
dist: `${base}.yml.dist`, | |
}; | |
const { name, ext } = path.parse(path); | |
const id = ext === ".dist" ? path.basename(name) : name; | |
return { | |
yml: `${id}.yml`, | |
dist: `${id}.yml.dist`, | |
}; |
As we migrate more keys to BCD, adding or changing keys will be more challenging. We essentially will need to "undist" the .dist file, and move the keys without comments over to the .yml file.
Some examples-
I'm wondering if the positional argument should be a feature id rather than a path, as this is only useful for features, and not drafts.
I opted to make this work on a single file rather than multiple to enable the add functionality, as that use case seems the most common.