Skip to content

Commit

Permalink
feat(ng-dev/format): add staged-re command
Browse files Browse the repository at this point in the history
add a staged-re command which after formatting the staged files also
re adds them to the staging area
  • Loading branch information
dario-piotrowicz committed Feb 12, 2022
1 parent 0e1a218 commit c69c815
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ng-dev/format/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export function buildFormatParser(localYargs: yargs.Argv) {
process.exitCode = await executionCmd(allStagedFiles);
},
)
.command(
'staged-re',
`Run the formatter on all staged files and re-stages the
formatted files (this command ignores the --check option)`,
(args) => args,
async () => {
const allStagedFiles = GitClient.get().allStagedFiles();
process.exitCode = await formatFiles(allStagedFiles);
if (process.exitCode === 0) {
GitClient.get().stageFiles(allStagedFiles);
}
},
)
.command(
'files <files..>',
'Run the formatter on provided files',
Expand Down
5 changes: 5 additions & 0 deletions ng-dev/utils/git/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ export class GitClient {
);
}

/** Adds the provided files to the staging area. */
stageFiles(files: string[]) {
return gitOutputAsArray(this.runGraceful(['add', files.join(' ')]));
}

/** Retrieve a list of all files tracked in the repository. */
allFiles(): string[] {
return gitOutputAsArray(this.runGraceful(['ls-files']));
Expand Down

0 comments on commit c69c815

Please sign in to comment.