Joey Perrott d331e09b71 refactor(dev-infra): create ng-dev executable locally in the repo ()
Rather than running ng-dev via ts-node, going forward ng-dev is generated and run
locally via node.  Additionally, the generated file is tested on each commit to
ensure that the local generated version stays up to date.

PR Close 
2020-10-22 13:36:14 -07:00

51 lines
1.9 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* 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 * as yargs from 'yargs';
import {allChangedFilesSince, allFiles, allStagedFiles} from '../utils/repo-files';
import {checkFiles, formatFiles} from './format';
/** Build the parser for the format commands. */
export function buildFormatParser(localYargs: yargs.Argv) {
return localYargs.help()
.strict()
.demandCommand()
.option('check', {
type: 'boolean',
default: process.env['CI'] ? true : false,
description: 'Run the formatter to check formatting rather than updating code format'
})
.command(
'all', 'Run the formatter on all files in the repository', args => args,
({check}) => {
const executionCmd = check ? checkFiles : formatFiles;
executionCmd(allFiles());
})
.command(
'changed [shaOrRef]', 'Run the formatter on files changed since the provided sha/ref',
args => args.positional('shaOrRef', {type: 'string'}),
({shaOrRef, check}) => {
const sha = shaOrRef || 'master';
const executionCmd = check ? checkFiles : formatFiles;
executionCmd(allChangedFilesSince(sha));
})
.command(
'staged', 'Run the formatter on all staged files', args => args,
({check}) => {
const executionCmd = check ? checkFiles : formatFiles;
executionCmd(allStagedFiles());
})
.command(
'files <files..>', 'Run the formatter on provided files',
args => args.positional('files', {array: true, type: 'string'}), ({check, files}) => {
const executionCmd = check ? checkFiles : formatFiles;
executionCmd(files!);
});
}