I created this tool, because my stack is Nest.js and Next.js, and I wanted to create a CLI tool for Next.js like Nest. Currently works as a standalone package, but I am planning to integrate the official next cli into this tool.
npm install -g @iamendor/next-cli
You can create a configuration file to configure the cli.
next init config
The CLI does not require to use the configuration file, but I recommend to configure it per project to configure the extension, styling and etc. See the example configuration file here.
Initialize configuration file
Generate Next.js templates, in every subcommand you have to specify a path and also you can specify extension, if you specify it in the command line, the configuration file arguments will be overriden.
If you want to use typescript, specify
--ts
flag in command route and middleware or
--tsx
in command module, page, loading, error, layout, notfound and component
next generate module <path>
Generate a Next.js module, this includes a page, loading, error, and not found pages, you can also include a layout file, creates a style file for every file.
-
--layout
- create layout file -
--error
,--no-error
- create error file -
--loading
,--no-loading
- create loading file -
--not-found
,--no-not-found
- create not found file -
--style
,--no-style
- specify style files, available options: css, scss, or if you want to use tailwind specify--no-style
flag, you can also specify--scss
flag to use scss as styling -
--merge-styles
- create one style file -
--type
- specify the route type, available options: default, dynamic, parallel, intercepting, if you want to create these type of route specify it in the flag, do not use in the path, it gives an error, this can be a future feature.
You can also specify it with prefixed flags like--dynamic
,--parallel
,--intercepting
-
--level
- if you use--intercepting
flag, specify the level of the interception, available options: 0, 1, 2, root
next generate page <path>
Generate a page file
next generate layout <path>
Generate a layout file
next generate error <path>
Generate an error file
next generate loading <path>
Generate an loading file
next generate notfound <path>
Generate a not found file
next generate component <path>
Generate a component file, unlike the router components, this file is generated by the last part of the path, so if you provide g c foo/bar
, this creates foo/Bar.jsx
next generate route <path>
Generate a route file
-
--type
- see in module, available options: default, dynamic, flag--dynamic
is also available -
--handlers
- List of handlers to create, available options: GET, POST, PUT, PATCH, DELETE.
You can also specify--GET
,--POST
flags to add these handlers -
--single-handler
- Create a global handler for route
next generate middleware <path>
Generate a middleware file
-
--matcher
- specify matcher for the middleware, see the usage here -
--global
- make the middleware global