Skip to content

Commit 4105ca0

Browse files
authored
Support multiple input folders (#24)
* support multiple input folders * Update index.ts * wip * Update CHANGELOG.md * Update README.md * Update README.md * Update index.ts
1 parent c90b658 commit 4105ca0

5 files changed

Lines changed: 307 additions & 126 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
### 1.2.0
2+
3+
- Support multiple input folders (eg `--input folder1 folder2`)
24
- Add Claude Sonnet token estimation
35
- Upgrade packages
46

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@
22

33
A CLI tool to aggregate your codebase into a single Markdown file for use with Claude Projects or custom ChatGPTs.
44

5-
## Features
6-
7-
- Aggregates all files in the specified directory and subdirectories
8-
- Ignores common build artifacts and configuration files
9-
- Outputs a single Markdown file containing the whole codebase
10-
- Provides options for whitespace removal and custom ignore patterns
11-
- View file size statistics with visual bar charts
12-
- Watch mode for automatic rebuilding when files change
13-
145
## How to Use
156

167
Start by running the CLI tool in your project directory:
@@ -23,6 +14,15 @@ This will generate a `codebase.md` file with your codebase.
2314

2415
Once you've generated the Markdown file containing your codebase, you can use it with AI models like ChatGPT and Claude for code analysis and assistance.
2516

17+
## Features
18+
19+
- Aggregates all files in the specified directory and subdirectories
20+
- Ignores common build artifacts and configuration files
21+
- Outputs a single Markdown file containing the whole codebase
22+
- Provides options for whitespace removal and custom ignore patterns
23+
- View file size statistics with visual bar charts
24+
- Watch mode for automatic rebuilding when files change
25+
2626
### With ChatGPT:
2727

2828
1. Create a Custom GPT
@@ -37,7 +37,7 @@ For best results, re-upload the Markdown file before starting a new chat session
3737

3838
## Options
3939

40-
- `-i, --input <directory>`: Specify input directory (default: current directory)
40+
- `-i, --input <directories...>`: Specify input directories (multiple allowed, default: current directory)
4141
- `-o, --output <file>`: Specify output file (default: codebase.md)
4242
- `--no-default-ignores`: Disable default ignore patterns
4343
- `--whitespace-removal`: Enable whitespace removal

src/index.test.ts

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,91 @@ describe("AI Digest CLI", () => {
232232
await fs.rm(tempDir, { recursive: true, force: true });
233233
}
234234
}, 15000);
235-
});
236235

237-
it("should recognize the --watch flag", async () => {
238-
// This test verifies the CLI recognizes the --watch flag
239-
// Set NODE_ENV to test to ensure watchFiles() exits early
240-
const originalEnv = process.env.NODE_ENV;
241-
process.env.NODE_ENV = 'test';
242-
243-
try {
244-
// Run CLI with watch flag
245-
const { stdout } = await runCLI("--watch");
246-
247-
// Verify watch mode was initialized but did not hang
248-
expect(stdout).toContain("Watch mode enabled");
249-
expect(stdout).toContain("Waiting for file changes");
250-
} finally {
251-
// Restore original environment
252-
process.env.NODE_ENV = originalEnv;
253-
}
254-
}, 10000);
236+
it("should recognize the --watch flag", async () => {
237+
// This test verifies the CLI recognizes the --watch flag
238+
// Set NODE_ENV to test to ensure watchFiles() exits early
239+
const originalEnv = process.env.NODE_ENV;
240+
process.env.NODE_ENV = "test";
241+
242+
try {
243+
// Run CLI with watch flag
244+
const { stdout } = await runCLI("--watch");
245+
246+
// Verify watch mode was initialized but did not hang
247+
expect(stdout).toContain("Watch mode enabled");
248+
expect(stdout).toContain("Waiting for file changes");
249+
} finally {
250+
// Restore original environment
251+
process.env.NODE_ENV = originalEnv;
252+
}
253+
}, 10000);
254+
255+
// Test for multiple input directories
256+
it("should handle multiple input directories", async () => {
257+
// Create two temporary directories
258+
const tempDir1 = await fs.mkdtemp(
259+
path.join(os.tmpdir(), "ai-digest-test-dir1-")
260+
);
261+
const tempDir2 = await fs.mkdtemp(
262+
path.join(os.tmpdir(), "ai-digest-test-dir2-")
263+
);
264+
265+
try {
266+
// Create test files in first directory
267+
await fs.writeFile(
268+
path.join(tempDir1, "dir1-file1.txt"),
269+
"Content from dir1"
270+
);
271+
await fs.writeFile(
272+
path.join(tempDir1, "common.txt"),
273+
"Common file in dir1"
274+
);
275+
276+
// Create test files in second directory
277+
await fs.writeFile(
278+
path.join(tempDir2, "dir2-file1.txt"),
279+
"Content from dir2"
280+
);
281+
await fs.writeFile(
282+
path.join(tempDir2, "common.txt"),
283+
"Common file in dir2"
284+
);
285+
286+
// Run CLI with multiple input directories
287+
const { stdout } = await runCLI(
288+
`--input ${tempDir1} ${tempDir2} --show-output-files`
289+
);
290+
291+
// Verify output
292+
expect(stdout).toContain(`Scanning directory: ${tempDir1}`);
293+
expect(stdout).toContain(`Scanning directory: ${tempDir2}`);
294+
295+
// Verify files from both directories are included
296+
expect(stdout).toContain(`${path.basename(tempDir1)}/dir1-file1.txt`);
297+
expect(stdout).toContain(`${path.basename(tempDir2)}/dir2-file1.txt`);
298+
expect(stdout).toContain(`${path.basename(tempDir1)}/common.txt`);
299+
expect(stdout).toContain(`${path.basename(tempDir2)}/common.txt`);
300+
301+
// Read the generated codebase.md file
302+
const codebasePath = path.resolve(process.cwd(), "codebase.md");
303+
const content = await fs.readFile(codebasePath, "utf-8");
304+
305+
// Verify content from both directories is included
306+
expect(content).toContain(`# ${path.basename(tempDir1)}/dir1-file1.txt`);
307+
expect(content).toContain("Content from dir1");
308+
expect(content).toContain(`# ${path.basename(tempDir2)}/dir2-file1.txt`);
309+
expect(content).toContain("Content from dir2");
310+
311+
// Check common files are included with directory prefixes
312+
expect(content).toContain(`# ${path.basename(tempDir1)}/common.txt`);
313+
expect(content).toContain("Common file in dir1");
314+
expect(content).toContain(`# ${path.basename(tempDir2)}/common.txt`);
315+
expect(content).toContain("Common file in dir2");
316+
} finally {
317+
// Clean up the temporary directories
318+
await fs.rm(tempDir1, { recursive: true, force: true });
319+
await fs.rm(tempDir2, { recursive: true, force: true });
320+
}
321+
}, 15000);
322+
});

0 commit comments

Comments
 (0)