-
Notifications
You must be signed in to change notification settings - Fork 11
cli: add .gitignore template #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a JSON metadata file for the pre-release of the "apibara" package and integrates new functionality in the CLI. The CLI now creates or updates a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant FS as FileSystem
participant Prompter
User->>CLI: Run project initialization
CLI->>FS: Check if ".gitignore" exists
alt File exists
FS-->>CLI: true
CLI->>Prompter: Prompt for action (append, keep, overwrite)
Prompter-->>CLI: Return user decision
alt Append selected
CLI->>FS: Read current ".gitignore"
CLI->>FS: Append selected items
else Overwrite selected
CLI->>FS: Write new ".gitignore" content
else Keep selected
CLI-->>User: Retain existing ".gitignore"
end
else File does not exist
FS-->>CLI: false
CLI->>FS: Create new ".gitignore" with default entries
end
CLI-->>User: Log success message
Possibly related PRs
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/cli/src/create/templates.ts (3)
500-569: Comprehensive .gitignore file handling with user interaction.The implementation handles different scenarios well:
- Creating a new file if none exists
- Providing options to append, keep, or overwrite if file exists
- Interactive selection of items to append
However, there's a small inconsistency in the code.
In the append case, you're using
result.ignoreItemsinstead of the destructuredignoreItemsvariable:- fs.writeFileSync(gitIgnorePath, `${gitIgnoreContent}\n${result.ignoreItems.join("\n")}`,); + fs.writeFileSync(gitIgnorePath, `${gitIgnoreContent}\n${ignoreItems.join("\n")}`,);Also consider adding a check for duplicates when appending items to avoid adding entries that already exist in the file.
548-548: Use destructured variable for consistency.There's a variable naming inconsistency where you use
result.ignoreItemsinstead of the destructuredignoreItemsvariable that was defined earlier.- `${gitIgnoreContent}\n${result.ignoreItems.join("\n")}` + `${gitIgnoreContent}\n${ignoreItems.join("\n")}`
544-552: Consider checking for duplicates when appending items.When appending to an existing .gitignore file, it would be useful to check if the selected items already exist in the file to avoid duplicates. This enhances the user experience by preventing redundant entries.
Here's a simple approach:
if (overwrite === "append" && ignoreItems.length > 0) { const gitIgnoreContent = fs.readFileSync(gitIgnorePath, "utf8"); + const existingItems = gitIgnoreContent.split("\n").map(line => line.trim()); + const newItems = ignoreItems.filter(item => !existingItems.includes(item)); + + if (newItems.length === 0) { + consola.info("All selected items already exist in .gitignore"); + return; + } fs.writeFileSync( gitIgnorePath, - `${gitIgnoreContent}\n${result.ignoreItems.join("\n")}`, + `${gitIgnoreContent}\n${newItems.join("\n")}`, ); consola.success(`Updated ${cyan(".gitignore")}`); return; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
change/apibara-e6e30cda-092c-494d-b47b-f3c452f6e898.json(1 hunks)packages/cli/src/create/init.ts(3 hunks)packages/cli/src/create/templates.ts(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- change/apibara-e6e30cda-092c-494d-b47b-f3c452f6e898.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: test
🔇 Additional comments (4)
packages/cli/src/create/init.ts (3)
8-8: Added import for new functionality.The
createGitIgnoreFilefunction has been properly imported from the templates module.
133-133: Standardized success message formatting.Removed space after "Created" for consistency in the success messages. This makes the output formatting more consistent across all files created during project initialization.
Also applies to: 141-141, 149-149
158-159: Integration of .gitignore file creation.Good placement of the
createGitIgnoreFilefunction call - after creating all other project files but before the success message, ensuring a complete project initialization.packages/cli/src/create/templates.ts (1)
471-498: Well-structured .gitignore template with clear categorization.The
gitIgnoreItemsstructure provides a good foundation with:
- Common entries like node_modules, dist
- Apibara-specific entries
- Clear marking of recommended items
- Helpful descriptions for certain entries
This makes the .gitignore template both comprehensive and informative for users.
fracek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I really like they can pick what they add when the file already exists.
No description provided.