feat(dev-infra): standard CLI commands using yargs (#36326)

Creates a standard model for CLI commands provided by ng-dev.
Allows for us to have any of the tools/scripts extend to be
included in the ng-dev command, or be standalone using the same
yargs parser.

PR Close #36326
This commit is contained in:
Joey Perrott
2020-03-26 10:45:09 -07:00
committed by Kara Erickson
parent 326240eb91
commit 43006bcc45
9 changed files with 114 additions and 40 deletions

View File

@ -6,26 +6,17 @@
* 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 {readFileSync} from 'fs';
import {join} from 'path';
import {verify} from './pullapprove/verify';
import {validateCommitMessage} from './commit-message/validate';
import {getRepoBaseDir} from './utils/config';
import * as yargs from 'yargs';
import {tsCircularDependenciesBuilder} from './ts-circular-dependencies/index';
import {buildPullapproveParser} from './pullapprove/cli';
import {buildCommitMessageParser} from './commit-message/cli';
const args = process.argv.slice(2);
// TODO(josephperrott): Set up proper cli flag/command handling
switch (args[0]) {
case 'pullapprove:verify':
verify();
break;
case 'commit-message:pre-commit-validate':
const commitMessage = readFileSync(join(getRepoBaseDir(), '.git/COMMIT_EDITMSG'), 'utf8');
if (validateCommitMessage(commitMessage)) {
console.info('√ Valid commit message');
}
break;
default:
console.info('No commands were matched');
}
yargs.scriptName('ng-dev')
.demandCommand()
.recommendCommands()
.command('ts-circular-deps <command>', '', tsCircularDependenciesBuilder)
.command('pullapprove <command>', '', buildPullapproveParser)
.command('commit-message <command>', '', buildCommitMessageParser)
.wrap(120)
.strict()
.parse();