Skip to content

Commit fac86f0

Browse files
committed
updated api docs
1 parent d2ec6f8 commit fac86f0

23 files changed

+802
-229
lines changed

docs/api/apiaccess/fs/createFile.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,89 @@ data:
3737
<CBBaseInfo/>
3838
<CBParameters/>
3939

40-
### Example
40+
## Examples
41+
42+
### Basic File Creation
43+
44+
```js
45+
// Create a simple text file
46+
const result = await codebolt.fs.createFile(
47+
'example.txt',
48+
'This is the content of the file.',
49+
'/home/user/documents'
50+
);
51+
console.log('File created:', result);
52+
```
53+
54+
### Creating Files with Complex Content
55+
56+
```js
57+
// Create a JavaScript file with code content
58+
const jsCodeContent = `
59+
// Sample JavaScript file with various code definitions
60+
class TestClass {
61+
constructor(name) {
62+
this.name = name;
63+
}
64+
65+
testMethod() {
66+
return 'Hello from ' + this.name;
67+
}
68+
69+
static staticMethod() {
70+
return 'Static method called';
71+
}
72+
}
73+
74+
function testFunction(param1, param2) {
75+
return param1 + param2;
76+
}
77+
78+
const arrowFunction = (x, y) => x * y;
79+
80+
module.exports = { TestClass, testFunction, arrowFunction };
81+
`;
82+
83+
const createResult = await codebolt.fs.createFile(
84+
'test-code-definitions.js',
85+
jsCodeContent,
86+
'.'
87+
);
88+
console.log('JavaScript file created:', createResult);
89+
```
90+
91+
### Error Handling
92+
93+
```js
94+
try {
95+
const result = await codebolt.fs.createFile(
96+
'test-file.txt',
97+
'This is a test file created by CodeboltJS',
98+
'.'
99+
);
100+
101+
if (result.success) {
102+
console.log('✅ File created successfully:', result.fileName);
103+
console.log('Message:', result.message);
104+
} else {
105+
console.log('❌ File creation failed:', result.message);
106+
}
107+
} catch (error) {
108+
console.error('Error creating file:', error.message);
109+
}
110+
```
111+
112+
### Creating Files in Current Directory
113+
114+
```js
115+
// Create a file in the current working directory
116+
const result = await codebolt.fs.createFile(
117+
'fs-test-file.txt',
118+
'This is a test file created by CodeboltJS FS test',
119+
'.'
120+
);
121+
console.log('File created in current directory:', result);
122+
```
41123

42124
```js
43125
// Let's assume you want to create a file named example.txt in the /home/user/documents directory with some content.

docs/api/apiaccess/fs/createFolder.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,70 @@ data:
2424
<CBBaseInfo/>
2525
<CBParameters/>
2626

27-
### Example
27+
## Examples
28+
29+
### Basic Folder Creation
30+
31+
```js
32+
// Create a folder in a specific directory
33+
const result = await codebolt.fs.createFolder('exampleFolder', '/home/user/documents');
34+
console.log('Folder created:', result);
35+
```
36+
37+
### Create Folder in Current Directory
38+
39+
```js
40+
// Create a folder in the current working directory
41+
const folderResult = await codebolt.fs.createFolder('test-folder', '.');
42+
console.log('✅ Folder created:', folderResult);
43+
```
44+
45+
### Complete Workflow with File Operations
46+
47+
```js
48+
// Create a project structure
49+
await codebolt.fs.createFolder('my-project', '.');
50+
await codebolt.fs.createFolder('src', './my-project');
51+
52+
// Create files in the folders
53+
await codebolt.fs.createFile('index.js', 'console.log("Hello World");', './my-project/src');
54+
55+
// List the created structure
56+
const projectFiles = await codebolt.fs.listFile('./my-project', true);
57+
console.log('Project structure:', projectFiles);
58+
```
59+
60+
### Create Multiple Folders
61+
62+
```js
63+
// Create multiple folders for different purposes
64+
const folders = ['assets', 'components', 'utils', 'config'];
65+
66+
for (const folder of folders) {
67+
try {
68+
const result = await codebolt.fs.createFolder(folder, '.');
69+
console.log(`✅ Created folder: ${folder}`, result);
70+
} catch (error) {
71+
console.error(`❌ Failed to create folder ${folder}:`, error.message);
72+
}
73+
}
74+
```
75+
76+
### Error Handling
77+
78+
```js
79+
try {
80+
const result = await codebolt.fs.createFolder('test-folder', '.');
81+
82+
if (result.success) {
83+
console.log('✅ Folder created successfully');
84+
} else {
85+
console.log('❌ Folder creation failed:', result.message);
86+
}
87+
} catch (error) {
88+
console.error('Error creating folder:', error.message);
89+
}
90+
```
2891

2992
```js
3093
// Let's assume you want to create a folder named "exampleFolder" in the /home/user/documents directory.

docs/api/apiaccess/fs/deleteFile.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,20 @@ data:
2424
<CBBaseInfo/>
2525
<CBParameters/>
2626

27-
### Example
27+
## Examples
28+
29+
### Basic File Deletion
2830

2931
```js
30-
// Let's assume you want to delete a file named example.txt in the /home/user/documents directory.
32+
// Delete a file from a specific directory
33+
const result = await codebolt.fs.deleteFile('example.txt', '/home/user/documents');
34+
console.log('File deleted:', result);
35+
```
36+
37+
### Delete File from Current Directory
3138

32-
codebolt.fs.deleteFile('example.txt', '/home/user/documents');
39+
```js
40+
// Delete a file from the current working directory
41+
const deleteResult = await codebolt.fs.deleteFile('fs-test-file.txt', '.');
42+
console.log('✅ File deleted:', deleteResult);
43+
```

docs/api/apiaccess/fs/deleteFolder.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,20 @@ data:
2424
<CBBaseInfo/>
2525
<CBParameters/>
2626

27-
### Example
27+
## Examples
28+
29+
### Basic Folder Deletion
2830

2931
```js
30-
// Let's assume you want to delete a folder named "exampleFolder" in the /home/user/documents directory.
32+
// Delete a folder from a specific directory
33+
const result = await codebolt.fs.deleteFolder('exampleFolder', '/home/user/documents');
34+
console.log('Folder deleted:', result);
35+
```
36+
37+
### Delete Folder from Current Directory
3138

32-
codebolt.fs.deleteFolder('exampleFolder', '/home/user/documents');
39+
```js
40+
// Delete a folder from the current working directory
41+
const deleteFolderResult = await codebolt.fs.deleteFolder('test-folder', '.');
42+
console.log('✅ Folder deleted:', deleteFolderResult);
43+
```

docs/api/apiaccess/fs/index.md

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,106 @@
22
cbapicategory:
33
- name: createFile
44
link: /docs/api/apiaccess/fs/createFile
5-
description: 'Creates a new file with the specified name and content.'
5+
description: 'Creates a new file with the specified name and content. Supports creating files with complex content including code definitions.'
66
- name: createFolder
77
link: /docs/api/apiaccess/fs/createFolder
8-
description: 'Creates a new folder at the specified location.'
8+
description: 'Creates a new folder at the specified location. Useful for organizing project structures and temporary workspaces.'
99
- name: readFile
1010
link: /docs/api/apiaccess/fs/readFile
11-
description: 'Reads the contents of a file and returns it as a string.'
11+
description: 'Reads the contents of a file and returns it as a string. Works with various file types including text, code, and configuration files.'
1212
- name: updateFile
1313
link: /docs/api/apiaccess/fs/updateFile
14-
description: 'Updates an existing file with new content.'
14+
description: 'Updates an existing file with new content. Requires separate filename and path parameters.'
15+
- name: writeToFile
16+
link: /docs/api/apiaccess/fs/writeToFile
17+
description: 'Creates or updates a file and writes data to it. Uses a single relative path parameter and overwrites existing content.'
1518
- name: deleteFile
1619
link: /docs/api/apiaccess/fs/deleteFile
17-
description: 'Deletes a specified file from the filesystem.'
20+
description: 'Deletes a specified file from the filesystem. Includes proper error handling and cleanup workflows.'
1821
- name: deleteFolder
1922
link: /docs/api/apiaccess/fs/deleteFolder
20-
description: 'Deletes a specified folder and its contents.'
23+
description: 'Deletes a specified folder and its contents. Requires the folder to be empty before deletion.'
2124
- name: listFile
2225
link: /docs/api/apiaccess/fs/listFile
23-
description: 'Lists all files in the specified directory.'
26+
description: 'Lists all files in the specified directory. Supports recursive listing and enhanced file information modes.'
2427
- name: listCodeDefinitionNames
2528
link: /docs/api/apiaccess/fs/listCodeDefinitionNames
26-
description: 'Lists all code definition names within a project.'
29+
description: 'Extracts and lists all code definition names (functions, classes, methods) from source files within a project.'
2730
- name: searchFiles
2831
link: /docs/api/apiaccess/fs/searchFiles
29-
description: 'Searches for files matching a specific pattern or criteria.'
30-
- name: writeToFile
31-
link: /docs/api/apiaccess/fs/writeToFile
32-
description: 'Creates or updates a file and writes data to it.'
32+
description: 'Searches for files matching a regex pattern within file contents. Supports advanced regex patterns and file type filtering.'
3333
---
3434

3535
# fs
36-
<CBAPICategory />
36+
37+
The `fs` module provides comprehensive file system operations for CodeboltJS. It includes methods for creating, reading, updating, and deleting files and folders, as well as advanced features like code definition extraction and content searching.
38+
39+
<CBAPICategory />
40+
41+
## Key Features
42+
43+
### File Operations
44+
- **File Creation**: Create files with simple or complex content, including code definitions
45+
- **File Reading**: Read various file types (text, code, configuration files)
46+
- **File Updates**: Two methods available - `updateFile` (separate name/path) and `writeToFile` (single path)
47+
- **File Deletion**: Safe deletion with proper error handling and cleanup workflows
48+
49+
### Folder Operations
50+
- **Folder Creation**: Create single folders or complex directory structures
51+
- **Folder Deletion**: Remove folders with proper cleanup procedures
52+
- **Directory Listing**: List files with options for recursive scanning and enhanced information
53+
54+
### Advanced Features
55+
- **Code Analysis**: Extract function names, class names, and other code definitions from source files
56+
- **Content Search**: Search within file contents using regex patterns with file type filtering
57+
- **Batch Operations**: Perform operations on multiple files or folders efficiently
58+
59+
## Common Workflows
60+
61+
### Complete File Lifecycle
62+
```js
63+
// Create → Read → Update → Delete
64+
await codebolt.fs.createFile('example.txt', 'Initial content', '.');
65+
const content = await codebolt.fs.readFile('./example.txt');
66+
await codebolt.fs.updateFile('example.txt', '.', 'Updated content');
67+
await codebolt.fs.deleteFile('example.txt', '.');
68+
```
69+
70+
### Project Structure Creation
71+
```js
72+
// Create organized project structure
73+
await codebolt.fs.createFolder('my-project', '.');
74+
await codebolt.fs.createFolder('src', './my-project');
75+
await codebolt.fs.createFolder('tests', './my-project');
76+
await codebolt.fs.createFile('index.js', 'console.log("Hello");', './my-project/src');
77+
```
78+
79+
### Code Analysis Workflow
80+
```js
81+
// Create code file and extract definitions
82+
const jsCode = `
83+
class MyClass {
84+
method() { return 'test'; }
85+
}
86+
function myFunction() { return 'hello'; }
87+
`;
88+
await codebolt.fs.createFile('code.js', jsCode, '.');
89+
const definitions = await codebolt.fs.listCodeDefinitionNames('.');
90+
```
91+
92+
## Error Handling
93+
94+
All fs methods return promises and should be used with proper error handling:
95+
96+
```js
97+
try {
98+
const result = await codebolt.fs.createFile('test.txt', 'content', '.');
99+
if (result.success) {
100+
console.log('✅ Operation successful');
101+
} else {
102+
console.log('❌ Operation failed:', result.message);
103+
}
104+
} catch (error) {
105+
console.error('Error:', error.message);
106+
}
107+
```

docs/api/apiaccess/fs/listCodeDefinitionNames.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: listCodeDefinitionNames
33
cbbaseinfo:
4-
description: 'Lists all code definition names in a given path.'
4+
description: 'Lists all code definition names in a given path. Extracts function names, class names, method names, and other code definitions from source files.'
55
cbparameters:
66
parameters:
77
- name: path
@@ -21,9 +21,32 @@ data:
2121
<CBBaseInfo/>
2222
<CBParameters/>
2323

24-
### Example
24+
## Examples
25+
26+
### Basic Code Definition Extraction
27+
28+
```js
29+
// Extract code definitions from current directory
30+
const result = await codebolt.fs.listCodeDefinitionNames('/home/user/projects');
31+
console.log('Code definitions found:', result);
32+
```
33+
34+
### Extract from Current Directory
2535

2636
```js
27-
// Let's assume you want to list all code definition names in the /home/user/projects directory.
37+
// List all code definitions in current directory
38+
const codeDefResult = await codebolt.fs.listCodeDefinitionNames('.');
39+
console.log('✅ Code definitions in current directory:', codeDefResult);
2840

29-
codebolt.fs.listCodeDefinitionNames('/home/user/projects');
41+
// Process the results
42+
if (codeDefResult.success && codeDefResult.result) {
43+
console.log('Found code definitions:');
44+
if (Array.isArray(codeDefResult.result)) {
45+
codeDefResult.result.forEach((def, index) => {
46+
console.log(`${index + 1}. ${def}`);
47+
});
48+
} else {
49+
console.log('Result:', codeDefResult.result);
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)