nextjs-route-generator

1.6.0 • Public • Published

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-generator

Usage

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 -r

This will create the following structure:

pages/
└── posts/
    └── [id]/
        ├── page.tsx
        ├── layout.tsx
        └── route.ts

Generate a Route with Specific Files

You can specify which files to generate using the flags:

  • -p for page.tsx or page.jsx
  • -l for layout.tsx or layout.jsx
  • -r for route.ts or route.js

For example, to generate only page.tsx and layout.tsx:

npx next-generate "posts/[id]" -p -l

This will create the following structure:

pages/
└── posts/
    └── [id]/
        ├── page.tsx
        └── layout.tsx

Determining 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: .tsx and .ts
  • For JavaScript: .jsx and .js

License

MIT

Package Sidebar

Install

npm i nextjs-route-generator

Weekly Downloads

1

Version

1.6.0

License

MIT

Unpacked Size

15.4 kB

Total Files

12

Last publish

Collaborators

  • abdelmonaamaouini