Skip to content

Commit ba6000a

Browse files
committed
build: 📦 fix cascade-changes
1 parent eae4786 commit ba6000a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

‎tools/cascade-changes.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ async function main(args: string[]) {
1616
.flat();
1717

1818
const startIndex = projects.indexOf(startProject);
19-
const filteredProjects = projects.slice(startIndex);
19+
if (startIndex === -1) {
20+
console.error(`Project ${startProject} not found`);
21+
process.exit(1);
22+
}
2023

21-
const pairwisedProjects = filteredProjects.reduce(
22-
(acc, project, index) => {
23-
if (index > 0) {
24-
acc.push([projects[index - 1], project]);
25-
}
26-
return acc;
27-
},
28-
[] as [string, string][],
29-
);
24+
const filteredProjects = projects.slice(startIndex);
25+
const pairwisedProjects = pairwise(filteredProjects);
3026

3127
for (const [source, destination] of pairwisedProjects) {
3228
execSync(`pnpm nx run tools:clone-changes ${source} ${destination}`, {
@@ -42,4 +38,16 @@ function computeExerciseProjects(exerciseId: string) {
4238
};
4339
}
4440

41+
function pairwise<T>(list: Array<T>): Array<[T, T]> {
42+
return list.reduce(
43+
(acc, project, index) => {
44+
if (index > 0) {
45+
acc.push([list[index - 1], project]);
46+
}
47+
return acc;
48+
},
49+
[] as [T, T][],
50+
);
51+
}
52+
4553
main(process.argv.slice(2));

0 commit comments

Comments
 (0)