feat(dev-infra): introduce validators for ng-dev config loading (#37049)
Introduces infrastructure to validate configuration of the ng-dev command at run time. Allowing for errors to be returned to the user running the command. PR Close #37049
This commit is contained in:

committed by
Misko Hevery

parent
45f4a47286
commit
14c0ec97d8
@ -5,9 +5,27 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {assertNoErrors, getConfig, NgDevConfig} from '../utils/config';
|
||||
|
||||
export interface CommitMessageConfig {
|
||||
maxLineLength: number;
|
||||
minBodyLength: number;
|
||||
types: string[];
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
/** Retrieve and validate the config as `CommitMessageConfig`. */
|
||||
export function getCommitMessageConfig() {
|
||||
// List of errors encountered validating the config.
|
||||
const errors: string[] = [];
|
||||
// The unvalidated config object.
|
||||
const config: Partial<NgDevConfig<{commitMessage: CommitMessageConfig}>> = getConfig();
|
||||
|
||||
if (config.commitMessage === undefined) {
|
||||
errors.push(`No configuration defined for "commitMessage"`);
|
||||
}
|
||||
|
||||
assertNoErrors(errors);
|
||||
return config as Required<typeof config>;
|
||||
}
|
||||
|
Reference in New Issue
Block a user