Skip to content

Commit aff642c

Browse files
Copilothotlong
andcommitted
Add automatic .gitignore update in init command
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 82f6f70 commit aff642c

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pnpm objectdocs init
9191
This will:
9292
- Copy the site engine to `content/.objectdocs`
9393
- Install necessary dependencies
94+
- Automatically add `content/.objectdocs` to `.gitignore`
9495
- Prepare your project for development
9596

9697
### 4. Add content

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pnpm objectdocs init
3535
This command:
3636
- Copies the `@objectdocs/site` package to `content/.objectdocs`
3737
- Installs necessary dependencies
38+
- Automatically adds `content/.objectdocs` to `.gitignore`
3839
- Prepares your project for local development
3940

4041
### Site Management

packages/cli/src/commands/init.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ export function registerInitCommand(cli) {
6565

6666
console.log('✅ ObjectDocs site copied successfully!\n');
6767

68+
// Add to .gitignore
69+
const gitignorePath = path.resolve(process.cwd(), '.gitignore');
70+
const gitignoreEntry = 'content/.objectdocs';
71+
72+
try {
73+
let gitignoreContent = '';
74+
if (fs.existsSync(gitignorePath)) {
75+
gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
76+
}
77+
78+
// Check if the entry already exists
79+
if (!gitignoreContent.includes(gitignoreEntry)) {
80+
// Add the entry with a comment
81+
const separator = gitignoreContent.trim() ? '\n\n' : '';
82+
const newContent = gitignoreContent.trim() + separator + '# ObjectDocs\n' + gitignoreEntry + '\n';
83+
fs.writeFileSync(gitignorePath, newContent);
84+
console.log('📝 Added content/.objectdocs to .gitignore\n');
85+
}
86+
} catch (e) {
87+
console.warn('⚠️ Could not update .gitignore:', e.message);
88+
}
89+
6890
// Install dependencies in the target directory
6991
console.log('📦 Installing dependencies...\n');
7092

0 commit comments

Comments
 (0)