create-product-page-cli
v1.0.1
Published
CLI tool to create product page and API route in Next.js projects
Maintainers
Readme
Create Product Page CLI for Next.js
A CLI tool that automatically generates a product creation page and API route for your Next.js application.
Features
- ✅ Creates a styled product form page with name, description, and price fields
- ✅ Creates an API route with validation for handling product creation
- ✅ Checks for existing files before overwriting
- ✅ TypeScript support
- ✅ Works with Next.js App Router
Installation
Global Installation
npm install -g create-product-page-cliLocal Installation
npm install create-product-page-cli --save-devUsage
Run the CLI tool in your Next.js project directory:
npx create-product-page-cliThe CLI will:
- Check if you're in a Next.js project
- Look for existing files and ask if you want to overwrite them
- Generate the necessary files:
src/app/products/page.tsx- Product creation form pagesrc/app/api/products/route.ts- API route for handling POST requests
After running the CLI, you can access your product creation page at:
http://localhost:3000/productsGenerated Files
Product Page (page.tsx)
A React component with a form for creating products, including:
- Input fields for name, description, and price
- Form validation
- Styled with simple CSS classes
- Responsive design
- Form submission handling
API Route (route.ts)
A Next.js API route that handles POST requests for product creation, including:
- Request validation
- TypeScript interfaces
- Error handling
- Response formatting
Documentation
For more detailed information, check out these documentation files:
- Detailed Usage Guide - Comprehensive usage instructions
- Publishing Guide - How to publish this package to npm
Development
If you want to contribute to this project:
- Clone the repository
- Install dependencies:
npm install - Build the project:
npm run build - Link for local development:
npm link - Run tests:
npm test
Project Structure
my-cli-tool/
├── bin/
│ └── cli.js # Main CLI tool file that handles execution
├── src/
│ ├── createProductPage.ts # Wrapper for product page generator
│ ├── createApiRoute.ts # Wrapper for API route generator
│ ├── index.ts # Main export file
│ ├── utils.ts # Utility functions
│ └── generators/ # Generator classes (following SOLID principles)
│ ├── baseGenerator.ts # Abstract base generator
│ ├── productPageGenerator.ts # Concrete product page generator
│ └── apiRouteGenerator.ts # Concrete API route generator
├── tests/ # Tests
├── dist/ # Compiled TypeScript
├── package.json # NPM package configuration
└── tsconfig.json # TypeScript configurationSOLID Principles Implementation
This project follows SOLID principles:
- Single Responsibility: Each class has a single responsibility
- Open/Closed: BaseGenerator can be extended without modification
- Liskov Substitution: Concrete generators can be used interchangeably
- Interface Segregation: Clean interfaces with only necessary methods
- Dependency Inversion: High-level modules depend on abstractions
License
MIT
