@cobol-ts/files 0.0.14 → 0.0.17
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/README.md +18 -32
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,38 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cobol-ts/files
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Provide a small text-file port plus a Node adapter, and upward directory discovery for `.cobolts` configuration.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The `TextFiles` interface separates filesystem I/O from catalogue and generator logic.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
import {findDirectoryUp} from '@cobol-ts/files';
|
|
7
|
+
## Example
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```typescript
|
|
10
|
+
import {findDirectoryUp, nodeTextFiles} from '@cobol-ts/files'
|
|
11
|
+
|
|
12
|
+
const configDirectory = await findDirectoryUp('.cobolts', process.cwd())
|
|
13
|
+
const source = await nodeTextFiles.read(`${configDirectory}/files.yaml`)
|
|
11
14
|
```
|
|
12
15
|
|
|
13
|
-
`
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
- `index.ts`: package entrypoint, re-exporting the utility.
|
|
23
|
-
|
|
24
|
-
## Text-file port
|
|
25
|
-
|
|
26
|
-
`TextFiles` is the small I/O boundary for configuration and TypeScript source generation. It can be replaced by an in-memory implementation in tests:
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
export interface TextFiles {
|
|
30
|
-
read(filename: string): Promise<string>
|
|
31
|
-
write(filename: string, text: readonly string[]): Promise<void>
|
|
32
|
-
exists(filename: string): Promise<boolean>
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
`nodeTextFiles` is the standard Node implementation. It reads UTF-8, writes each string as a line with `\n` separators and a final newline for a nonempty array, creates missing parent directories, and checks whether a file path exists. Exceptions from Node I/O are propagated for callers to convert into their own `ErrorsOr` context.
|
|
37
|
-
|
|
38
|
-
Top-level convenience functions `readTextFile(filename)` and `writeTextFile(filename, lines)` delegate to `nodeTextFiles`. The existing `findDirectoryUp()` API remains unchanged.
|
|
16
|
+
`TextFiles` is a small read/write port used by configuration and generators. `findDirectoryUp` walks parents looking for a directory; it throws when no match exists.
|
|
17
|
+
|
|
18
|
+
## Source and tests
|
|
19
|
+
|
|
20
|
+
**Public entry points:** [files.ts](./src/files.ts), [text.files.ts](./src/text.files.ts).
|
|
21
|
+
|
|
22
|
+
**Tests:** [files.spec.ts](src/files.spec.ts), [text.files.spec.ts](src/text.files.spec.ts)
|
|
23
|
+
|
|
24
|
+
**Related:** [@cobol-ts/file-catalogue](../../config/file-catalogue/README.md) · [@cobol-ts/codegen](../../codegen/codegen/README.md).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobol-ts/files",
|
|
3
3
|
"description": "file utilities for the @cobol-ts project",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
7
7
|
"browserslist": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@cobol-ts/records": "0.0.
|
|
20
|
+
"@cobol-ts/records": "0.0.17"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^5.2.2",
|