-
Notifications
You must be signed in to change notification settings - Fork 17
feat(sdk): add create-nitrolite-app project scaffolding tool #286
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
base: main
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @maxpushka, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request delivers a new create-nitrolite-app CLI tool, enabling developers to quickly scaffold Nitrolite applications with a guided interactive experience. It includes a fully-featured Next.js template that integrates essential SDK components and modern web development practices, significantly accelerating project setup for Nitrolite-based applications.
Highlights
- New Project Scaffolding CLI: This PR introduces
create-nitrolite-app, a new interactive command-line interface (CLI) tool built with Ink and React, designed to streamline the creation of new Nitrolite applications. - Next.js Application Template: A comprehensive
nextjs-apptemplate has been added, featuring Next.js 15 with App Router, TypeScript, TailwindCSS, and pre-configured integration with the Nitrolite SDK, Privy.io for authentication, Viem for blockchain interactions, and Valtio for state management. - Interactive Setup and Generation: The CLI guides users through project setup, including directory naming, Git initialization, and template selection, with real-time progress updates during file copying, templating, and dependency installation. It also supports non-interactive mode via CLI flags.
- WebSocket Integration Utilities: The Next.js template includes a robust set of components, hooks, and state management stores (
YellowWebSocketProvider,useYellowWebSocket,AssetsStore, etc.) for handling WebSocket connections, authentication, and data synchronization with a 'Yellow' service.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new project scaffolding tool, create-nitrolite-app. There are several inconsistencies regarding the available templates. The default template is often referred to as react-vite, but this template is not included, and the UI for template selection shows different options. This should be unified. I've also identified a critical issue in the Next.js template regarding environment variable handling, and a few other areas for improvement in terms of code quality and correctness. Please see my detailed comments.
| export const isDevelopment = import.meta.env.DEV; | ||
| export const isProduction = import.meta.env.PROD; | ||
|
|
||
| export const config = { | ||
| isDev: isDevelopment, | ||
| isProd: isProduction, | ||
| yellowWsUrl: import.meta.env.VITE_YELLOW_WS_URL || 'wss://clearnet.yellow.com/ws', | ||
| asset: import.meta.env.VITE_ASSET || 'usdc', | ||
| vApp: { | ||
| name: import.meta.env.VITE_VAPP_NAME || '', | ||
| scope: import.meta.env.VITE_VAPP_SCOPE || '', | ||
| }, | ||
| } as const; |
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.
This file uses import.meta.env and VITE_* prefixed environment variables, which will not work in a Next.js application. Next.js exposes environment variables through process.env and they must be prefixed with NEXT_PUBLIC_.
| export const isDevelopment = import.meta.env.DEV; | |
| export const isProduction = import.meta.env.PROD; | |
| export const config = { | |
| isDev: isDevelopment, | |
| isProd: isProduction, | |
| yellowWsUrl: import.meta.env.VITE_YELLOW_WS_URL || 'wss://clearnet.yellow.com/ws', | |
| asset: import.meta.env.VITE_ASSET || 'usdc', | |
| vApp: { | |
| name: import.meta.env.VITE_VAPP_NAME || '', | |
| scope: import.meta.env.VITE_VAPP_SCOPE || '', | |
| }, | |
| } as const; | |
| export const isDevelopment = process.env.NODE_ENV === 'development'; | |
| export const isProduction = process.env.NODE_ENV === 'production'; | |
| export const config = { | |
| isDev: isDevelopment, | |
| isProd: isProduction, | |
| yellowWsUrl: process.env.NEXT_PUBLIC_YELLOW_WS_URL || 'wss://clearnet.yellow.com/ws', | |
| asset: process.env.NEXT_PUBLIC_ASSET || 'usdc', | |
| vApp: { | |
| name: process.env.NEXT_PUBLIC_VAPP_NAME || '', | |
| scope: process.env.NEXT_PUBLIC_VAPP_SCOPE || '', | |
| }, | |
| } as const; |
| const privateKey = generatePrivateKey(); | ||
| const privateKeyHash = keccak256(toBytes(privateKey)); | ||
| const account = privateKeyToAccount(privateKeyHash); |
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.
The private key is generated and then immediately hashed with keccak256. This is a non-standard way of handling private keys. Use the raw private key to derive the public key and address. If this is intentional, document the rationale.
| const privateKey = generatePrivateKey(); | |
| const privateKeyHash = keccak256(toBytes(privateKey)); | |
| const account = privateKeyToAccount(privateKeyHash); | |
| const account = privateKeyToAccount(privateKey); |
| "declaration": true, | ||
| "outDir": "./dist", | ||
| "rootDir": "./src", | ||
| "strict": false, |
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.
|
|
||
| | Option | Description | Default | | ||
| | ------------------- | ---------------------------- | ------------ | | ||
| | `--template <name>` | Template to use | `react-vite` | |
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.
| ``` | ||
| my-nitrolite-app/ | ||
| ├── src/ | ||
| │ ├── components/ # React/Vue components | ||
| │ ├── hooks/ # Custom hooks (React) | ||
| │ ├── composables/ # Composables (Vue) | ||
| │ ├── utils/ # Utility functions | ||
| │ └── main.tsx # Entry point | ||
| ├── public/ # Static assets | ||
| ├── package.json | ||
| └── README.md | ||
| ``` |
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.
| const TEMPLATES: Template[] = [ | ||
| { | ||
| id: 'nextjs-app', | ||
| name: 'Next.js App Router', | ||
| description: 'Next.js with App Router, TypeScript, and TailwindCSS', | ||
| features: ['Next.js 15', 'App Router', 'TypeScript', 'TailwindCSS', 'SSR support'], | ||
| }, | ||
| { | ||
| id: 'minimal-sdk', | ||
| name: 'Minimal SDK Integration', | ||
| description: 'Minimal setup with just the Nitrolite SDK', | ||
| features: ['TypeScript', 'Minimal setup', 'WebSocket client', 'SDK only'], | ||
| }, | ||
| ]; |
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.
| .description('CLI tool to create new Nitrolite applications') | ||
| .version('1.0.0') | ||
| .argument('[project-directory]', 'directory where the project will be created') | ||
| .option('-t, --template <template>', 'template to use', 'react-vite') |
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.
| @@ -0,0 +1,295 @@ | |||
| import fs from 'fs-extra'; | |||
| import path from 'path'; | |||
| import { execSync } from 'child_process'; | |||
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.
| export async function checkGitAvailability(): Promise<boolean> { | ||
| try { | ||
| execSync('git --version', { stdio: 'ignore' }); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } |
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.
checkGitAvailability is declared as async but uses the synchronous execSync. Use an asynchronous execution method like execa to match the function signature.
| export async function checkGitAvailability(): Promise<boolean> { | |
| try { | |
| execSync('git --version', { stdio: 'ignore' }); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| export async function checkGitAvailability(): Promise<boolean> { | |
| try { | |
| await execa('git', ['--version'], { stdio: 'ignore' }); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } |
| const YellowWebSocketContext = createContext<YellowWebSocketContextType | null>(null); | ||
|
|
||
| interface YellowWebSocketProviderProps { | ||
| children: typeof Children; |
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.
No description provided.