Skip to content

Commit 84686d9

Browse files
bcabanesvsavkin
authored andcommitted
fix(command-line): format split in chunks patterns
The format command now splits all the array containing all the urls and patterns given, in smaller chunks arrays, executing the command on each chunks. This prevent to have too long argument on the command for the terminal, which can lead to error on specific OS. The chaining of command is transparent for the user. close #511
1 parent f93d8e3 commit 84686d9

File tree

1 file changed

+13
-2
lines changed
  • packages/schematics/src/command-line

1 file changed

+13
-2
lines changed

packages/schematics/src/command-line/format.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ export function format(args: string[]) {
1414
process.exit(1);
1515
}
1616

17+
// Chunkify the patterns array to prevent crashing the windows terminal
18+
const chunkList: string[][] = chunkify(patterns, 70);
19+
1720
switch (command) {
1821
case 'write':
19-
write(patterns);
22+
chunkList.forEach(chunk => write(chunk));
2023
break;
2124
case 'check':
22-
check(patterns);
25+
chunkList.forEach(chunk => check(chunk));
2326
break;
2427
}
2528
}
@@ -48,6 +51,14 @@ function getPatternsFromApps(affectedFiles: string[]): string[] {
4851
}
4952
}
5053

54+
function chunkify(target: string[], size: number): string[][] {
55+
return target.reduce((current: string[][], value: string, index: number) => {
56+
if (index % size === 0) current.push([]);
57+
current[current.length - 1].push(value);
58+
return current;
59+
}, []);
60+
}
61+
5162
function printError(command: string, e: any) {
5263
console.error(
5364
`Pass the SHA range, as follows: npm run format:${command} -- SHA1 SHA2.`

0 commit comments

Comments
 (0)