@soederpop/luca 0.0.6 → 0.0.8
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/CLAUDE.md +10 -1
- package/RUNME.md +56 -0
- package/bun.lock +1 -1
- package/commands/build-bootstrap.ts +78 -0
- package/commands/build-scaffolds.ts +24 -2
- package/commands/try-all-challenges.ts +543 -0
- package/commands/try-challenge.ts +100 -0
- package/docs/README.md +52 -80
- package/docs/TABLE-OF-CONTENTS.md +82 -51
- package/docs/apis/clients/elevenlabs.md +232 -8
- package/docs/apis/clients/graph.md +59 -8
- package/docs/apis/clients/openai.md +362 -2
- package/docs/apis/clients/rest.md +122 -2
- package/docs/apis/clients/websocket.md +71 -17
- package/docs/apis/features/agi/assistant.md +9 -3
- package/docs/apis/features/agi/assistants-manager.md +2 -2
- package/docs/apis/features/agi/claude-code.md +153 -14
- package/docs/apis/features/agi/conversation-history.md +15 -3
- package/docs/apis/features/agi/conversation.md +133 -20
- package/docs/apis/features/agi/openai-codex.md +90 -12
- package/docs/apis/features/agi/skills-library.md +23 -5
- package/docs/apis/features/node/container-link.md +59 -0
- package/docs/apis/features/node/content-db.md +1 -1
- package/docs/apis/features/node/disk-cache.md +1 -1
- package/docs/apis/features/node/dns.md +1 -0
- package/docs/apis/features/node/docker.md +2 -1
- package/docs/apis/features/node/esbuild.md +4 -3
- package/docs/apis/features/node/file-manager.md +13 -4
- package/docs/apis/features/node/fs.md +726 -171
- package/docs/apis/features/node/git.md +1 -0
- package/docs/apis/features/node/google-auth.md +23 -4
- package/docs/apis/features/node/google-calendar.md +14 -2
- package/docs/apis/features/node/google-docs.md +15 -2
- package/docs/apis/features/node/google-drive.md +21 -3
- package/docs/apis/features/node/google-sheets.md +14 -2
- package/docs/apis/features/node/grep.md +2 -0
- package/docs/apis/features/node/helpers.md +29 -0
- package/docs/apis/features/node/ink.md +2 -2
- package/docs/apis/features/node/networking.md +39 -4
- package/docs/apis/features/node/os.md +28 -0
- package/docs/apis/features/node/postgres.md +26 -4
- package/docs/apis/features/node/proc.md +37 -28
- package/docs/apis/features/node/process-manager.md +33 -5
- package/docs/apis/features/node/repl.md +1 -1
- package/docs/apis/features/node/runpod.md +1 -0
- package/docs/apis/features/node/secure-shell.md +7 -0
- package/docs/apis/features/node/semantic-search.md +12 -5
- package/docs/apis/features/node/sqlite.md +26 -4
- package/docs/apis/features/node/telegram.md +30 -5
- package/docs/apis/features/node/tts.md +17 -2
- package/docs/apis/features/node/ui.md +1 -1
- package/docs/apis/features/node/vault.md +4 -9
- package/docs/apis/features/node/vm.md +3 -12
- package/docs/apis/features/node/window-manager.md +128 -20
- package/docs/apis/features/web/asset-loader.md +13 -1
- package/docs/apis/features/web/container-link.md +59 -0
- package/docs/apis/features/web/esbuild.md +4 -3
- package/docs/apis/features/web/helpers.md +29 -0
- package/docs/apis/features/web/network.md +16 -2
- package/docs/apis/features/web/speech.md +16 -2
- package/docs/apis/features/web/vault.md +4 -9
- package/docs/apis/features/web/vm.md +3 -12
- package/docs/apis/features/web/voice.md +18 -1
- package/docs/apis/servers/express.md +18 -2
- package/docs/apis/servers/mcp.md +29 -4
- package/docs/apis/servers/websocket.md +34 -6
- package/docs/bootstrap/CLAUDE.md +100 -0
- package/docs/bootstrap/SKILL.md +222 -0
- package/docs/bootstrap/templates/about-command.ts +41 -0
- package/docs/bootstrap/templates/docs-models.ts +22 -0
- package/docs/bootstrap/templates/docs-readme.md +43 -0
- package/docs/bootstrap/templates/example-feature.ts +53 -0
- package/docs/bootstrap/templates/health-endpoint.ts +15 -0
- package/docs/bootstrap/templates/luca-cli.ts +25 -0
- package/docs/bootstrap/templates/runme.md +54 -0
- package/docs/challenges/caching-proxy.md +16 -0
- package/docs/challenges/content-db-round-trip.md +14 -0
- package/docs/challenges/custom-command.md +9 -0
- package/docs/challenges/file-watcher-pipeline.md +11 -0
- package/docs/challenges/grep-audit-report.md +15 -0
- package/docs/challenges/multi-feature-dashboard.md +14 -0
- package/docs/challenges/process-orchestrator.md +17 -0
- package/docs/challenges/rest-api-server-with-client.md +12 -0
- package/docs/challenges/script-runner-with-vm.md +11 -0
- package/docs/challenges/simple-rest-api.md +15 -0
- package/docs/challenges/websocket-serve-and-client.md +11 -0
- package/docs/challenges/yaml-config-system.md +14 -0
- package/docs/command-system-overhaul.md +94 -0
- package/docs/examples/assistant/CORE.md +18 -0
- package/docs/examples/assistant/hooks.ts +3 -0
- package/docs/examples/assistant/tools.ts +10 -0
- package/docs/examples/window-manager-layouts.md +180 -0
- package/docs/in-memory-fs.md +4 -0
- package/docs/models.ts +13 -10
- package/docs/philosophy.md +4 -3
- package/docs/reports/console-hmr-design.md +170 -0
- package/docs/reports/helper-semantic-search.md +72 -0
- package/docs/scaffolds/client.md +29 -20
- package/docs/scaffolds/command.md +64 -50
- package/docs/scaffolds/endpoint.md +31 -36
- package/docs/scaffolds/feature.md +28 -18
- package/docs/scaffolds/selector.md +91 -0
- package/docs/scaffolds/server.md +18 -9
- package/docs/selectors.md +115 -0
- package/docs/sessions/custom-command/attempt-log-2.md +195 -0
- package/docs/sessions/file-watcher-pipeline/attempt-log-1.md +728 -0
- package/docs/sessions/file-watcher-pipeline/attempt-log-2.md +555 -0
- package/docs/sessions/grep-audit-report/attempt-log-1.md +289 -0
- package/docs/sessions/multi-feature-dashboard/attempt-log-2.md +679 -0
- package/docs/sessions/rest-api-server-with-client/attempt-log-1.md +1 -0
- package/docs/sessions/rest-api-server-with-client/attempt-log-3.md +920 -0
- package/docs/sessions/simple-rest-api/attempt-log-1.md +593 -0
- package/docs/sessions/websocket-serve-and-client/attempt-log-2.md +995 -0
- package/docs/tutorials/00-bootstrap.md +148 -0
- package/docs/tutorials/07-endpoints.md +7 -7
- package/docs/tutorials/08-commands.md +153 -72
- package/luca.cli.ts +3 -0
- package/package.json +6 -5
- package/public/index.html +1430 -0
- package/scripts/examples/using-ollama.ts +2 -1
- package/scripts/update-introspection-data.ts +2 -2
- package/src/agi/endpoints/experts.ts +1 -1
- package/src/agi/features/assistant.ts +7 -0
- package/src/agi/features/assistants-manager.ts +5 -5
- package/src/agi/features/claude-code.ts +263 -3
- package/src/agi/features/conversation-history.ts +7 -1
- package/src/agi/features/conversation.ts +26 -3
- package/src/agi/features/openai-codex.ts +26 -2
- package/src/agi/features/openapi.ts +6 -1
- package/src/agi/features/skills-library.ts +9 -1
- package/src/bootstrap/generated.ts +595 -0
- package/src/cli/cli.ts +64 -21
- package/src/client.ts +23 -357
- package/src/clients/civitai/index.ts +1 -1
- package/src/clients/client-template.ts +1 -1
- package/src/clients/comfyui/index.ts +13 -2
- package/src/clients/elevenlabs/index.ts +2 -1
- package/src/clients/graph.ts +87 -0
- package/src/clients/openai/index.ts +10 -1
- package/src/clients/rest.ts +207 -0
- package/src/clients/websocket.ts +176 -0
- package/src/command.ts +281 -34
- package/src/commands/bootstrap.ts +185 -0
- package/src/commands/chat.ts +5 -4
- package/src/commands/describe.ts +341 -4
- package/src/commands/help.ts +35 -9
- package/src/commands/index.ts +3 -0
- package/src/commands/introspect.ts +92 -2
- package/src/commands/prompt.ts +5 -6
- package/src/commands/run.ts +75 -10
- package/src/commands/save-api-docs.ts +49 -0
- package/src/commands/scaffold.ts +169 -23
- package/src/commands/select.ts +94 -0
- package/src/commands/serve.ts +10 -1
- package/src/container.ts +15 -0
- package/src/endpoint.ts +19 -0
- package/src/graft.ts +181 -0
- package/src/introspection/generated.agi.ts +12458 -8968
- package/src/introspection/generated.node.ts +10573 -7145
- package/src/introspection/generated.web.ts +1 -1
- package/src/introspection/index.ts +26 -0
- package/src/node/container.ts +6 -7
- package/src/node/features/content-db.ts +49 -2
- package/src/node/features/disk-cache.ts +16 -9
- package/src/node/features/dns.ts +16 -3
- package/src/node/features/docker.ts +16 -4
- package/src/node/features/esbuild.ts +22 -2
- package/src/node/features/file-manager.ts +184 -29
- package/src/node/features/fs.ts +704 -248
- package/src/node/features/git.ts +21 -8
- package/src/node/features/grep.ts +23 -3
- package/src/node/features/helpers.ts +372 -43
- package/src/node/features/networking.ts +39 -4
- package/src/node/features/opener.ts +28 -15
- package/src/node/features/os.ts +76 -0
- package/src/node/features/port-exposer.ts +11 -1
- package/src/node/features/postgres.ts +17 -1
- package/src/node/features/proc.ts +4 -1
- package/src/node/features/python.ts +63 -14
- package/src/node/features/repl.ts +11 -7
- package/src/node/features/runpod.ts +16 -3
- package/src/node/features/secure-shell.ts +27 -2
- package/src/node/features/semantic-search.ts +12 -1
- package/src/node/features/ui.ts +5 -69
- package/src/node/features/vm.ts +17 -0
- package/src/node/features/window-manager.ts +68 -20
- package/src/node.ts +5 -0
- package/src/scaffolds/generated.ts +492 -290
- package/src/scaffolds/template.ts +9 -0
- package/src/schemas/base.ts +46 -5
- package/src/selector.ts +282 -0
- package/src/server.ts +11 -0
- package/src/servers/express.ts +27 -12
- package/src/servers/socket.ts +45 -11
- package/src/web/clients/socket.ts +4 -1
- package/src/web/container.ts +2 -1
- package/src/web/features/network.ts +7 -1
- package/src/web/features/voice-recognition.ts +16 -1
- package/test/clients-servers.test.ts +2 -1
- package/test/command.test.ts +267 -0
- package/test/vm-context.test.ts +146 -0
- package/test-integration/assistants-manager.test.ts +10 -20
- package/docs/apis/features/node/launcher-app-command-listener.md +0 -145
- package/docs/examples/launcher-app-command-listener.md +0 -120
- package/docs/tasks/web-container-helper-discovery.md +0 -71
- package/docs/todos.md +0 -1
- package/scripts/test-command-listener.ts +0 -123
- package/src/node/features/launcher-app-command-listener.ts +0 -389
|
@@ -10,121 +10,138 @@ container.feature('fs')
|
|
|
10
10
|
|
|
11
11
|
## Methods
|
|
12
12
|
|
|
13
|
-
###
|
|
13
|
+
### readFile
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Synchronously reads a file and returns its contents as a string.
|
|
16
16
|
|
|
17
17
|
**Parameters:**
|
|
18
18
|
|
|
19
19
|
| Name | Type | Required | Description |
|
|
20
20
|
|------|------|----------|-------------|
|
|
21
21
|
| `path` | `string` | ✓ | The file path relative to the container's working directory |
|
|
22
|
+
| `encoding` | `BufferEncoding | null` | | The encoding to use. Pass null to get a raw Buffer. |
|
|
22
23
|
|
|
23
|
-
**Returns:** `
|
|
24
|
+
**Returns:** `string | Buffer`
|
|
24
25
|
|
|
25
26
|
```ts
|
|
26
|
-
const
|
|
27
|
-
const buffer =
|
|
28
|
-
console.log(buffer.toString())
|
|
27
|
+
const content = fs.readFile('README.md')
|
|
28
|
+
const buffer = fs.readFile('image.png', null)
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
###
|
|
33
|
+
### readFileAsync
|
|
34
34
|
|
|
35
|
-
Asynchronously reads
|
|
35
|
+
Asynchronously reads a file and returns its contents as a string.
|
|
36
36
|
|
|
37
37
|
**Parameters:**
|
|
38
38
|
|
|
39
39
|
| Name | Type | Required | Description |
|
|
40
40
|
|------|------|----------|-------------|
|
|
41
|
-
| `path` | `string` | ✓ | The
|
|
41
|
+
| `path` | `string` | ✓ | The file path relative to the container's working directory |
|
|
42
|
+
| `encoding` | `BufferEncoding | null` | | The encoding to use. Pass null to get a raw Buffer. |
|
|
42
43
|
|
|
43
|
-
**Returns:** `
|
|
44
|
+
**Returns:** `Promise<string | Buffer>`
|
|
44
45
|
|
|
45
46
|
```ts
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
console.log(entries) // ['index.ts', 'utils.ts', 'components']
|
|
47
|
+
const content = await fs.readFileAsync('data.txt')
|
|
48
|
+
const buffer = await fs.readFileAsync('image.png', null)
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
###
|
|
53
|
+
### readJson
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Synchronously reads and parses a JSON file.
|
|
56
56
|
|
|
57
57
|
**Parameters:**
|
|
58
58
|
|
|
59
59
|
| Name | Type | Required | Description |
|
|
60
60
|
|------|------|----------|-------------|
|
|
61
|
-
| `
|
|
62
|
-
| `options` | `WalkOptions` | | Options to configure the walk behavior |
|
|
61
|
+
| `path` | `string` | ✓ | The path to the JSON file |
|
|
63
62
|
|
|
64
|
-
`
|
|
63
|
+
**Returns:** `void`
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const config = fs.readJson('config.json')
|
|
67
|
+
console.log(config.version)
|
|
68
|
+
```
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
### readJsonAsync
|
|
73
|
+
|
|
74
|
+
Asynchronously reads and parses a JSON file.
|
|
75
|
+
|
|
76
|
+
**Parameters:**
|
|
77
|
+
|
|
78
|
+
| Name | Type | Required | Description |
|
|
79
|
+
|------|------|----------|-------------|
|
|
80
|
+
| `path` | `string` | ✓ | The path to the JSON file |
|
|
72
81
|
|
|
73
82
|
**Returns:** `void`
|
|
74
83
|
|
|
75
84
|
```ts
|
|
76
|
-
const
|
|
77
|
-
console.log(
|
|
85
|
+
const config = await fs.readJsonAsync('config.json')
|
|
86
|
+
console.log(config.version)
|
|
78
87
|
```
|
|
79
88
|
|
|
80
89
|
|
|
81
90
|
|
|
82
|
-
###
|
|
91
|
+
### readdirSync
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
Synchronously reads the contents of a directory.
|
|
85
94
|
|
|
86
95
|
**Parameters:**
|
|
87
96
|
|
|
88
97
|
| Name | Type | Required | Description |
|
|
89
98
|
|------|------|----------|-------------|
|
|
90
|
-
| `
|
|
91
|
-
| `options` | `WalkOptions` | | Options to configure the walk behavior |
|
|
99
|
+
| `path` | `string` | ✓ | The directory path relative to the container's working directory |
|
|
92
100
|
|
|
93
|
-
`
|
|
101
|
+
**Returns:** `void`
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
```ts
|
|
104
|
+
const entries = fs.readdirSync('src')
|
|
105
|
+
console.log(entries) // ['index.ts', 'utils.ts', 'components']
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### readdir
|
|
111
|
+
|
|
112
|
+
Asynchronously reads the contents of a directory.
|
|
113
|
+
|
|
114
|
+
**Parameters:**
|
|
115
|
+
|
|
116
|
+
| Name | Type | Required | Description |
|
|
117
|
+
|------|------|----------|-------------|
|
|
118
|
+
| `path` | `string` | ✓ | The directory path relative to the container's working directory |
|
|
101
119
|
|
|
102
120
|
**Returns:** `void`
|
|
103
121
|
|
|
104
122
|
```ts
|
|
105
|
-
const
|
|
106
|
-
console.log(
|
|
123
|
+
const entries = await fs.readdir('src')
|
|
124
|
+
console.log(entries) // ['index.ts', 'utils.ts', 'components']
|
|
107
125
|
```
|
|
108
126
|
|
|
109
127
|
|
|
110
128
|
|
|
111
|
-
###
|
|
129
|
+
### writeFile
|
|
112
130
|
|
|
113
|
-
|
|
131
|
+
Synchronously writes content to a file.
|
|
114
132
|
|
|
115
133
|
**Parameters:**
|
|
116
134
|
|
|
117
135
|
| Name | Type | Required | Description |
|
|
118
136
|
|------|------|----------|-------------|
|
|
119
|
-
| `path` | `string` | ✓ | The file path where
|
|
120
|
-
| `content` | `string` | ✓ | The content to write to the file |
|
|
121
|
-
| `overwrite` | `any` | | Whether to overwrite the file if it already exists |
|
|
137
|
+
| `path` | `string` | ✓ | The file path where content should be written |
|
|
138
|
+
| `content` | `Buffer | string` | ✓ | The content to write to the file |
|
|
122
139
|
|
|
123
140
|
**Returns:** `void`
|
|
124
141
|
|
|
125
142
|
```ts
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
fs.writeFile('output.txt', 'Hello World')
|
|
144
|
+
fs.writeFile('data.bin', Buffer.from([1, 2, 3, 4]))
|
|
128
145
|
```
|
|
129
146
|
|
|
130
147
|
|
|
@@ -149,6 +166,46 @@ await fs.writeFileAsync('data.bin', Buffer.from([1, 2, 3, 4]))
|
|
|
149
166
|
|
|
150
167
|
|
|
151
168
|
|
|
169
|
+
### writeJson
|
|
170
|
+
|
|
171
|
+
Synchronously writes an object to a file as JSON.
|
|
172
|
+
|
|
173
|
+
**Parameters:**
|
|
174
|
+
|
|
175
|
+
| Name | Type | Required | Description |
|
|
176
|
+
|------|------|----------|-------------|
|
|
177
|
+
| `path` | `string` | ✓ | The file path where the JSON should be written |
|
|
178
|
+
| `data` | `any` | ✓ | The data to serialize as JSON |
|
|
179
|
+
| `indent` | `number` | | The number of spaces to use for indentation |
|
|
180
|
+
|
|
181
|
+
**Returns:** `void`
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
fs.writeJson('config.json', { version: '1.0.0', debug: false })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
### writeJsonAsync
|
|
190
|
+
|
|
191
|
+
Asynchronously writes an object to a file as JSON.
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
|
|
195
|
+
| Name | Type | Required | Description |
|
|
196
|
+
|------|------|----------|-------------|
|
|
197
|
+
| `path` | `string` | ✓ | The file path where the JSON should be written |
|
|
198
|
+
| `data` | `any` | ✓ | The data to serialize as JSON |
|
|
199
|
+
| `indent` | `number` | | The number of spaces to use for indentation |
|
|
200
|
+
|
|
201
|
+
**Returns:** `void`
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
await fs.writeJsonAsync('config.json', { version: '1.0.0', debug: false })
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
152
209
|
### appendFile
|
|
153
210
|
|
|
154
211
|
Synchronously appends content to a file.
|
|
@@ -187,102 +244,96 @@ await fs.appendFileAsync('log.txt', 'New line\n')
|
|
|
187
244
|
|
|
188
245
|
|
|
189
246
|
|
|
190
|
-
###
|
|
247
|
+
### ensureFile
|
|
191
248
|
|
|
192
|
-
Synchronously ensures a
|
|
249
|
+
Synchronously ensures a file exists with the specified content, creating directories as needed.
|
|
193
250
|
|
|
194
251
|
**Parameters:**
|
|
195
252
|
|
|
196
253
|
| Name | Type | Required | Description |
|
|
197
254
|
|------|------|----------|-------------|
|
|
198
|
-
| `path` | `string` | ✓ | The
|
|
255
|
+
| `path` | `string` | ✓ | The file path where the file should be created |
|
|
256
|
+
| `content` | `string` | ✓ | The content to write to the file |
|
|
257
|
+
| `overwrite` | `any` | | Whether to overwrite the file if it already exists |
|
|
199
258
|
|
|
200
259
|
**Returns:** `void`
|
|
201
260
|
|
|
202
261
|
```ts
|
|
203
|
-
fs.
|
|
204
|
-
// Creates logs and logs/debug directories if they don't exist
|
|
262
|
+
fs.ensureFile('logs/app.log', '', false)
|
|
205
263
|
```
|
|
206
264
|
|
|
207
265
|
|
|
208
266
|
|
|
209
|
-
###
|
|
267
|
+
### ensureFileAsync
|
|
268
|
+
|
|
269
|
+
Asynchronously ensures a file exists with the specified content, creating directories as needed.
|
|
210
270
|
|
|
211
271
|
**Parameters:**
|
|
212
272
|
|
|
213
273
|
| Name | Type | Required | Description |
|
|
214
274
|
|------|------|----------|-------------|
|
|
215
|
-
| `
|
|
275
|
+
| `path` | `string` | ✓ | The file path where the file should be created |
|
|
276
|
+
| `content` | `string` | ✓ | The content to write to the file |
|
|
277
|
+
| `overwrite` | `any` | | Whether to overwrite the file if it already exists |
|
|
216
278
|
|
|
217
279
|
**Returns:** `void`
|
|
218
280
|
|
|
281
|
+
```ts
|
|
282
|
+
await fs.ensureFileAsync('config/settings.json', '{}', true)
|
|
283
|
+
```
|
|
219
284
|
|
|
220
285
|
|
|
221
|
-
### ensureFile
|
|
222
286
|
|
|
223
|
-
|
|
287
|
+
### ensureFolder
|
|
288
|
+
|
|
289
|
+
Synchronously ensures a directory exists, creating parent directories as needed.
|
|
224
290
|
|
|
225
291
|
**Parameters:**
|
|
226
292
|
|
|
227
293
|
| Name | Type | Required | Description |
|
|
228
294
|
|------|------|----------|-------------|
|
|
229
|
-
| `path` | `string` | ✓ | The
|
|
230
|
-
| `content` | `string` | ✓ | The content to write to the file |
|
|
231
|
-
| `overwrite` | `any` | | Whether to overwrite the file if it already exists |
|
|
295
|
+
| `path` | `string` | ✓ | The directory path to create |
|
|
232
296
|
|
|
233
297
|
**Returns:** `void`
|
|
234
298
|
|
|
235
299
|
```ts
|
|
236
|
-
fs.
|
|
237
|
-
// Creates logs directory and app.log file if they don't exist
|
|
300
|
+
fs.ensureFolder('logs/debug')
|
|
238
301
|
```
|
|
239
302
|
|
|
240
303
|
|
|
241
304
|
|
|
242
|
-
###
|
|
305
|
+
### ensureFolderAsync
|
|
243
306
|
|
|
244
|
-
|
|
307
|
+
Asynchronously ensures a directory exists, creating parent directories as needed.
|
|
245
308
|
|
|
246
309
|
**Parameters:**
|
|
247
310
|
|
|
248
311
|
| Name | Type | Required | Description |
|
|
249
312
|
|------|------|----------|-------------|
|
|
250
|
-
| `
|
|
251
|
-
| `options` | `{ cwd?: string }` | | Options for the search |
|
|
252
|
-
|
|
253
|
-
`{ cwd?: string }` properties:
|
|
254
|
-
|
|
255
|
-
| Property | Type | Description |
|
|
256
|
-
|----------|------|-------------|
|
|
257
|
-
| `cwd` | `any` | The directory to start searching from (defaults to container.cwd) |
|
|
313
|
+
| `path` | `string` | ✓ | The directory path to create |
|
|
258
314
|
|
|
259
|
-
**Returns:** `
|
|
315
|
+
**Returns:** `void`
|
|
260
316
|
|
|
261
317
|
```ts
|
|
262
|
-
|
|
263
|
-
if (packageJson) {
|
|
264
|
-
console.log(`Found package.json at: ${packageJson}`)
|
|
265
|
-
}
|
|
318
|
+
await fs.ensureFolderAsync('logs/debug')
|
|
266
319
|
```
|
|
267
320
|
|
|
268
321
|
|
|
269
322
|
|
|
270
|
-
###
|
|
323
|
+
### mkdirp
|
|
271
324
|
|
|
272
|
-
|
|
325
|
+
Alias for ensureFolder. Synchronously creates a directory and all parent directories.
|
|
273
326
|
|
|
274
327
|
**Parameters:**
|
|
275
328
|
|
|
276
329
|
| Name | Type | Required | Description |
|
|
277
330
|
|------|------|----------|-------------|
|
|
278
|
-
| `
|
|
331
|
+
| `folder` | `string` | ✓ | The directory path to create |
|
|
279
332
|
|
|
280
333
|
**Returns:** `void`
|
|
281
334
|
|
|
282
335
|
```ts
|
|
283
|
-
|
|
284
|
-
console.log('Config file exists!')
|
|
285
|
-
}
|
|
336
|
+
fs.mkdirp('deep/nested/path')
|
|
286
337
|
```
|
|
287
338
|
|
|
288
339
|
|
|
@@ -309,185 +360,530 @@ if (fs.exists('config.json')) {
|
|
|
309
360
|
|
|
310
361
|
### existsSync
|
|
311
362
|
|
|
363
|
+
Alias for exists. Synchronously checks if a file or directory exists.
|
|
364
|
+
|
|
312
365
|
**Parameters:**
|
|
313
366
|
|
|
314
367
|
| Name | Type | Required | Description |
|
|
315
368
|
|------|------|----------|-------------|
|
|
316
|
-
| `path` | `string` | ✓ |
|
|
369
|
+
| `path` | `string` | ✓ | The path to check for existence |
|
|
317
370
|
|
|
318
371
|
**Returns:** `boolean`
|
|
319
372
|
|
|
373
|
+
```ts
|
|
374
|
+
if (fs.existsSync('config.json')) {
|
|
375
|
+
console.log('Config file exists!')
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
320
379
|
|
|
321
380
|
|
|
322
|
-
###
|
|
381
|
+
### existsAsync
|
|
323
382
|
|
|
324
|
-
Asynchronously
|
|
383
|
+
Asynchronously checks if a file or directory exists.
|
|
325
384
|
|
|
326
385
|
**Parameters:**
|
|
327
386
|
|
|
328
387
|
| Name | Type | Required | Description |
|
|
329
388
|
|------|------|----------|-------------|
|
|
330
|
-
| `path` | `string` | ✓ | The path
|
|
389
|
+
| `path` | `string` | ✓ | The path to check for existence |
|
|
331
390
|
|
|
332
391
|
**Returns:** `void`
|
|
333
392
|
|
|
334
393
|
```ts
|
|
335
|
-
await fs.
|
|
394
|
+
if (await fs.existsAsync('config.json')) {
|
|
395
|
+
console.log('Config file exists!')
|
|
396
|
+
}
|
|
336
397
|
```
|
|
337
398
|
|
|
338
399
|
|
|
339
400
|
|
|
340
|
-
###
|
|
401
|
+
### stat
|
|
341
402
|
|
|
342
|
-
Synchronously
|
|
403
|
+
Synchronously returns the stat object for a file or directory.
|
|
343
404
|
|
|
344
405
|
**Parameters:**
|
|
345
406
|
|
|
346
407
|
| Name | Type | Required | Description |
|
|
347
408
|
|------|------|----------|-------------|
|
|
348
|
-
| `path` | `string` | ✓ | The path to
|
|
409
|
+
| `path` | `string` | ✓ | The path to stat |
|
|
349
410
|
|
|
350
411
|
**Returns:** `void`
|
|
351
412
|
|
|
352
413
|
```ts
|
|
353
|
-
const
|
|
354
|
-
console.log(
|
|
414
|
+
const info = fs.stat('package.json')
|
|
415
|
+
console.log(info.size, info.mtime)
|
|
355
416
|
```
|
|
356
417
|
|
|
357
418
|
|
|
358
419
|
|
|
359
|
-
###
|
|
420
|
+
### statAsync
|
|
360
421
|
|
|
361
|
-
|
|
422
|
+
Asynchronously returns the stat object for a file or directory.
|
|
362
423
|
|
|
363
424
|
**Parameters:**
|
|
364
425
|
|
|
365
426
|
| Name | Type | Required | Description |
|
|
366
427
|
|------|------|----------|-------------|
|
|
367
|
-
| `path` | `string` | ✓ | The path to
|
|
428
|
+
| `path` | `string` | ✓ | The path to stat |
|
|
368
429
|
|
|
369
430
|
**Returns:** `void`
|
|
370
431
|
|
|
371
432
|
```ts
|
|
372
|
-
const
|
|
373
|
-
console.log(
|
|
433
|
+
const info = await fs.statAsync('package.json')
|
|
434
|
+
console.log(info.size, info.mtime)
|
|
374
435
|
```
|
|
375
436
|
|
|
376
437
|
|
|
377
438
|
|
|
378
|
-
###
|
|
439
|
+
### isFile
|
|
379
440
|
|
|
380
|
-
|
|
441
|
+
Synchronously checks if a path is a file.
|
|
381
442
|
|
|
382
443
|
**Parameters:**
|
|
383
444
|
|
|
384
445
|
| Name | Type | Required | Description |
|
|
385
446
|
|------|------|----------|-------------|
|
|
386
|
-
| `
|
|
447
|
+
| `path` | `string` | ✓ | The path to check |
|
|
387
448
|
|
|
388
|
-
**Returns:** `
|
|
449
|
+
**Returns:** `boolean`
|
|
389
450
|
|
|
390
451
|
```ts
|
|
391
|
-
|
|
392
|
-
|
|
452
|
+
if (fs.isFile('package.json')) {
|
|
453
|
+
console.log('It is a file')
|
|
454
|
+
}
|
|
393
455
|
```
|
|
394
456
|
|
|
395
457
|
|
|
396
458
|
|
|
397
|
-
###
|
|
459
|
+
### isFileAsync
|
|
398
460
|
|
|
399
|
-
Asynchronously
|
|
461
|
+
Asynchronously checks if a path is a file.
|
|
400
462
|
|
|
401
463
|
**Parameters:**
|
|
402
464
|
|
|
403
465
|
| Name | Type | Required | Description |
|
|
404
466
|
|------|------|----------|-------------|
|
|
405
|
-
| `
|
|
406
|
-
| `options` | `{ cwd?: string; multiple?: boolean }` | | Options for the search |
|
|
407
|
-
|
|
408
|
-
`{ cwd?: string; multiple?: boolean }` properties:
|
|
467
|
+
| `path` | `string` | ✓ | The path to check |
|
|
409
468
|
|
|
410
|
-
|
|
411
|
-
|----------|------|-------------|
|
|
412
|
-
| `cwd` | `any` | The directory to start searching from (defaults to container.cwd) |
|
|
413
|
-
| `multiple` | `any` | Whether to find multiple instances of the file |
|
|
414
|
-
|
|
415
|
-
**Returns:** `Promise<string | string[] | null>`
|
|
469
|
+
**Returns:** `Promise<boolean>`
|
|
416
470
|
|
|
417
471
|
```ts
|
|
418
|
-
|
|
419
|
-
|
|
472
|
+
if (await fs.isFileAsync('package.json')) {
|
|
473
|
+
console.log('It is a file')
|
|
474
|
+
}
|
|
420
475
|
```
|
|
421
476
|
|
|
422
477
|
|
|
423
478
|
|
|
424
|
-
|
|
479
|
+
### isDirectory
|
|
425
480
|
|
|
426
|
-
|
|
427
|
-
|----------|------|-------------|
|
|
428
|
-
| `enabled` | `boolean` | Whether this feature is currently enabled |
|
|
481
|
+
Synchronously checks if a path is a directory.
|
|
429
482
|
|
|
430
|
-
|
|
483
|
+
**Parameters:**
|
|
431
484
|
|
|
432
|
-
|
|
485
|
+
| Name | Type | Required | Description |
|
|
486
|
+
|------|------|----------|-------------|
|
|
487
|
+
| `path` | `string` | ✓ | The path to check |
|
|
488
|
+
|
|
489
|
+
**Returns:** `boolean`
|
|
433
490
|
|
|
434
491
|
```ts
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
await fs.ensureFileAsync('output/result.json', '{}')
|
|
492
|
+
if (fs.isDirectory('src')) {
|
|
493
|
+
console.log('It is a directory')
|
|
494
|
+
}
|
|
439
495
|
```
|
|
440
496
|
|
|
441
497
|
|
|
442
498
|
|
|
443
|
-
|
|
499
|
+
### isDirectoryAsync
|
|
444
500
|
|
|
445
|
-
|
|
446
|
-
const fs = container.feature('fs')
|
|
447
|
-
const buffer = await fs.readFileAsync('data.txt')
|
|
448
|
-
console.log(buffer.toString())
|
|
449
|
-
```
|
|
501
|
+
Asynchronously checks if a path is a directory.
|
|
450
502
|
|
|
503
|
+
**Parameters:**
|
|
451
504
|
|
|
505
|
+
| Name | Type | Required | Description |
|
|
506
|
+
|------|------|----------|-------------|
|
|
507
|
+
| `path` | `string` | ✓ | The path to check |
|
|
452
508
|
|
|
453
|
-
**
|
|
509
|
+
**Returns:** `Promise<boolean>`
|
|
454
510
|
|
|
455
511
|
```ts
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
512
|
+
if (await fs.isDirectoryAsync('src')) {
|
|
513
|
+
console.log('It is a directory')
|
|
514
|
+
}
|
|
459
515
|
```
|
|
460
516
|
|
|
461
517
|
|
|
462
518
|
|
|
463
|
-
|
|
519
|
+
### rmSync
|
|
464
520
|
|
|
465
|
-
|
|
466
|
-
const result = fs.walk('src', { files: true, directories: false })
|
|
467
|
-
console.log(result.files) // ['src/index.ts', 'src/utils.ts', 'src/components/Button.tsx']
|
|
468
|
-
```
|
|
521
|
+
Synchronously removes a file.
|
|
469
522
|
|
|
523
|
+
**Parameters:**
|
|
470
524
|
|
|
525
|
+
| Name | Type | Required | Description |
|
|
526
|
+
|------|------|----------|-------------|
|
|
527
|
+
| `path` | `string` | ✓ | The path of the file to remove |
|
|
471
528
|
|
|
472
|
-
**
|
|
529
|
+
**Returns:** `void`
|
|
473
530
|
|
|
474
531
|
```ts
|
|
475
|
-
|
|
476
|
-
console.log(`Found ${result.files.length} files and ${result.directories.length} directories`)
|
|
532
|
+
fs.rmSync('temp/cache.tmp')
|
|
477
533
|
```
|
|
478
534
|
|
|
479
535
|
|
|
480
536
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
```ts
|
|
484
|
-
await fs.ensureFileAsync('config/settings.json', '{}', true)
|
|
485
|
-
// Creates config directory and settings.json file with '{}' content
|
|
486
|
-
```
|
|
537
|
+
### rm
|
|
487
538
|
|
|
539
|
+
Asynchronously removes a file.
|
|
488
540
|
|
|
541
|
+
**Parameters:**
|
|
489
542
|
|
|
490
|
-
|
|
543
|
+
| Name | Type | Required | Description |
|
|
544
|
+
|------|------|----------|-------------|
|
|
545
|
+
| `path` | `string` | ✓ | The path of the file to remove |
|
|
546
|
+
|
|
547
|
+
**Returns:** `void`
|
|
548
|
+
|
|
549
|
+
```ts
|
|
550
|
+
await fs.rm('temp/cache.tmp')
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
### rmdirSync
|
|
556
|
+
|
|
557
|
+
Synchronously removes a directory and all its contents.
|
|
558
|
+
|
|
559
|
+
**Parameters:**
|
|
560
|
+
|
|
561
|
+
| Name | Type | Required | Description |
|
|
562
|
+
|------|------|----------|-------------|
|
|
563
|
+
| `dirPath` | `string` | ✓ | The path of the directory to remove |
|
|
564
|
+
|
|
565
|
+
**Returns:** `void`
|
|
566
|
+
|
|
567
|
+
```ts
|
|
568
|
+
fs.rmdirSync('temp/cache')
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
### rmdir
|
|
574
|
+
|
|
575
|
+
Asynchronously removes a directory and all its contents.
|
|
576
|
+
|
|
577
|
+
**Parameters:**
|
|
578
|
+
|
|
579
|
+
| Name | Type | Required | Description |
|
|
580
|
+
|------|------|----------|-------------|
|
|
581
|
+
| `dirPath` | `string` | ✓ | The path of the directory to remove |
|
|
582
|
+
|
|
583
|
+
**Returns:** `void`
|
|
584
|
+
|
|
585
|
+
```ts
|
|
586
|
+
await fs.rmdir('temp/cache')
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
### copy
|
|
592
|
+
|
|
593
|
+
Synchronously copies a file or directory. Auto-detects whether the source is a file or directory and handles each appropriately (recursive for directories).
|
|
594
|
+
|
|
595
|
+
**Parameters:**
|
|
596
|
+
|
|
597
|
+
| Name | Type | Required | Description |
|
|
598
|
+
|------|------|----------|-------------|
|
|
599
|
+
| `src` | `string` | ✓ | The source path to copy from |
|
|
600
|
+
| `dest` | `string` | ✓ | The destination path to copy to |
|
|
601
|
+
| `options` | `{ overwrite?: boolean }` | | Copy options |
|
|
602
|
+
|
|
603
|
+
`{ overwrite?: boolean }` properties:
|
|
604
|
+
|
|
605
|
+
| Property | Type | Description |
|
|
606
|
+
|----------|------|-------------|
|
|
607
|
+
| `overwrite` | `any` | Whether to overwrite existing files at the destination |
|
|
608
|
+
|
|
609
|
+
**Returns:** `void`
|
|
610
|
+
|
|
611
|
+
```ts
|
|
612
|
+
fs.copy('src/config.json', 'backup/config.json')
|
|
613
|
+
fs.copy('src', 'backup/src')
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
### copyAsync
|
|
619
|
+
|
|
620
|
+
Asynchronously copies a file or directory. Auto-detects whether the source is a file or directory and handles each appropriately (recursive for directories).
|
|
621
|
+
|
|
622
|
+
**Parameters:**
|
|
623
|
+
|
|
624
|
+
| Name | Type | Required | Description |
|
|
625
|
+
|------|------|----------|-------------|
|
|
626
|
+
| `src` | `string` | ✓ | The source path to copy from |
|
|
627
|
+
| `dest` | `string` | ✓ | The destination path to copy to |
|
|
628
|
+
| `options` | `{ overwrite?: boolean }` | | Copy options |
|
|
629
|
+
|
|
630
|
+
`{ overwrite?: boolean }` properties:
|
|
631
|
+
|
|
632
|
+
| Property | Type | Description |
|
|
633
|
+
|----------|------|-------------|
|
|
634
|
+
| `overwrite` | `any` | Whether to overwrite existing files at the destination |
|
|
635
|
+
|
|
636
|
+
**Returns:** `void`
|
|
637
|
+
|
|
638
|
+
```ts
|
|
639
|
+
await fs.copyAsync('src/config.json', 'backup/config.json')
|
|
640
|
+
await fs.copyAsync('src', 'backup/src')
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
### move
|
|
646
|
+
|
|
647
|
+
Synchronously moves (renames) a file or directory. Falls back to copy + delete for cross-device moves.
|
|
648
|
+
|
|
649
|
+
**Parameters:**
|
|
650
|
+
|
|
651
|
+
| Name | Type | Required | Description |
|
|
652
|
+
|------|------|----------|-------------|
|
|
653
|
+
| `src` | `string` | ✓ | The source path to move from |
|
|
654
|
+
| `dest` | `string` | ✓ | The destination path to move to |
|
|
655
|
+
|
|
656
|
+
**Returns:** `void`
|
|
657
|
+
|
|
658
|
+
```ts
|
|
659
|
+
fs.move('temp/draft.txt', 'final/document.txt')
|
|
660
|
+
fs.move('old-dir', 'new-dir')
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
### moveAsync
|
|
666
|
+
|
|
667
|
+
Asynchronously moves (renames) a file or directory. Falls back to copy + delete for cross-device moves.
|
|
668
|
+
|
|
669
|
+
**Parameters:**
|
|
670
|
+
|
|
671
|
+
| Name | Type | Required | Description |
|
|
672
|
+
|------|------|----------|-------------|
|
|
673
|
+
| `src` | `string` | ✓ | The source path to move from |
|
|
674
|
+
| `dest` | `string` | ✓ | The destination path to move to |
|
|
675
|
+
|
|
676
|
+
**Returns:** `void`
|
|
677
|
+
|
|
678
|
+
```ts
|
|
679
|
+
await fs.moveAsync('temp/draft.txt', 'final/document.txt')
|
|
680
|
+
await fs.moveAsync('old-dir', 'new-dir')
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
### walk
|
|
686
|
+
|
|
687
|
+
Recursively walks a directory and returns arrays of file and directory paths. By default paths are absolute. Pass `relative: true` to get paths relative to `basePath`. Supports filtering with exclude and include glob patterns.
|
|
688
|
+
|
|
689
|
+
**Parameters:**
|
|
690
|
+
|
|
691
|
+
| Name | Type | Required | Description |
|
|
692
|
+
|------|------|----------|-------------|
|
|
693
|
+
| `basePath` | `string` | ✓ | The base directory path to start walking from |
|
|
694
|
+
| `options` | `WalkOptions` | | Options to configure the walk behavior |
|
|
695
|
+
|
|
696
|
+
`WalkOptions` properties:
|
|
697
|
+
|
|
698
|
+
| Property | Type | Description |
|
|
699
|
+
|----------|------|-------------|
|
|
700
|
+
| `directories` | `boolean` | Whether to include directories in results |
|
|
701
|
+
| `files` | `boolean` | Whether to include files in results |
|
|
702
|
+
| `exclude` | `string | string[]` | ] - Glob patterns to exclude (e.g. 'node_modules', '*.log') |
|
|
703
|
+
| `include` | `string | string[]` | ] - Glob patterns to include (only matching paths are returned) |
|
|
704
|
+
| `relative` | `boolean` | When true, returned paths are relative to `baseDir` instead of absolute. |
|
|
705
|
+
|
|
706
|
+
**Returns:** `void`
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
const result = fs.walk('src', { files: true, directories: false })
|
|
710
|
+
const filtered = fs.walk('.', { exclude: ['node_modules', '.git'], include: ['*.ts'] })
|
|
711
|
+
const relative = fs.walk('inbox', { relative: true }) // => { files: ['contact-1.json', ...] }
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
### walkAsync
|
|
717
|
+
|
|
718
|
+
Asynchronously and recursively walks a directory and returns arrays of file and directory paths. By default paths are absolute. Pass `relative: true` to get paths relative to `baseDir`. Supports filtering with exclude and include glob patterns.
|
|
719
|
+
|
|
720
|
+
**Parameters:**
|
|
721
|
+
|
|
722
|
+
| Name | Type | Required | Description |
|
|
723
|
+
|------|------|----------|-------------|
|
|
724
|
+
| `baseDir` | `string` | ✓ | The base directory path to start walking from |
|
|
725
|
+
| `options` | `WalkOptions` | | Options to configure the walk behavior |
|
|
726
|
+
|
|
727
|
+
`WalkOptions` properties:
|
|
728
|
+
|
|
729
|
+
| Property | Type | Description |
|
|
730
|
+
|----------|------|-------------|
|
|
731
|
+
| `directories` | `boolean` | Whether to include directories in results |
|
|
732
|
+
| `files` | `boolean` | Whether to include files in results |
|
|
733
|
+
| `exclude` | `string | string[]` | ] - Glob patterns to exclude (e.g. 'node_modules', '.git') |
|
|
734
|
+
| `include` | `string | string[]` | ] - Glob patterns to include (only matching paths are returned) |
|
|
735
|
+
| `relative` | `boolean` | When true, returned paths are relative to `baseDir` instead of absolute. |
|
|
736
|
+
|
|
737
|
+
**Returns:** `void`
|
|
738
|
+
|
|
739
|
+
```ts
|
|
740
|
+
const result = await fs.walkAsync('src', { exclude: ['node_modules'] })
|
|
741
|
+
const files = await fs.walkAsync('inbox', { relative: true })
|
|
742
|
+
// files.files => ['contact-1.json', 'subfolder/file.txt', ...]
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
### findUp
|
|
748
|
+
|
|
749
|
+
Synchronously finds a file by walking up the directory tree from the current working directory.
|
|
750
|
+
|
|
751
|
+
**Parameters:**
|
|
752
|
+
|
|
753
|
+
| Name | Type | Required | Description |
|
|
754
|
+
|------|------|----------|-------------|
|
|
755
|
+
| `fileName` | `string` | ✓ | The name of the file to search for |
|
|
756
|
+
| `options` | `{ cwd?: string }` | | Options for the search |
|
|
757
|
+
|
|
758
|
+
`{ cwd?: string }` properties:
|
|
759
|
+
|
|
760
|
+
| Property | Type | Description |
|
|
761
|
+
|----------|------|-------------|
|
|
762
|
+
| `cwd` | `any` | The directory to start searching from (defaults to container.cwd) |
|
|
763
|
+
|
|
764
|
+
**Returns:** `string | null`
|
|
765
|
+
|
|
766
|
+
```ts
|
|
767
|
+
const packageJson = fs.findUp('package.json')
|
|
768
|
+
if (packageJson) {
|
|
769
|
+
console.log(`Found package.json at: ${packageJson}`)
|
|
770
|
+
}
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
### findUpAsync
|
|
776
|
+
|
|
777
|
+
Asynchronously finds a file by walking up the directory tree.
|
|
778
|
+
|
|
779
|
+
**Parameters:**
|
|
780
|
+
|
|
781
|
+
| Name | Type | Required | Description |
|
|
782
|
+
|------|------|----------|-------------|
|
|
783
|
+
| `fileName` | `string` | ✓ | The name of the file to search for |
|
|
784
|
+
| `options` | `{ cwd?: string; multiple?: boolean }` | | Options for the search |
|
|
785
|
+
|
|
786
|
+
`{ cwd?: string; multiple?: boolean }` properties:
|
|
787
|
+
|
|
788
|
+
| Property | Type | Description |
|
|
789
|
+
|----------|------|-------------|
|
|
790
|
+
| `cwd` | `any` | The directory to start searching from (defaults to container.cwd) |
|
|
791
|
+
| `multiple` | `any` | Whether to find multiple instances of the file |
|
|
792
|
+
|
|
793
|
+
**Returns:** `Promise<string | string[] | null>`
|
|
794
|
+
|
|
795
|
+
```ts
|
|
796
|
+
const packageJson = await fs.findUpAsync('package.json')
|
|
797
|
+
const allPackageJsons = await fs.findUpAsync('package.json', { multiple: true })
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
## State (Zod v4 schema)
|
|
803
|
+
|
|
804
|
+
| Property | Type | Description |
|
|
805
|
+
|----------|------|-------------|
|
|
806
|
+
| `enabled` | `boolean` | Whether this feature is currently enabled |
|
|
807
|
+
|
|
808
|
+
## Examples
|
|
809
|
+
|
|
810
|
+
**features.fs**
|
|
811
|
+
|
|
812
|
+
```ts
|
|
813
|
+
const fs = container.feature('fs')
|
|
814
|
+
const content = fs.readFile('package.json')
|
|
815
|
+
const exists = fs.exists('tsconfig.json')
|
|
816
|
+
await fs.writeFileAsync('output.txt', 'Hello World')
|
|
817
|
+
fs.writeFile('sync-output.txt', 'Hello Sync')
|
|
818
|
+
fs.copy('src', 'backup/src')
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
**readFile**
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
const content = fs.readFile('README.md')
|
|
827
|
+
const buffer = fs.readFile('image.png', null)
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
**readFileAsync**
|
|
833
|
+
|
|
834
|
+
```ts
|
|
835
|
+
const content = await fs.readFileAsync('data.txt')
|
|
836
|
+
const buffer = await fs.readFileAsync('image.png', null)
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
**readJson**
|
|
842
|
+
|
|
843
|
+
```ts
|
|
844
|
+
const config = fs.readJson('config.json')
|
|
845
|
+
console.log(config.version)
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
**readJsonAsync**
|
|
851
|
+
|
|
852
|
+
```ts
|
|
853
|
+
const config = await fs.readJsonAsync('config.json')
|
|
854
|
+
console.log(config.version)
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
**readdirSync**
|
|
860
|
+
|
|
861
|
+
```ts
|
|
862
|
+
const entries = fs.readdirSync('src')
|
|
863
|
+
console.log(entries) // ['index.ts', 'utils.ts', 'components']
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
**readdir**
|
|
869
|
+
|
|
870
|
+
```ts
|
|
871
|
+
const entries = await fs.readdir('src')
|
|
872
|
+
console.log(entries) // ['index.ts', 'utils.ts', 'components']
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
**writeFile**
|
|
878
|
+
|
|
879
|
+
```ts
|
|
880
|
+
fs.writeFile('output.txt', 'Hello World')
|
|
881
|
+
fs.writeFile('data.bin', Buffer.from([1, 2, 3, 4]))
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
**writeFileAsync**
|
|
491
887
|
|
|
492
888
|
```ts
|
|
493
889
|
await fs.writeFileAsync('output.txt', 'Hello World')
|
|
@@ -496,6 +892,22 @@ await fs.writeFileAsync('data.bin', Buffer.from([1, 2, 3, 4]))
|
|
|
496
892
|
|
|
497
893
|
|
|
498
894
|
|
|
895
|
+
**writeJson**
|
|
896
|
+
|
|
897
|
+
```ts
|
|
898
|
+
fs.writeJson('config.json', { version: '1.0.0', debug: false })
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
**writeJsonAsync**
|
|
904
|
+
|
|
905
|
+
```ts
|
|
906
|
+
await fs.writeJsonAsync('config.json', { version: '1.0.0', debug: false })
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
499
911
|
**appendFile**
|
|
500
912
|
|
|
501
913
|
```ts
|
|
@@ -512,30 +924,61 @@ await fs.appendFileAsync('log.txt', 'New line\n')
|
|
|
512
924
|
|
|
513
925
|
|
|
514
926
|
|
|
927
|
+
**ensureFile**
|
|
928
|
+
|
|
929
|
+
```ts
|
|
930
|
+
fs.ensureFile('logs/app.log', '', false)
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
**ensureFileAsync**
|
|
936
|
+
|
|
937
|
+
```ts
|
|
938
|
+
await fs.ensureFileAsync('config/settings.json', '{}', true)
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
515
943
|
**ensureFolder**
|
|
516
944
|
|
|
517
945
|
```ts
|
|
518
946
|
fs.ensureFolder('logs/debug')
|
|
519
|
-
// Creates logs and logs/debug directories if they don't exist
|
|
520
947
|
```
|
|
521
948
|
|
|
522
949
|
|
|
523
950
|
|
|
524
|
-
**
|
|
951
|
+
**ensureFolderAsync**
|
|
525
952
|
|
|
526
953
|
```ts
|
|
527
|
-
fs.
|
|
528
|
-
// Creates logs directory and app.log file if they don't exist
|
|
954
|
+
await fs.ensureFolderAsync('logs/debug')
|
|
529
955
|
```
|
|
530
956
|
|
|
531
957
|
|
|
532
958
|
|
|
533
|
-
**
|
|
959
|
+
**mkdirp**
|
|
534
960
|
|
|
535
961
|
```ts
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
962
|
+
fs.mkdirp('deep/nested/path')
|
|
963
|
+
```
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
**exists**
|
|
968
|
+
|
|
969
|
+
```ts
|
|
970
|
+
if (fs.exists('config.json')) {
|
|
971
|
+
console.log('Config file exists!')
|
|
972
|
+
}
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
**existsSync**
|
|
978
|
+
|
|
979
|
+
```ts
|
|
980
|
+
if (fs.existsSync('config.json')) {
|
|
981
|
+
console.log('Config file exists!')
|
|
539
982
|
}
|
|
540
983
|
```
|
|
541
984
|
|
|
@@ -551,38 +994,84 @@ if (await fs.existsAsync('config.json')) {
|
|
|
551
994
|
|
|
552
995
|
|
|
553
996
|
|
|
554
|
-
**
|
|
997
|
+
**stat**
|
|
555
998
|
|
|
556
999
|
```ts
|
|
557
|
-
|
|
558
|
-
|
|
1000
|
+
const info = fs.stat('package.json')
|
|
1001
|
+
console.log(info.size, info.mtime)
|
|
1002
|
+
```
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
**statAsync**
|
|
1007
|
+
|
|
1008
|
+
```ts
|
|
1009
|
+
const info = await fs.statAsync('package.json')
|
|
1010
|
+
console.log(info.size, info.mtime)
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
**isFile**
|
|
1016
|
+
|
|
1017
|
+
```ts
|
|
1018
|
+
if (fs.isFile('package.json')) {
|
|
1019
|
+
console.log('It is a file')
|
|
559
1020
|
}
|
|
560
1021
|
```
|
|
561
1022
|
|
|
562
1023
|
|
|
563
1024
|
|
|
564
|
-
**
|
|
1025
|
+
**isFileAsync**
|
|
565
1026
|
|
|
566
1027
|
```ts
|
|
567
|
-
await fs.
|
|
1028
|
+
if (await fs.isFileAsync('package.json')) {
|
|
1029
|
+
console.log('It is a file')
|
|
1030
|
+
}
|
|
568
1031
|
```
|
|
569
1032
|
|
|
570
1033
|
|
|
571
1034
|
|
|
572
|
-
**
|
|
1035
|
+
**isDirectory**
|
|
573
1036
|
|
|
574
1037
|
```ts
|
|
575
|
-
|
|
576
|
-
console.log(
|
|
1038
|
+
if (fs.isDirectory('src')) {
|
|
1039
|
+
console.log('It is a directory')
|
|
1040
|
+
}
|
|
577
1041
|
```
|
|
578
1042
|
|
|
579
1043
|
|
|
580
1044
|
|
|
581
|
-
**
|
|
1045
|
+
**isDirectoryAsync**
|
|
582
1046
|
|
|
583
1047
|
```ts
|
|
584
|
-
|
|
585
|
-
console.log(
|
|
1048
|
+
if (await fs.isDirectoryAsync('src')) {
|
|
1049
|
+
console.log('It is a directory')
|
|
1050
|
+
}
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
**rmSync**
|
|
1056
|
+
|
|
1057
|
+
```ts
|
|
1058
|
+
fs.rmSync('temp/cache.tmp')
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
**rm**
|
|
1064
|
+
|
|
1065
|
+
```ts
|
|
1066
|
+
await fs.rm('temp/cache.tmp')
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
**rmdirSync**
|
|
1072
|
+
|
|
1073
|
+
```ts
|
|
1074
|
+
fs.rmdirSync('temp/cache')
|
|
586
1075
|
```
|
|
587
1076
|
|
|
588
1077
|
|
|
@@ -591,7 +1080,73 @@ console.log(content)
|
|
|
591
1080
|
|
|
592
1081
|
```ts
|
|
593
1082
|
await fs.rmdir('temp/cache')
|
|
594
|
-
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
**copy**
|
|
1088
|
+
|
|
1089
|
+
```ts
|
|
1090
|
+
fs.copy('src/config.json', 'backup/config.json')
|
|
1091
|
+
fs.copy('src', 'backup/src')
|
|
1092
|
+
```
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
1096
|
+
**copyAsync**
|
|
1097
|
+
|
|
1098
|
+
```ts
|
|
1099
|
+
await fs.copyAsync('src/config.json', 'backup/config.json')
|
|
1100
|
+
await fs.copyAsync('src', 'backup/src')
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
**move**
|
|
1106
|
+
|
|
1107
|
+
```ts
|
|
1108
|
+
fs.move('temp/draft.txt', 'final/document.txt')
|
|
1109
|
+
fs.move('old-dir', 'new-dir')
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
**moveAsync**
|
|
1115
|
+
|
|
1116
|
+
```ts
|
|
1117
|
+
await fs.moveAsync('temp/draft.txt', 'final/document.txt')
|
|
1118
|
+
await fs.moveAsync('old-dir', 'new-dir')
|
|
1119
|
+
```
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
**walk**
|
|
1124
|
+
|
|
1125
|
+
```ts
|
|
1126
|
+
const result = fs.walk('src', { files: true, directories: false })
|
|
1127
|
+
const filtered = fs.walk('.', { exclude: ['node_modules', '.git'], include: ['*.ts'] })
|
|
1128
|
+
const relative = fs.walk('inbox', { relative: true }) // => { files: ['contact-1.json', ...] }
|
|
1129
|
+
```
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
**walkAsync**
|
|
1134
|
+
|
|
1135
|
+
```ts
|
|
1136
|
+
const result = await fs.walkAsync('src', { exclude: ['node_modules'] })
|
|
1137
|
+
const files = await fs.walkAsync('inbox', { relative: true })
|
|
1138
|
+
// files.files => ['contact-1.json', 'subfolder/file.txt', ...]
|
|
1139
|
+
```
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1143
|
+
**findUp**
|
|
1144
|
+
|
|
1145
|
+
```ts
|
|
1146
|
+
const packageJson = fs.findUp('package.json')
|
|
1147
|
+
if (packageJson) {
|
|
1148
|
+
console.log(`Found package.json at: ${packageJson}`)
|
|
1149
|
+
}
|
|
595
1150
|
```
|
|
596
1151
|
|
|
597
1152
|
|