A CLI tool to quickly scaffold Next.js components with TypeScript support, optional CSS modules, and unit tests.
Install the package globally:
$ npm install -g next-comp-cliNavigate to your Next.js project directory and run:
$ gncFollow the prompts to specify:
- Component name
- Whether to include React hooks
- Whether to add a CSS module for styling
- Props for the component (comma-separated list)
When prompted for props, you can enter a comma-separated list of property names (e.g., title, onClick, disabled). Each prop will be typed as string by default in the generated component file. You can easily update the types later if different types are needed.
$ gnc
✔ What is the name of your component? Button
✔ Do you want to include React hooks? yes
✔ Do you want to include a CSS module? yes
✔ List component props (comma-separated, e.g., name:string, age:number): label: string, onClick: () => void, disabled: boolean
Component Button generated successfully!This will generate a folder components/Button with:
Button.tsxButton.module.cssButton.test.tsx
In Button.tsx, the interface ButtonProps will include the specified props;
interface ButtonProps {
label: string;
onClick: () => void;
disabled: boolean;
}To set up the project for development:
- Clone the repository
- Install the dependencies
$ npm install- Build the project
$ npm run build- Link the package locally for testing
$ npm linkNow you can run gnc locally to test any changes.