devbonzai 1.7.9 → 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.
Files changed (2) hide show
  1. package/cli.js +54 -35
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -817,10 +817,10 @@ function listAllFiles(dir, base = '', ignorePatterns = null) {
817
817
  const classFilePath = path.join(filePath, className).replace(/\\\\/g, '/');
818
818
  results.push(classFilePath);
819
819
 
820
- // Add methods with dot notation: ClassName.methodName
820
+ // Add methods nested under the class: ClassName.methodName
821
821
  for (const method of cls.methods) {
822
822
  const methodFileName = method.name + '.method';
823
- const methodFilePath = path.join(filePath, methodFileName).replace(/\\\\/g, '/');
823
+ const methodFilePath = path.join(classFilePath, methodFileName).replace(/\\\\/g, '/');
824
824
  results.push(methodFilePath);
825
825
  }
826
826
  }
@@ -889,47 +889,66 @@ app.get('/read', (req, res) => {
889
889
 
890
890
  // Check if this is a virtual file request (.function, .method, or .class)
891
891
  if (requestedPath.endsWith('.function') || requestedPath.endsWith('.method') || requestedPath.endsWith('.class')) {
892
- const parentFilePath = path.dirname(filePath);
893
- const parentRelativePath = path.relative(ROOT, parentFilePath);
894
- const fileName = path.basename(parentRelativePath);
895
-
896
- // Determine file type and parser
897
- let parseResult = null;
892
+ // Traverse up the path to find the actual source file
893
+ let currentPath = filePath;
894
+ let sourceFilePath = null;
898
895
  let parser = null;
899
896
 
900
- if (fileName.endsWith('.py')) {
901
- parser = extractPythonFunctions;
902
- } else if (fileName.endsWith('.js') || fileName.endsWith('.jsx') || fileName.endsWith('.ts') || fileName.endsWith('.tsx')) {
903
- parser = extractJavaScriptFunctions;
904
- } else if (fileName.endsWith('.vue')) {
905
- parser = extractVueFunctions;
906
- } else {
907
- return res.status(404).send('Parent file type not supported');
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;
923
+ }
924
+
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';
908
942
  }
909
943
 
910
- // Check if the parent file exists
944
+ // Check if the source file exists
911
945
  try {
912
- if (!fs.existsSync(parentFilePath)) {
913
- return res.status(404).send('Parent file not found');
946
+ if (!fs.existsSync(sourceFilePath)) {
947
+ return res.status(404).send('Source file not found');
914
948
  }
915
949
 
916
950
  // Parse the file
917
- parseResult = parser(parentFilePath);
918
-
919
- // Extract the requested item name
920
- let itemName = '';
921
- let itemType = '';
922
-
923
- if (requestedPath.endsWith('.function')) {
924
- itemName = path.basename(requestedPath, '.function');
925
- itemType = 'function';
926
- } else if (requestedPath.endsWith('.method')) {
927
- itemName = path.basename(requestedPath, '.method');
928
- itemType = 'method';
929
- } else if (requestedPath.endsWith('.class')) {
930
- itemName = path.basename(requestedPath, '.class');
931
- itemType = 'class';
932
- }
951
+ const parseResult = parser(sourceFilePath);
933
952
 
934
953
  // Find and return the content
935
954
  const content = findAndReturn(parseResult, itemName, itemType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devbonzai",
3
- "version": "1.7.9",
3
+ "version": "1.8.0",
4
4
  "description": "Quickly set up a local file server in any repository for browser-based file access",
5
5
  "main": "cli.js",
6
6
  "bin": {