1.6.0 • Published 1 year ago
nextjs-route-generator v1.6.0
Next.js Route Generator
A CLI tool to generate pages/layouts/routes for Next.js projects.
Installation
You can install the CLI globally using npm:
npm install -g nextjs-route-generatorUsage
To generate a route, use the next-generate command followed by the route path. You can also specify which files to create using the flags.
Generate a Route with All Files
npx next-generate "posts/[id]" -p -l -rThis will create the following structure:
pages/
└── posts/
└── [id]/
├── page.tsx
├── layout.tsx
└── route.tsGenerate a Route with Specific Files
You can specify which files to generate using the flags:
-pforpage.tsxorpage.jsx-lforlayout.tsxorlayout.jsx-rforroute.tsorroute.js
For example, to generate only page.tsx and layout.tsx:
npx next-generate "posts/[id]" -p -lThis will create the following structure:
pages/
└── posts/
└── [id]/
├── page.tsx
└── layout.tsxDetermining Project Type
The tool automatically determines whether your project is using TypeScript or JavaScript based on the presence of tsconfig.json in your project root. It will generate files with appropriate extensions:
- For TypeScript:
.tsxand.ts - For JavaScript:
.jsxand.js
License
MIT