@rayburst/cli 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -410,11 +410,48 @@ function findNodesInFile(filePath, nodeMap) {
|
|
|
410
410
|
}
|
|
411
411
|
return nodes;
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function createRouterDecisionNode(sourceFilePath, gitHash, routeCount) {
|
|
414
|
+
return {
|
|
415
|
+
id: `${sourceFilePath}::RouterDecision::${gitHash}`,
|
|
416
|
+
type: "switch",
|
|
417
|
+
position: { x: 600, y: 400 },
|
|
418
|
+
data: {
|
|
419
|
+
label: "Router (TanStack)",
|
|
420
|
+
description: `URL-based routing decision tree with ${routeCount} routes`,
|
|
421
|
+
switchExpression: "window.location.pathname",
|
|
422
|
+
cases: `${routeCount} route${routeCount !== 1 ? "s" : ""}`
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function extractRoutePathFromFile(routeFilePath) {
|
|
427
|
+
let path5 = routeFilePath.replace(/^src\/routes\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/route$/, "").replace(/\/index$/, "");
|
|
428
|
+
if (path5 === "/__root") {
|
|
429
|
+
return "/";
|
|
430
|
+
}
|
|
431
|
+
path5 = path5.replace(/\/\$([^/]+)/g, (_, param) => `/:${param}`);
|
|
432
|
+
if (path5 === "" || path5 === "/") {
|
|
433
|
+
return "/";
|
|
434
|
+
}
|
|
435
|
+
return path5;
|
|
436
|
+
}
|
|
437
|
+
function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edgeType = "config", useRoutePathLabels = false) {
|
|
414
438
|
let edgesCreated = 0;
|
|
415
439
|
for (const targetFilePath of targetFilePaths) {
|
|
416
440
|
const targetNodes = findNodesInFile(targetFilePath, nodeMap);
|
|
441
|
+
const routePath = useRoutePathLabels ? extractRoutePathFromFile(targetFilePath) : null;
|
|
442
|
+
let edgeLabel = edgeType;
|
|
443
|
+
if (useRoutePathLabels && routePath) {
|
|
444
|
+
const isDynamic = routePath.includes(":");
|
|
445
|
+
if (isDynamic) {
|
|
446
|
+
edgeLabel = `path matches "${routePath}"`;
|
|
447
|
+
} else {
|
|
448
|
+
edgeLabel = `path === "${routePath}"`;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
417
451
|
for (const targetNode of targetNodes) {
|
|
452
|
+
if (targetNode.type !== "component") {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
418
455
|
if (sourceNode.id === targetNode.id) {
|
|
419
456
|
continue;
|
|
420
457
|
}
|
|
@@ -427,7 +464,7 @@ function createConfigBasedEdges(sourceNode, targetFilePaths, nodeMap, edges, edg
|
|
|
427
464
|
source: sourceNode.id,
|
|
428
465
|
target: targetNode.id,
|
|
429
466
|
type: "floating",
|
|
430
|
-
label:
|
|
467
|
+
label: edgeLabel
|
|
431
468
|
});
|
|
432
469
|
edgesCreated++;
|
|
433
470
|
}
|
|
@@ -576,7 +613,7 @@ function traceConfigToComponentPaths(configObject, propertyName, projectPath, pr
|
|
|
576
613
|
}
|
|
577
614
|
return [];
|
|
578
615
|
}
|
|
579
|
-
function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project) {
|
|
616
|
+
function detectConfigBasedComponents(sourceFile, nodes, nodeMap, edges, projectPath, project, gitHash) {
|
|
580
617
|
let totalEdgesCreated = 0;
|
|
581
618
|
try {
|
|
582
619
|
const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement);
|
|
@@ -618,16 +655,48 @@ function detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, pr
|
|
|
618
655
|
const componentPaths = analyzeJsxPropsForComponents(jsxElement, propName, projectPath, project);
|
|
619
656
|
console.log(`[DEBUG] Component paths found: ${componentPaths.length}`);
|
|
620
657
|
if (componentPaths.length > 0) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
componentPaths
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
`
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
658
|
+
if (propName === "router") {
|
|
659
|
+
console.log(`[DEBUG] Creating router decision node for ${componentPaths.length} routes`);
|
|
660
|
+
const relativePath = sourceFile.getFilePath().replace(projectPath + "/", "");
|
|
661
|
+
const routerNode = createRouterDecisionNode(relativePath, gitHash, componentPaths.length);
|
|
662
|
+
nodes.push(routerNode);
|
|
663
|
+
nodeMap.set(routerNode.id, routerNode);
|
|
664
|
+
console.log(`[DEBUG] Created router node: ${routerNode.id}`);
|
|
665
|
+
const appToRouterEdgeId = `e-${sourceNode.id}-${routerNode.id}`;
|
|
666
|
+
if (!edges.find((e) => e.id === appToRouterEdgeId)) {
|
|
667
|
+
edges.push({
|
|
668
|
+
id: appToRouterEdgeId,
|
|
669
|
+
source: sourceNode.id,
|
|
670
|
+
target: routerNode.id,
|
|
671
|
+
type: "floating",
|
|
672
|
+
label: "router prop"
|
|
673
|
+
});
|
|
674
|
+
totalEdgesCreated++;
|
|
675
|
+
console.log(`[DEBUG] Created edge: App -> Router`);
|
|
676
|
+
}
|
|
677
|
+
const routerToRoutesEdges = createConfigBasedEdges(
|
|
678
|
+
routerNode,
|
|
679
|
+
componentPaths,
|
|
680
|
+
nodeMap,
|
|
681
|
+
edges,
|
|
682
|
+
"route",
|
|
683
|
+
true
|
|
684
|
+
// Use route path labels
|
|
685
|
+
);
|
|
686
|
+
console.log(`[DEBUG] Created ${routerToRoutesEdges} edges from Router to routes`);
|
|
687
|
+
totalEdgesCreated += routerToRoutesEdges;
|
|
688
|
+
} else {
|
|
689
|
+
console.log(`[DEBUG] Creating edges for ${componentPaths.length} components`);
|
|
690
|
+
const edgesCreated = createConfigBasedEdges(
|
|
691
|
+
sourceNode,
|
|
692
|
+
componentPaths,
|
|
693
|
+
nodeMap,
|
|
694
|
+
edges,
|
|
695
|
+
`config:${propName}`
|
|
696
|
+
);
|
|
697
|
+
console.log(`[DEBUG] Edges created: ${edgesCreated}`);
|
|
698
|
+
totalEdgesCreated += edgesCreated;
|
|
699
|
+
}
|
|
631
700
|
}
|
|
632
701
|
}
|
|
633
702
|
}
|
|
@@ -701,7 +770,7 @@ async function analyzeProject(projectPath, projectId, onLog) {
|
|
|
701
770
|
log(` Analyzing config-based components...`);
|
|
702
771
|
let totalConfigEdges = 0;
|
|
703
772
|
for (const sourceFile of sourceFiles) {
|
|
704
|
-
const configEdges = detectConfigBasedComponents(sourceFile, nodeMap, edges, projectPath, project);
|
|
773
|
+
const configEdges = detectConfigBasedComponents(sourceFile, nodes, nodeMap, edges, projectPath, project, gitHash);
|
|
705
774
|
totalConfigEdges += configEdges;
|
|
706
775
|
}
|
|
707
776
|
if (totalConfigEdges > 0) {
|
package/dist/index.js
CHANGED
package/dist/vite-plugin.js
CHANGED