feat(schematics): affected support for uncommitted changes
Extended the syntax for affected so that it can get the list of files from either locally staged changes or all modified but unstaged files. Syntax is: nx affected apps staged nx affected apps unstaged This could enable developer to more easily run a subset of tests locally before committing. Related to #201
This commit is contained in:
parent
cd8a0feb24
commit
113b51bd33
@ -10,7 +10,7 @@ export class FormatFiles implements TaskConfigurationGenerator<any> {
|
||||
return {
|
||||
name: 'node-package',
|
||||
options: {
|
||||
command: 'run format',
|
||||
command: 'run format -- --untracked',
|
||||
quiet: true
|
||||
}
|
||||
};
|
||||
|
||||
@ -38,6 +38,9 @@ function printError(command: string, e: any) {
|
||||
console.error(
|
||||
`Or pass the list of files, as follows: npm run affected:${command} -- --files="libs/mylib/index.ts,libs/mylib2/index.ts".`
|
||||
);
|
||||
console.error(
|
||||
`Or to get the list of files from staged or unstaged changes: npm run affected:${command} -- staged | unstaged".`
|
||||
);
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
|
||||
@ -29,12 +29,25 @@ export function parseFiles(
|
||||
});
|
||||
|
||||
const dashDashFiles = named.filter(a => a.startsWith('--files='))[0];
|
||||
const uncommitted = named.some(a => a === '--uncommitted');
|
||||
const untracked = named.some(a => a === '--untracked');
|
||||
|
||||
if (dashDashFiles) {
|
||||
named.splice(named.indexOf(dashDashFiles), 1);
|
||||
return {
|
||||
files: parseDashDashFiles(dashDashFiles),
|
||||
rest: [...unnamed, ...named]
|
||||
};
|
||||
} else if (uncommitted) {
|
||||
return {
|
||||
files: getUncommittedFiles(),
|
||||
rest: [...unnamed, ...named]
|
||||
};
|
||||
} else if (untracked) {
|
||||
return {
|
||||
files: getUntrackedFiles(),
|
||||
rest: [...unnamed, ...named]
|
||||
};
|
||||
} else if (unnamed.length >= 2) {
|
||||
return {
|
||||
files: getFilesFromShash(unnamed[0], unnamed[1]),
|
||||
@ -53,8 +66,20 @@ function parseDashDashFiles(dashDashFiles: string): string[] {
|
||||
return f.split(',').map(f => f.trim());
|
||||
}
|
||||
|
||||
function getUncommittedFiles(): string[] {
|
||||
return parseGitOutput(`git diff --name-only HEAD .`);
|
||||
}
|
||||
|
||||
function getUntrackedFiles(): string[] {
|
||||
return parseGitOutput(`git ls-files --others --exclude-standard`);
|
||||
}
|
||||
|
||||
function getFilesFromShash(sha1: string, sha2: string): string[] {
|
||||
return execSync(`git diff --name-only ${sha1} ${sha2}`)
|
||||
return parseGitOutput(`git diff --name-only ${sha1} ${sha2}`);
|
||||
}
|
||||
|
||||
function parseGitOutput(command: string): string[] {
|
||||
return execSync(command)
|
||||
.toString('utf-8')
|
||||
.split('\n')
|
||||
.map(a => a.trim())
|
||||
|
||||
@ -10,7 +10,7 @@ export class FormatFiles implements TaskConfigurationGenerator<any> {
|
||||
return {
|
||||
name: 'node-package',
|
||||
options: {
|
||||
command: 'run format',
|
||||
command: 'run format -- --untracked',
|
||||
quiet: true
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user