flatten-tool 1.6.1 → 1.6.2
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 +4 -0
- package/index.ts +34 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,6 +140,10 @@ This project uses Bun for runtime, TypeScript for type safety, and follows the g
|
|
|
140
140
|
|
|
141
141
|
## Changelog
|
|
142
142
|
|
|
143
|
+
### v1.6.2
|
|
144
|
+
- Updated AGENTS.md with revised coding guidelines.
|
|
145
|
+
- Added '..' links in subdirectory file trees for navigation to parent directories.
|
|
146
|
+
|
|
143
147
|
### v1.6.1
|
|
144
148
|
- Added instructions for running flatten-tool directly with npx and bunx.
|
|
145
149
|
|
package/index.ts
CHANGED
|
@@ -147,6 +147,8 @@ export async function flattenDirectory(
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
sections.push({ path: '', headerText: 'Project File Tree' });
|
|
151
|
+
|
|
150
152
|
collectSections(treeObj, '');
|
|
151
153
|
|
|
152
154
|
const anchorMap = new Map<string, string>();
|
|
@@ -161,10 +163,21 @@ export async function flattenDirectory(
|
|
|
161
163
|
node: any,
|
|
162
164
|
depth: number = 0,
|
|
163
165
|
prefix: string = '',
|
|
164
|
-
anchorMap: Map<string, string
|
|
166
|
+
anchorMap: Map<string, string>,
|
|
167
|
+
parentPath: string | null // null for global root (no ..)
|
|
165
168
|
): string {
|
|
166
169
|
let result = '';
|
|
167
170
|
const indent = ' '.repeat(depth);
|
|
171
|
+
|
|
172
|
+
// Add .. if we have a parent
|
|
173
|
+
if (parentPath !== null) {
|
|
174
|
+
const parentAnchor = anchorMap.get(parentPath) ?? '';
|
|
175
|
+
result += `${indent}- [..](#${parentAnchor})\n`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Determine indentation for direct children
|
|
179
|
+
const entryIndent = ' '.repeat(depth);
|
|
180
|
+
|
|
168
181
|
const entries: [string, any][] = Object.entries(node);
|
|
169
182
|
|
|
170
183
|
entries.sort(([a], [b]) => {
|
|
@@ -180,17 +193,27 @@ export async function flattenDirectory(
|
|
|
180
193
|
const display = isDir ? name + '/' : name;
|
|
181
194
|
const pathHere = prefix ? `${prefix}/${name}` : name;
|
|
182
195
|
const anchor = anchorMap.get(pathHere) ?? '';
|
|
183
|
-
|
|
196
|
+
|
|
197
|
+
result += `${entryIndent}- [${display}](#${anchor})\n`;
|
|
198
|
+
|
|
184
199
|
if (isDir) {
|
|
185
|
-
|
|
200
|
+
// Recurse with increased depth; child's parent is current prefix
|
|
201
|
+
result += renderMarkdownTree(
|
|
202
|
+
value,
|
|
203
|
+
depth + 1,
|
|
204
|
+
pathHere,
|
|
205
|
+
anchorMap,
|
|
206
|
+
prefix
|
|
207
|
+
);
|
|
186
208
|
}
|
|
187
209
|
}
|
|
210
|
+
|
|
188
211
|
return result;
|
|
189
212
|
}
|
|
190
213
|
|
|
191
214
|
// Render global tree with correct anchors
|
|
192
|
-
let treeMarkdown = "# Project File Tree\n\n
|
|
193
|
-
treeMarkdown += renderMarkdownTree(treeObj,
|
|
215
|
+
let treeMarkdown = "# Project File Tree\n\n";
|
|
216
|
+
treeMarkdown += renderMarkdownTree(treeObj, 0, '', anchorMap, null);
|
|
194
217
|
treeMarkdown += "\n\n";
|
|
195
218
|
|
|
196
219
|
const writeStream = createWriteStream(absTarget);
|
|
@@ -230,8 +253,12 @@ export async function flattenDirectory(
|
|
|
230
253
|
if (currentPath) {
|
|
231
254
|
writeStream.write(`# ${currentPath}\n\n`);
|
|
232
255
|
writeStream.write(`File Tree\n\n`);
|
|
233
|
-
|
|
234
|
-
|
|
256
|
+
|
|
257
|
+
const parentPath = currentPath.includes('/')
|
|
258
|
+
? currentPath.slice(0, currentPath.lastIndexOf('/'))
|
|
259
|
+
: '';
|
|
260
|
+
|
|
261
|
+
writeStream.write(renderMarkdownTree(node, 0, currentPath, anchorMap, parentPath));
|
|
235
262
|
writeStream.write('\n');
|
|
236
263
|
}
|
|
237
264
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flatten-tool",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
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",
|