feat(dev-infra): create format tool in @angular/dev-infra-private (#36726)
Previously we used gulp to run our formatter, currently clang-format, across our repository. This new tool within ng-dev allows us to migrate away from our gulp based solution as our gulp solution had issue with memory pressure and would cause OOM errors with too large of change sets. PR Close #36726
This commit is contained in:

committed by
Andrew Kushnir

parent
cc71116ba6
commit
00724dcdbb
40
dev-infra/utils/repo-files.ts
Normal file
40
dev-infra/utils/repo-files.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. 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 {exec} from 'shelljs';
|
||||
import {getRepoBaseDir} from './config';
|
||||
|
||||
/**
|
||||
* A list of all files currently in the repo which have been modified since the provided sha.
|
||||
*
|
||||
* git diff
|
||||
* Deleted files (--diff-filter=d) are not included as they are not longer present in the repo
|
||||
* and can not be checked anymore.
|
||||
*
|
||||
* git ls-files
|
||||
* Untracked files (--others), which are not matched by .gitignore (--exclude-standard)
|
||||
* as they are expected to become tracked files.
|
||||
*/
|
||||
export function allChangedFilesSince(sha = 'HEAD') {
|
||||
const diffFiles = gitOutputAsArray(`git diff --name-only --diff-filter=d ${sha}`);
|
||||
const untrackedFiles = gitOutputAsArray(`git ls-files --others --exclude-standard`);
|
||||
// Use a set to deduplicate the list as its possible for a file to show up in both lists.
|
||||
return Array.from(new Set([...diffFiles, ...untrackedFiles]));
|
||||
}
|
||||
|
||||
export function allFiles() {
|
||||
return gitOutputAsArray(`git ls-files`);
|
||||
}
|
||||
|
||||
|
||||
function gitOutputAsArray(cmd: string) {
|
||||
return exec(cmd, {cwd: getRepoBaseDir(), silent: true})
|
||||
.split('\n')
|
||||
.map(x => x.trim())
|
||||
.filter(x => !!x);
|
||||
}
|
Reference in New Issue
Block a user