Skip to content

Commit 1f00c98

Browse files
committed
fix some issue with grouping and add to changlog
1 parent 73ae055 commit 1f00c98

7 files changed

Lines changed: 55 additions & 39 deletions

File tree

‎packages/cli/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
Implement grouping
6+
Fix minor UI issue with edges
7+
58
## [0.0.6] - 2024-10-27
69

710
Update design css

‎packages/cli/src/api/scan.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { z } from "zod";
22
import { getDependencyTree } from "../helper/dependencies";
33
import { ScanCodebaseResponsePayload } from "../helper/payloads";
4-
import { iterateOverTree } from "../helper/tree";
4+
import { getEndpontsFromTree } from "../helper/tree";
55
import { scanSchema } from "./helpers/validation";
66

77
export function scan(
88
payload: z.infer<typeof scanSchema>,
99
): ScanCodebaseResponsePayload {
1010
const tree = getDependencyTree(payload.entrypointPath);
1111

12-
const endpoints = iterateOverTree(tree);
12+
const endpoints = getEndpontsFromTree(tree);
1313

1414
return { endpoints };
1515
}

‎packages/cli/src/api/split.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import path from "path";
33
import { getDependencyTree } from "../helper/dependencies";
44
import { cleanupOutputDir, createOutputDir } from "../helper/file";
55
import { SplitCodebaseResponsePayload } from "../helper/payloads";
6-
import { getGroupsFromTree, splitPath } from "../helper/tree";
6+
import { getEndpontsFromTree, splitPath } from "../helper/tree";
77
import { splitSchema } from "./helpers/validation";
88
import { z } from "zod";
99
import { GroupMap } from "../helper/types";
10+
import { getGroupsFromEndpoints } from "../helper/groups";
1011

1112
export function split(
1213
payload: z.infer<typeof splitSchema>,
@@ -23,8 +24,11 @@ export function split(
2324
cleanupOutputDir(payload.outputDir);
2425
createOutputDir(payload.outputDir);
2526

26-
// Iterate over the tree and get groups
27-
const groups = getGroupsFromTree(tree);
27+
// Iterate over the tree and get endpoints
28+
const endpoints = getEndpontsFromTree(tree);
29+
30+
// Get groups from the endpoints
31+
const groups = getGroupsFromEndpoints(endpoints);
2832

2933
// Process each endpoint for splitting
3034
for (const group of groups) {

‎packages/cli/src/api/sync.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
} from "../helper/file";
1010
import { getDependencyTree } from "../helper/dependencies";
1111
import Parser from "tree-sitter";
12-
import { iterateOverTree } from "../helper/tree";
12+
import { getEndpontsFromTree } from "../helper/tree";
1313

1414
export function sync(payload: z.infer<typeof syncSchema>) {
1515
const tree = getDependencyTree(payload.entrypointPath);
1616

17-
const endpoints = iterateOverTree(tree);
17+
const endpoints = getEndpontsFromTree(tree);
1818

1919
const updatedEndpoints = endpoints.map((endpoint) => {
2020
const updatedEndpoint = payload.endpoints.find(

‎packages/cli/src/commands/split.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import path from "path";
22
import fs from "fs";
33
import { getDependencyTree } from "../helper/dependencies";
44
import { cleanupOutputDir, createOutputDir } from "../helper/file";
5-
import { getGroupsFromTree, splitPath } from "../helper/tree";
5+
import { getEndpontsFromTree, splitPath } from "../helper/tree";
66
import { GroupMap } from "../helper/types";
7+
import { getGroupsFromEndpoints } from "../helper/groups";
78

89
export default function splitCommandHandler(
910
entrypointPath: string, // Path to the entrypoint file
@@ -17,8 +18,11 @@ export default function splitCommandHandler(
1718
cleanupOutputDir(outputDir);
1819
createOutputDir(outputDir);
1920

20-
// Iterate over the tree and get groups
21-
const groups = getGroupsFromTree(tree);
21+
// Iterate over the tree and get endpoints
22+
const endpoints = getEndpontsFromTree(tree);
23+
24+
// Get groups from the endpoints
25+
const groups = getGroupsFromEndpoints(endpoints);
2226

2327
// Process each endpoint for splitting
2428
for (const group of groups) {

‎packages/cli/src/helper/groups.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Endpoint, Group } from "./types";
2+
3+
export function getGroupsFromEndpoints(endpoints: Endpoint[]) {
4+
const groups: Group[] = [];
5+
6+
for (const endpoint of endpoints) {
7+
const group = groups.find((group) => group.name === endpoint.group);
8+
if (group) {
9+
group.endpoints.push(endpoint);
10+
} else {
11+
groups.push({
12+
name: endpoint.group || "",
13+
endpoints: [endpoint],
14+
});
15+
}
16+
}
17+
18+
return groups;
19+
}

‎packages/cli/src/helper/tree.ts‎

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getEndpointsFromFile } from "./file";
55
import { Dependencies, Endpoint, Group, GroupMap } from "./types";
66

77
// Helper function to process the tree and gather endpoints
8-
export function getGroupsFromTree(
8+
export function getEndpontsFromTree(
99
tree: Dependencies,
1010
parentFiles: string[] = [],
1111
endpoints: Endpoint[] = [],
@@ -27,25 +27,11 @@ export function getGroupsFromTree(
2727
// Recursively process the tree
2828
if (typeof value !== "string") {
2929
const updatedParentFiles = [...parentFiles, filePath];
30-
getGroupsFromTree(value, updatedParentFiles, endpoints);
30+
getEndpontsFromTree(value, updatedParentFiles, endpoints);
3131
}
3232
}
3333

34-
const groups: Group[] = [];
35-
36-
for (const endpoint of endpoints) {
37-
const group = groups.find((group) => group.name === endpoint.group);
38-
if (group) {
39-
group.endpoints.push(endpoint);
40-
} else {
41-
groups.push({
42-
name: endpoint.group || "",
43-
endpoints: [endpoint],
44-
});
45-
}
46-
}
47-
48-
return groups;
34+
return endpoints;
4935
}
5036

5137
// Function to handle splitting and storing paths based on the split command logic
@@ -73,18 +59,18 @@ export function splitPath(
7359
);
7460
fs.copyFileSync(entrypointPath, entrypointCopyPath);
7561

76-
// Copy other files based on the dependencies, remove duplicates
77-
const files = [
78-
...new Set(
79-
...group.endpoints.map((endpoint) => {
80-
return [
81-
endpoint.filePath,
82-
...endpoint.parentFilePaths,
83-
...endpoint.childrenFilePaths,
84-
];
85-
}),
86-
),
87-
];
62+
// Copy other files based on the dependencies
63+
const endpointsFiles = group.endpoints.map((endpoint) => {
64+
return [
65+
endpoint.filePath,
66+
...endpoint.parentFilePaths,
67+
...endpoint.childrenFilePaths,
68+
];
69+
});
70+
71+
// Flatten the array and remove duplicates
72+
const files = Array.from(new Set(endpointsFiles.flat()));
73+
8874
for (const filePath of files) {
8975
const relativeFileNamePath = path.relative(targetDir, filePath);
9076
const destinationPath = path.join(

0 commit comments

Comments
 (0)