Skip to content

Commit 39e81d6

Browse files
committed
feat: add .codebaseignore support to exclude file contents from export
1 parent b4de091 commit 39e81d6

File tree

9 files changed

+191
-26
lines changed

9 files changed

+191
-26
lines changed

RELEASE-NOTES-1.0.2.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# CodebaseMD v1.0.2 Release Notes
2+
3+
We're excited to announce the release of CodebaseMD v1.0.2!
4+
5+
## New Features
6+
7+
### .codebaseignore Support
8+
9+
This release adds support for a special `.codebaseignore` file that works similarly to `.gitignore` but is specifically for controlling what file contents are exported:
10+
11+
- Files matching patterns in `.codebaseignore` will still be included in the folder structure
12+
- Their contents will be excluded from the export, showing "*(File content excluded by .codebaseignore)*" instead
13+
- The `.codebaseignore` file uses the same syntax as `.gitignore`
14+
15+
## How to Use .codebaseignore
16+
17+
1. Create a `.codebaseignore` file in the root of your workspace
18+
2. Add file patterns following standard gitignore syntax
19+
3. Run the export command - files matching these patterns will be in the structure but their contents won't be included
20+
21+
Example `.codebaseignore` file:
22+
```
23+
# Exclude all test files
24+
*.test.js
25+
*.spec.js
26+
__tests__/
27+
28+
# Exclude configuration files
29+
.eslintrc
30+
.prettierrc
31+
tsconfig.json
32+
33+
# Exclude specific files or directories
34+
src/legacy/
35+
temp.js
36+
```
37+
38+
## Installation
39+
40+
Download the `.vsix` file from this release and install it in VS Code:
41+
42+
1. Open VS Code
43+
2. Press `Ctrl+Shift+X` to open the Extensions view
44+
3. Click on the three dots (⋯) in the top right corner
45+
4. Select "Install from VSIX..." and choose the downloaded file
46+
47+
Thank you for using CodebaseMD!

docs/changelog.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
# Changelog
22

3-
All notable changes to the CodebaseMD extension will be documented in this file.
3+
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
## [1.0.2] - 2025-03-16
11+
12+
### Added
13+
- `.codebaseignore` file support - Allows excluding file contents from export while keeping files in the directory structure
14+
15+
## [1.0.1] - 2024-09-26
16+
17+
### Added
18+
- New logo: A clean and minimalist logo added to the extension
19+
- Updated package.json to reference the logo in the marketplace
20+
821
## [1.0.0] - 2024-09-26
922

1023
### Added
11-
- Initial release of CodebaseMD
12-
- Feature to export entire codebase as Markdown
13-
- Feature to export selected files and folders as Markdown
14-
- Automatic exclusion of files and folders based on .gitignore and common patterns
15-
- Support for multiple file types
24+
- Initial release
25+
- Export entire codebase as Markdown
26+
- Export selected files or folders as Markdown
27+
- Automatically exclude files based on .gitignore and default patterns
28+
- File content syntax highlighting in exported Markdown
1629
- Folder structure visualization in the generated Markdown
1730
- Project statistics in the generated Markdown
1831

@@ -31,9 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3144
### Security
3245
- N/A (Initial release)
3346

34-
## [Unreleased]
35-
36-
### Planned Features
47+
## Planned Features
3748
- User-configurable ignore patterns
3849
- Option to include or exclude specific file types
3950
- Customizable Markdown output format

docs/configuration.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,31 @@
22

33
Currently, CodebaseMD does not have user-configurable settings through the Visual Studio Code settings interface. However, you can customize some behaviors by modifying the source code directly.
44

5+
## Using .codebaseignore File
6+
7+
CodebaseMD supports a special `.codebaseignore` file that works similarly to `.gitignore` but specifically for controlling what file contents are exported:
8+
9+
1. Create a `.codebaseignore` file in the root of your workspace
10+
2. Add file patterns following the same syntax as `.gitignore`
11+
3. Files matching these patterns will still be listed in the folder structure but their contents will be excluded from the export
12+
13+
Example `.codebaseignore` file:
14+
```
15+
# Exclude all test files
16+
*.test.js
17+
*.spec.js
18+
__tests__/
19+
20+
# Exclude configuration files
21+
.eslintrc
22+
.prettierrc
23+
tsconfig.json
24+
25+
# Exclude specific files or directories
26+
src/legacy/
27+
temp.js
28+
```
29+
530
## Customizing Ignored Files and Directories
631

732
To change which files and directories are ignored during export:

docs/usage.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
# Usage
22

3-
CodebaseMD provides two main functionalities: exporting your entire codebase and exporting selected files or folders.
3+
CodebaseMD provides two main commands to export your codebase to a Markdown file:
4+
5+
1. **Export All**: Export the entire codebase to a Markdown file
6+
2. **Export Selected**: Export only the selected files or folders to a Markdown file
47

58
## Exporting the Entire Codebase
69

7-
1. Open your project in Visual Studio Code
8-
2. Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`)
9-
3. Search for and select "Export Codebase as Markdown"
10+
1. Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS)
11+
2. Type "CodebaseMD: Export All" and select it
12+
3. Choose a location to save the exported Markdown file
13+
4. The extension will process all files in your workspace, excluding files specified in `.gitignore` or default ignore patterns
14+
5. Once complete, you will see a notification that the file was saved successfully
15+
16+
## Exporting Selected Files
17+
18+
1. Select one or more files or folders in the Explorer view
19+
2. Right-click and select "CodebaseMD: Export Selected" from the context menu
20+
3. Alternatively, open the Command Palette and type "CodebaseMD: Export Selected" (you need to have selected files first)
1021
4. Choose a location to save the exported Markdown file
11-
5. The extension will generate a Markdown file containing your project's structure and file contents
22+
5. The extension will process only the selected files, still respecting ignore patterns
23+
6. Once complete, you will see a notification that the file was saved successfully
24+
25+
## Excluding Files from Content Export
26+
27+
You can exclude files from having their contents exported while still keeping them in the folder structure by using a `.codebaseignore` file:
1228

13-
## Exporting Selected Files or Folders
29+
1. Create a `.codebaseignore` file in the root of your workspace
30+
2. Add patterns using the same syntax as `.gitignore`
31+
3. When exporting, files matching these patterns will be included in the folder structure but will show a message indicating their contents were excluded
1432

15-
1. In the Explorer view, select one or more files or folders you want to export
16-
2. Right-click on the selection
17-
3. Choose "Export Selected as Markdown" from the context menu
18-
4. Select a location to save the exported Markdown file
19-
5. The extension will generate a Markdown file containing the structure and contents of your selected files and folders
33+
This is useful for files that you want to acknowledge exist in your project structure but don't need to include their full contents in the export.
2034

2135
## Understanding the Output
2236

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "codebase-md",
33
"displayName": "CodebaseMD",
44
"description": "Export your entire codebase or selected files as a Markdown file.",
5-
"version": "1.0.1",
5+
"version": "1.0.2",
66
"publisher": "alpha912",
77
"engines": {
88
"vscode": "^1.70.0"
@@ -36,7 +36,7 @@
3636
"explorer/context": [
3737
{
3838
"command": "codebaseMD.exportSelected",
39-
"when": "explorerResourceIsFo­lder || resourceFilename",
39+
"when": "explorerResourceIsFolder || resourceFilename",
4040
"group": "navigation"
4141
}
4242
]

releases/RELEASE-NOTES-1.0.2.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# CodebaseMD v1.0.2 Release Notes
2+
3+
We're excited to announce the release of CodebaseMD v1.0.2!
4+
5+
## New Features
6+
7+
### .codebaseignore Support
8+
9+
This release adds support for a special `.codebaseignore` file that works similarly to `.gitignore` but is specifically for controlling what file contents are exported:
10+
11+
- Files matching patterns in `.codebaseignore` will still be included in the folder structure
12+
- Their contents will be excluded from the export, showing "*(File content excluded by .codebaseignore)*" instead
13+
- The `.codebaseignore` file uses the same syntax as `.gitignore`
14+
15+
## How to Use .codebaseignore
16+
17+
1. Create a `.codebaseignore` file in the root of your workspace
18+
2. Add file patterns following standard gitignore syntax
19+
3. Run the export command - files matching these patterns will be in the structure but their contents won't be included
20+
21+
Example `.codebaseignore` file:
22+
```
23+
# Exclude all test files
24+
*.test.js
25+
*.spec.js
26+
__tests__/
27+
28+
# Exclude configuration files
29+
.eslintrc
30+
.prettierrc
31+
tsconfig.json
32+
33+
# Exclude specific files or directories
34+
src/legacy/
35+
temp.js
36+
```
37+
38+
## Installation
39+
40+
Download the `.vsix` file from this release and install it in VS Code:
41+
42+
1. Open VS Code
43+
2. Press `Ctrl+Shift+X` to open the Extensions view
44+
3. Click on the three dots (⋯) in the top right corner
45+
4. Select "Install from VSIX..." and choose the downloaded file
46+
47+
Thank you for using CodebaseMD!

releases/codebase-md-1.0.2.vsix

155 KB
Binary file not shown.

src/extension.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async function exportSelectedFiles(uris: vscode.Uri[]) {
4343

4444
async function getAllFiles(dir: string): Promise<string[]> {
4545
const ig = createIgnoreInstance(dir);
46+
const codebaseIgnoreFiles = getCodebaseIgnoreFiles(dir);
4647
const files: string[] = [];
4748

4849
async function traverse(currentDir: string) {
@@ -75,6 +76,7 @@ async function getFilesFromUris(uris: vscode.Uri[]): Promise<string[]> {
7576
const files: string[] = [];
7677
const rootPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
7778
const ig = createIgnoreInstance(rootPath);
79+
const codebaseIgnoreFiles = getCodebaseIgnoreFiles(rootPath);
7880

7981
async function processUri(currentUri: vscode.Uri) {
8082
const stat = await vscode.workspace.fs.stat(currentUri);
@@ -143,6 +145,16 @@ function createIgnoreInstance(rootDir: string): Ignore {
143145
return ig;
144146
}
145147

148+
function getCodebaseIgnoreFiles(rootDir: string): Ignore {
149+
const ig = ignore();
150+
const codebaseIgnorePath = path.join(rootDir, '.codebaseignore');
151+
if (fs.existsSync(codebaseIgnorePath)) {
152+
const codebaseIgnoreContent = fs.readFileSync(codebaseIgnorePath, 'utf8');
153+
ig.add(codebaseIgnoreContent);
154+
}
155+
return ig;
156+
}
157+
146158
function isLargeFile(fileName: string): boolean {
147159
const largeFiles = ['package-lock.json', 'yarn.lock'];
148160
return largeFiles.includes(fileName);
@@ -159,8 +171,14 @@ function isSupportedFile(fileName: string): boolean {
159171
return supportedExtensions.includes(ext);
160172
}
161173

174+
function shouldIncludeFileContents(filePath: string, rootPath: string, codebaseIgnoreFiles: Ignore): boolean {
175+
const relativePath = path.relative(rootPath, filePath);
176+
return !codebaseIgnoreFiles.ignores(relativePath) && isSupportedFile(path.basename(filePath));
177+
}
178+
162179
async function generateMarkdown(files: string[], rootPath: string): Promise<string> {
163180
let markdown = `# Project Export\n\n`;
181+
const codebaseIgnoreFiles = getCodebaseIgnoreFiles(rootPath);
164182

165183
// Project statistics
166184
markdown += `## Project Statistics\n\n`;
@@ -178,13 +196,15 @@ async function generateMarkdown(files: string[], rootPath: string): Promise<stri
178196
const fileName = path.basename(file);
179197
markdown += `\n### ${relativePath}\n\n`;
180198

181-
if (isSupportedFile(fileName)) {
199+
if (shouldIncludeFileContents(file, rootPath, codebaseIgnoreFiles)) {
182200
const code = fs.readFileSync(file, 'utf8');
183201
const ext = path.extname(file).substring(1);
184202
markdown += '```' + ext + '\n';
185203
markdown += code;
186204
markdown += '\n```\n';
187-
} else {
205+
} else if (codebaseIgnoreFiles.ignores(relativePath)) {
206+
markdown += `*(File content excluded by .codebaseignore)*\n`;
207+
} else if (!isSupportedFile(fileName)) {
188208
markdown += `*(Unsupported file type)*\n`;
189209
}
190210
}

0 commit comments

Comments
 (0)