Add message to config scopes
Closed this issue · 1 comments
Similar to the config's types
, it would be great to have a message. Something like:
interface Scope {
name: string;
message: string;
}
interface Config {
// ...
scopes: Scope[];
// ...
}
That way, it will be easier for new project contributors to check what each scope
is for when using prompt
mode.
Edit:
I'm not familiar with io-ts
so I don't know if this is the correct approach on how to do this:
const ScopeNameOnly = t.string;
export type ScopeNameOnly = t.TypeOf<typeof ScopeNameOnly>;
export function isScopeNameOnly(scopes: Scope[]): boolean {
return ScopeNameOnly.is(scopes[0]);
}
const ScopeWithMessage = t.type({
name: t.string,
message: t.string,
});
export type ScopeWithMessage = t.TypeOf<typeof ScopeWithMessage>;
export function isScopeWithMessage(scopes: Scope[]): boolean {
return ScopeWithMessage.is(scopes[0]);
}
/** This way, Scope can still support the basic string[] for backwards compatibility. */
const Scope = t.union([ScopeNameOnly, ScopeWithMessage]);
export type Scope = t.TypeOf<typeof Scope>; // Should be (string|{name:string,message:string})[].
Then getScopes(type: string, config: Config): Scope[]
can transform the basic ScopeNameOnly[]
to ScopeWithMessage[]
.
Very good suggestion, thank you! I did the changes myself by making scopes and scopeOverrides be the same type as types
. I also made this repo use this new feature directly as you can see in the package.json
. I am quickly fixing a small issue with the breaking changes prompt and then release a new version with both of your issues fixed