fix(schematics): fix format command to handle large number of files
This commit is contained in:
parent
a6cdd5ac5e
commit
2a892b7a41
@ -88,7 +88,21 @@ describe('Command line', () => {
|
||||
updateFile(
|
||||
'apps/myapp/src/main.ts',
|
||||
`
|
||||
const x = 3232;
|
||||
const x = 1111;
|
||||
`
|
||||
);
|
||||
|
||||
updateFile(
|
||||
'apps/myapp/src/app/app.module.ts',
|
||||
`
|
||||
const y = 1111;
|
||||
`
|
||||
);
|
||||
|
||||
updateFile(
|
||||
'apps/myapp/src/app/app.component.ts',
|
||||
`
|
||||
const z = 1111;
|
||||
`
|
||||
);
|
||||
|
||||
@ -97,7 +111,22 @@ describe('Command line', () => {
|
||||
fail('boom');
|
||||
} catch (e) {
|
||||
expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts');
|
||||
expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.module.ts');
|
||||
expect(e.stdout.toString()).toContain('apps/myapp/src/app/app.component.ts');
|
||||
}
|
||||
runCommand(
|
||||
'npm run format:write -- --files="apps/myapp/src/app/app.module.ts,apps/myapp/src/app/app.component.ts"'
|
||||
);
|
||||
|
||||
try {
|
||||
runCommand('npm run -s format:check');
|
||||
fail('boom');
|
||||
} catch (e) {
|
||||
expect(e.stdout.toString()).toContain('apps/myapp/src/main.ts');
|
||||
expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.module.ts');
|
||||
expect(e.stdout.toString()).not.toContain('apps/myapp/src/app/app.component.ts');
|
||||
}
|
||||
|
||||
runCommand('npm run format:write');
|
||||
expect(runCommand('npm run -s format:check')).toEqual('');
|
||||
},
|
||||
|
||||
@ -14,18 +14,18 @@ switch (command) {
|
||||
break;
|
||||
}
|
||||
|
||||
function parseFiles() {
|
||||
function parseFiles(): string[] {
|
||||
const args = process.argv.slice(3);
|
||||
if (args.length === 0) {
|
||||
return '"{apps,libs}/**/*.ts"';
|
||||
return ['"{apps,libs}/**/*.ts"'];
|
||||
}
|
||||
const dashDashFiles = args.filter(a => a.startsWith('--files='))[0];
|
||||
if (dashDashFiles) {
|
||||
args.splice(args.indexOf(dashDashFiles), 1);
|
||||
return `"${parseDashDashFiles(dashDashFiles).join(',')}"`;
|
||||
return parseDashDashFiles(dashDashFiles).map(t => `\"${t}\"`);
|
||||
} else {
|
||||
const withoutShahs = args.slice(2);
|
||||
return `"${getFilesFromShash(args[0], args[1]).join(',')}"`;
|
||||
return getFilesFromShash(args[0], args[1]).map(t => `\"${t}\"`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,19 +42,22 @@ function getFilesFromShash(sha1: string, sha2: string): string[] {
|
||||
.toString('utf-8')
|
||||
.split('\n')
|
||||
.map(a => a.trim())
|
||||
.filter(a => a.length > 0);
|
||||
.filter(a => a.length > 0)
|
||||
.filter(a => path.extname(a) === '.ts');
|
||||
}
|
||||
|
||||
function write(files: string) {
|
||||
execSync(`node ./node_modules/prettier/bin/prettier.js --single-quote --print-width 120 --write ${files}`, {
|
||||
function write(files: string[]) {
|
||||
execSync(`node ./node_modules/prettier/bin/prettier.js --single-quote --print-width 120 --write ${files.join(' ')}`, {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
}
|
||||
|
||||
function check(files: string) {
|
||||
function check(files: string[]) {
|
||||
try {
|
||||
execSync(
|
||||
`node ./node_modules/prettier/bin/prettier.js --single-quote --print-width 120 --list-different ${files}`,
|
||||
`node ./node_modules/prettier/bin/prettier.js --single-quote --print-width 120 --list-different ${files.join(
|
||||
' '
|
||||
)}`,
|
||||
{
|
||||
stdio: [0, 1, 2]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user