devbonzai 1.7.6 → 1.8.0
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.
- package/cli.js +60 -36
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -810,12 +810,17 @@ function listAllFiles(dir, base = '', ignorePatterns = null) {
|
|
|
810
810
|
results.push(functionFilePath);
|
|
811
811
|
}
|
|
812
812
|
|
|
813
|
-
// Add
|
|
814
|
-
// Methods keep their dot notation name (e.g., Real.__init__.method)
|
|
813
|
+
// Add classes and their methods
|
|
815
814
|
for (const cls of parseResult.classes) {
|
|
815
|
+
// Add class itself (optional, but useful)
|
|
816
|
+
const className = cls.name + '.class';
|
|
817
|
+
const classFilePath = path.join(filePath, className).replace(/\\\\/g, '/');
|
|
818
|
+
results.push(classFilePath);
|
|
819
|
+
|
|
820
|
+
// Add methods nested under the class: ClassName.methodName
|
|
816
821
|
for (const method of cls.methods) {
|
|
817
822
|
const methodFileName = method.name + '.method';
|
|
818
|
-
const methodFilePath = path.join(
|
|
823
|
+
const methodFilePath = path.join(classFilePath, methodFileName).replace(/\\\\/g, '/');
|
|
819
824
|
results.push(methodFilePath);
|
|
820
825
|
}
|
|
821
826
|
}
|
|
@@ -884,47 +889,66 @@ app.get('/read', (req, res) => {
|
|
|
884
889
|
|
|
885
890
|
// Check if this is a virtual file request (.function, .method, or .class)
|
|
886
891
|
if (requestedPath.endsWith('.function') || requestedPath.endsWith('.method') || requestedPath.endsWith('.class')) {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
// Determine file type and parser
|
|
892
|
-
let parseResult = null;
|
|
892
|
+
// Traverse up the path to find the actual source file
|
|
893
|
+
let currentPath = filePath;
|
|
894
|
+
let sourceFilePath = null;
|
|
893
895
|
let parser = null;
|
|
894
896
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
897
|
+
// Keep going up until we find a source file (.py, .js, .jsx, .ts, .tsx, .vue)
|
|
898
|
+
while (currentPath !== ROOT && currentPath !== path.dirname(currentPath)) {
|
|
899
|
+
const stat = fs.existsSync(currentPath) ? fs.statSync(currentPath) : null;
|
|
900
|
+
|
|
901
|
+
// Check if current path is a file with a supported extension
|
|
902
|
+
if (stat && stat.isFile()) {
|
|
903
|
+
if (currentPath.endsWith('.py')) {
|
|
904
|
+
parser = extractPythonFunctions;
|
|
905
|
+
sourceFilePath = currentPath;
|
|
906
|
+
break;
|
|
907
|
+
} else if (currentPath.endsWith('.js') || currentPath.endsWith('.jsx') ||
|
|
908
|
+
currentPath.endsWith('.ts') || currentPath.endsWith('.tsx')) {
|
|
909
|
+
parser = extractJavaScriptFunctions;
|
|
910
|
+
sourceFilePath = currentPath;
|
|
911
|
+
break;
|
|
912
|
+
} else if (currentPath.endsWith('.vue')) {
|
|
913
|
+
parser = extractVueFunctions;
|
|
914
|
+
sourceFilePath = currentPath;
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// Move up one level
|
|
920
|
+
const parentPath = path.dirname(currentPath);
|
|
921
|
+
if (parentPath === currentPath) break; // Reached root
|
|
922
|
+
currentPath = parentPath;
|
|
903
923
|
}
|
|
904
924
|
|
|
905
|
-
|
|
925
|
+
if (!sourceFilePath || !parser) {
|
|
926
|
+
return res.status(404).send('Source file not found for virtual file');
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// Extract the requested item name from the requested path
|
|
930
|
+
let itemName = '';
|
|
931
|
+
let itemType = '';
|
|
932
|
+
|
|
933
|
+
if (requestedPath.endsWith('.function')) {
|
|
934
|
+
itemName = path.basename(requestedPath, '.function');
|
|
935
|
+
itemType = 'function';
|
|
936
|
+
} else if (requestedPath.endsWith('.method')) {
|
|
937
|
+
itemName = path.basename(requestedPath, '.method');
|
|
938
|
+
itemType = 'method';
|
|
939
|
+
} else if (requestedPath.endsWith('.class')) {
|
|
940
|
+
itemName = path.basename(requestedPath, '.class');
|
|
941
|
+
itemType = 'class';
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
// Check if the source file exists
|
|
906
945
|
try {
|
|
907
|
-
if (!fs.existsSync(
|
|
908
|
-
return res.status(404).send('
|
|
946
|
+
if (!fs.existsSync(sourceFilePath)) {
|
|
947
|
+
return res.status(404).send('Source file not found');
|
|
909
948
|
}
|
|
910
949
|
|
|
911
950
|
// Parse the file
|
|
912
|
-
parseResult = parser(
|
|
913
|
-
|
|
914
|
-
// Extract the requested item name
|
|
915
|
-
let itemName = '';
|
|
916
|
-
let itemType = '';
|
|
917
|
-
|
|
918
|
-
if (requestedPath.endsWith('.function')) {
|
|
919
|
-
itemName = path.basename(requestedPath, '.function');
|
|
920
|
-
itemType = 'function';
|
|
921
|
-
} else if (requestedPath.endsWith('.method')) {
|
|
922
|
-
itemName = path.basename(requestedPath, '.method');
|
|
923
|
-
itemType = 'method';
|
|
924
|
-
} else if (requestedPath.endsWith('.class')) {
|
|
925
|
-
itemName = path.basename(requestedPath, '.class');
|
|
926
|
-
itemType = 'class';
|
|
927
|
-
}
|
|
951
|
+
const parseResult = parser(sourceFilePath);
|
|
928
952
|
|
|
929
953
|
// Find and return the content
|
|
930
954
|
const content = findAndReturn(parseResult, itemName, itemType);
|