flatten-tool 1.2.1 → 1.2.3
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 +11 -0
- package/index.ts +11 -19
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
A CLI utility to flatten directory structures.
|
|
6
6
|
|
|
7
|
+
[](https://asciinema.org/a/ThswNC1vrdlK0wdD)
|
|
8
|
+
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
Requires [Bun](https://bun.sh) runtime (v1.1+).
|
|
@@ -111,6 +113,15 @@ This project uses Bun for runtime, TypeScript for type safety, and follows the g
|
|
|
111
113
|
|
|
112
114
|
## Changelog
|
|
113
115
|
|
|
116
|
+
### v1.2.3
|
|
117
|
+
- Added demo.gif to docs/ and linked in README.md.
|
|
118
|
+
|
|
119
|
+
### v1.2.2
|
|
120
|
+
- Added `setMaxListeners(0)` on WriteStream in Markdown merging to silence listener warnings when processing many files.
|
|
121
|
+
|
|
122
|
+
### v1.2.1
|
|
123
|
+
- Fixed memory leak warnings in Markdown merging by refactoring to use `pipeline` and `finished` from `node:stream/promises`.
|
|
124
|
+
|
|
114
125
|
### v1.2.0
|
|
115
126
|
- Implemented streaming for Markdown merging to improve memory efficiency for large files/directories.
|
|
116
127
|
- Updated documentation and coding guidelines.
|
package/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { copyFile, rename, rm, stat, mkdir, readdir, rmdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join, relative, sep, resolve, extname } from 'node:path';
|
|
4
4
|
import { createReadStream, createWriteStream } from 'node:fs';
|
|
5
|
+
import { pipeline, finished } from 'node:stream/promises';
|
|
5
6
|
import yargs from 'yargs';
|
|
6
7
|
import { hideBin } from 'yargs/helpers';
|
|
7
8
|
import { globby } from 'globby';
|
|
@@ -68,6 +69,7 @@ export async function flattenDirectory(
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
const writeStream = createWriteStream(absTarget);
|
|
72
|
+
writeStream.setMaxListeners(0);
|
|
71
73
|
|
|
72
74
|
for (const srcPath of files) {
|
|
73
75
|
const relPath = relative(absSource, srcPath).replace(/\\/g, '/');
|
|
@@ -75,32 +77,22 @@ export async function flattenDirectory(
|
|
|
75
77
|
const isMd = ['md', 'markdown'].includes(ext.toLowerCase());
|
|
76
78
|
const ticks = isMd ? '````' : '```';
|
|
77
79
|
|
|
78
|
-
//
|
|
80
|
+
// Write header synchronously
|
|
79
81
|
writeStream.write(`# ${relPath}\n\n${ticks}${ext}\n`);
|
|
80
82
|
|
|
81
|
-
// Stream file content
|
|
83
|
+
// Stream file content (preserve original UTF-8 text behavior)
|
|
82
84
|
const readStream = createReadStream(srcPath, { encoding: 'utf8' });
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
// Pipe with { end: false } so writeStream stays open for next files
|
|
87
|
+
await pipeline(readStream, writeStream, { end: false });
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
writeStream.write(`\n${ticks}\n\n`);
|
|
90
|
-
resolve();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
readStream.on('error', reject);
|
|
94
|
-
writeStream.on('error', reject);
|
|
95
|
-
});
|
|
89
|
+
// Write closing fence
|
|
90
|
+
writeStream.write(`\n${ticks}\n\n`);
|
|
96
91
|
}
|
|
97
92
|
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
writeStream.on('close', resolve);
|
|
102
|
-
writeStream.on('error', reject);
|
|
103
|
-
});
|
|
93
|
+
// Close the output file and wait for it to finish
|
|
94
|
+
writeStream.end();
|
|
95
|
+
await finished(writeStream);
|
|
104
96
|
|
|
105
97
|
if (move) {
|
|
106
98
|
for (const srcPath of files) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatten-tool",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "CLI tool to flatten directory structures: merge files into a single Markdown file (default) or copy/move to a flat directory with escaped filenames. Respects .gitignore, supports move/overwrite, and more.",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"@types/yargs": "^17.0.35"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"typescript": "^5"
|
|
46
|
+
"typescript": "^5.9.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"globby": "^16.1.0",
|
|
50
50
|
"ignore": "^7.0.5",
|
|
51
|
-
"minimatch": "^10.1.
|
|
51
|
+
"minimatch": "^10.1.2",
|
|
52
52
|
"yargs": "^18.0.0"
|
|
53
53
|
}
|
|
54
54
|
}
|