build-app-with 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +240 -0
- package/bin/cli.js +18 -0
- package/index.js +3 -0
- package/package.json +80 -0
- package/src/__tests__/core/error-handler.test.js +99 -0
- package/src/__tests__/core/logger.test.js +93 -0
- package/src/__tests__/e2e/cli-integration.test.js +220 -0
- package/src/__tests__/e2e/framework-generation.test.js +249 -0
- package/src/__tests__/setup.js +70 -0
- package/src/config/package-mappings.js +110 -0
- package/src/constants/index.js +42 -0
- package/src/core/error-handler.js +89 -0
- package/src/core/logger.js +89 -0
- package/src/core/package-manager.js +114 -0
- package/src/create-app.js +90 -0
- package/src/generators/express/index.js +52 -0
- package/src/generators/express/project-generator.js +367 -0
- package/src/generators/express/prompts.js +74 -0
- package/src/generators/express/simple-generator.js +275 -0
- package/src/generators/express/templates/app.js +73 -0
- package/src/generators/express/templates/config/database.js +122 -0
- package/src/generators/express/templates/config.js +37 -0
- package/src/generators/express/templates/controllers.js +49 -0
- package/src/generators/express/templates/docker.js +72 -0
- package/src/generators/express/templates/middleware/errorHandler.js +49 -0
- package/src/generators/express/templates/middleware.js +59 -0
- package/src/generators/express/templates/models.js +77 -0
- package/src/generators/express/templates/package-json.js +55 -0
- package/src/generators/express/templates/readme.js +310 -0
- package/src/generators/express/templates/routes.js +36 -0
- package/src/generators/express/templates/server.js +59 -0
- package/src/generators/express/templates/services.js +55 -0
- package/src/generators/express/templates/tests.js +46 -0
- package/src/generators/express/templates/utils/logger.js +54 -0
- package/src/generators/fastify/index.js +46 -0
- package/src/generators/fastify/project-generator.js +373 -0
- package/src/generators/fastify/prompts.js +76 -0
- package/src/generators/fastify/templates/app.js +179 -0
- package/src/generators/fastify/templates/config.js +33 -0
- package/src/generators/fastify/templates/docker.js +73 -0
- package/src/generators/fastify/templates/models.js +77 -0
- package/src/generators/fastify/templates/package-json.js +57 -0
- package/src/generators/fastify/templates/plugins.js +38 -0
- package/src/generators/fastify/templates/readme.js +328 -0
- package/src/generators/fastify/templates/routes.js +32 -0
- package/src/generators/fastify/templates/server.js +71 -0
- package/src/generators/fastify/templates/services.js +50 -0
- package/src/generators/fastify/templates/tests.js +60 -0
- package/src/generators/nextjs/dependency-manager.js +99 -0
- package/src/generators/nextjs/file-generator.js +256 -0
- package/src/generators/nextjs/nextjs-generator.js +177 -0
- package/src/generators/nextjs/nextjs-project-generator.js +896 -0
- package/src/generators/nextjs/package-mappings.js +51 -0
- package/src/generators/nextjs/templates.js +272 -0
- package/src/generators/package-json-generator.js +117 -0
- package/src/generators/vite/components/CreditComponent.jsx +41 -0
- package/src/generators/vite/components/app-component.js +359 -0
- package/src/generators/vite/components/main-file.js +88 -0
- package/src/generators/vite/eslint-config-generator.js +20 -0
- package/src/generators/vite/file-generator.js +796 -0
- package/src/generators/vite/prettier-config-generator.js +10 -0
- package/src/generators/vite/structures/domain-driven-structure.js +465 -0
- package/src/generators/vite/structures/feature-based-structure.js +342 -0
- package/src/generators/vite/structures/simple-structure.js +62 -0
- package/src/generators/vite/styles/index-css.js +130 -0
- package/src/generators/vite/tailwind-config-generator.js +14 -0
- package/src/generators/vite/vite-config-generator.js +22 -0
- package/src/generators/vite/vite-project-generator.js +263 -0
- package/src/generators/vite-project-generator.js +136 -0
- package/src/prompts/index.js +262 -0
- package/src/types/index.js +113 -0
- package/src/utils/answer-helpers.js +24 -0
- package/src/utils/credits.js +192 -0
- package/src/utils/dependencies.js +25 -0
- package/src/utils/messages.js +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 New React App Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# 🚀 New React App - Production-Grade Project Generator
|
|
2
|
+
|
|
3
|
+
A powerful CLI tool that generates production-ready applications with modern frameworks, best practices, and comprehensive boilerplate code.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
### 🎯 Supported Frameworks
|
|
8
|
+
- **Next.js** - Full-stack React framework with App Router
|
|
9
|
+
- **Vite + React** - Lightning-fast frontend development
|
|
10
|
+
- **Express.js** - Production-ready Node.js backend
|
|
11
|
+
- **Fastify** - High-performance Node.js backend
|
|
12
|
+
|
|
13
|
+
### 🛠️ Production-Grade Features
|
|
14
|
+
- **TypeScript Support** - Full TypeScript configuration
|
|
15
|
+
- **Error Handling** - Comprehensive error handling and logging
|
|
16
|
+
- **Security** - Helmet, CORS, rate limiting, input validation
|
|
17
|
+
- **Database Integration** - MongoDB, PostgreSQL, MySQL, SQLite
|
|
18
|
+
- **Authentication** - JWT, Sessions, OAuth strategies
|
|
19
|
+
- **Testing** - Jest, Supertest, comprehensive test setup
|
|
20
|
+
- **Docker Support** - Production-ready containerization
|
|
21
|
+
- **Logging** - Winston logger with structured logging
|
|
22
|
+
- **API Documentation** - Swagger/OpenAPI integration
|
|
23
|
+
- **Code Quality** - ESLint, Prettier, Husky pre-commit hooks
|
|
24
|
+
|
|
25
|
+
### 🎨 Frontend Features
|
|
26
|
+
- **CSS Frameworks** - Tailwind, Bootstrap, MUI, Chakra UI, shadcn/ui
|
|
27
|
+
- **State Management** - Redux Toolkit, Zustand, MobX, Recoil
|
|
28
|
+
- **Data Fetching** - TanStack Query, Axios with interceptors
|
|
29
|
+
- **Forms** - React Hook Form, Formik with validation
|
|
30
|
+
- **Animations** - Framer Motion, React Spring
|
|
31
|
+
- **UI Components** - Ant Design, Material-UI, Chakra UI
|
|
32
|
+
- **Utilities** - React Icons, Toast notifications, i18n
|
|
33
|
+
|
|
34
|
+
### 🔧 Backend Features
|
|
35
|
+
- **Database ORMs** - Prisma, Mongoose, Sequelize
|
|
36
|
+
- **Authentication** - JWT, Passport.js, NextAuth
|
|
37
|
+
- **API Features** - tRPC, GraphQL support
|
|
38
|
+
- **Middleware** - CORS, Helmet, Morgan, Rate limiting
|
|
39
|
+
- **Validation** - Express Validator, Joi, Zod
|
|
40
|
+
- **Documentation** - Swagger/OpenAPI auto-generation
|
|
41
|
+
|
|
42
|
+
## 🚀 Quick Start
|
|
43
|
+
|
|
44
|
+
### Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Install globally
|
|
48
|
+
npm install -g build-app-with
|
|
49
|
+
|
|
50
|
+
# Or use with npx
|
|
51
|
+
npx build-app-with my-awesome-app
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Usage
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Start the interactive CLI
|
|
58
|
+
build-app-with
|
|
59
|
+
|
|
60
|
+
# Or specify project name directly
|
|
61
|
+
build-app-with my-project
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 📁 Project Structure
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
src/
|
|
68
|
+
├── core/ # Core utilities
|
|
69
|
+
│ ├── logger.js # Centralized logging
|
|
70
|
+
│ ├── error-handler.js # Error handling
|
|
71
|
+
│ └── package-manager.js # Package management
|
|
72
|
+
├── generators/ # Framework generators
|
|
73
|
+
│ ├── nextjs/ # Next.js generator
|
|
74
|
+
│ ├── vite/ # Vite + React generator
|
|
75
|
+
│ ├── express/ # Express.js generator
|
|
76
|
+
│ └── fastify/ # Fastify generator
|
|
77
|
+
├── templates/ # Code templates
|
|
78
|
+
├── config/ # Configuration files
|
|
79
|
+
├── types/ # Type definitions
|
|
80
|
+
└── utils/ # Utility functions
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 🎯 Framework-Specific Features
|
|
84
|
+
|
|
85
|
+
### Next.js Generator
|
|
86
|
+
- App Router and Pages Router support
|
|
87
|
+
- Server-side rendering (SSR)
|
|
88
|
+
- Static site generation (SSG)
|
|
89
|
+
- API routes
|
|
90
|
+
- Middleware support
|
|
91
|
+
- Image optimization
|
|
92
|
+
- Font optimization
|
|
93
|
+
- Built-in TypeScript support
|
|
94
|
+
|
|
95
|
+
### Vite + React Generator
|
|
96
|
+
- Lightning-fast HMR
|
|
97
|
+
- Multiple project structures
|
|
98
|
+
- CSS framework integration
|
|
99
|
+
- State management setup
|
|
100
|
+
- Testing configuration
|
|
101
|
+
- Build optimization
|
|
102
|
+
|
|
103
|
+
### Express.js Generator
|
|
104
|
+
- Modular architecture
|
|
105
|
+
- Database integration
|
|
106
|
+
- Authentication strategies
|
|
107
|
+
- Middleware stack
|
|
108
|
+
- Error handling
|
|
109
|
+
- Logging configuration
|
|
110
|
+
- API documentation
|
|
111
|
+
- Docker support
|
|
112
|
+
|
|
113
|
+
### Fastify Generator
|
|
114
|
+
- Plugin-based architecture
|
|
115
|
+
- High performance
|
|
116
|
+
- Schema validation
|
|
117
|
+
- TypeScript support
|
|
118
|
+
- WebSocket support
|
|
119
|
+
- GraphQL integration
|
|
120
|
+
- Rate limiting
|
|
121
|
+
- CORS configuration
|
|
122
|
+
|
|
123
|
+
## 🔧 Configuration
|
|
124
|
+
|
|
125
|
+
### Environment Variables
|
|
126
|
+
|
|
127
|
+
Each generated project includes comprehensive environment configuration:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Server Configuration
|
|
131
|
+
PORT=3000
|
|
132
|
+
NODE_ENV=development
|
|
133
|
+
|
|
134
|
+
# Database Configuration
|
|
135
|
+
DATABASE_URL=your_database_url
|
|
136
|
+
MONGODB_URI=mongodb://localhost:27017/your_db
|
|
137
|
+
|
|
138
|
+
# Authentication
|
|
139
|
+
JWT_SECRET=your_jwt_secret
|
|
140
|
+
JWT_EXPIRES_IN=7d
|
|
141
|
+
|
|
142
|
+
# CORS
|
|
143
|
+
CORS_ORIGIN=http://localhost:3000
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Package Manager Support
|
|
147
|
+
|
|
148
|
+
- **npm** - Default package manager
|
|
149
|
+
- **yarn** - Fast, reliable, and secure
|
|
150
|
+
- **pnpm** - Efficient disk space usage
|
|
151
|
+
|
|
152
|
+
## 🧪 Testing
|
|
153
|
+
|
|
154
|
+
All generated projects include comprehensive testing setup:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Run tests
|
|
158
|
+
npm test
|
|
159
|
+
|
|
160
|
+
# Run tests in watch mode
|
|
161
|
+
npm run test:watch
|
|
162
|
+
|
|
163
|
+
# Generate coverage report
|
|
164
|
+
npm run test:coverage
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 🐳 Docker Support
|
|
168
|
+
|
|
169
|
+
Production-ready Docker configuration:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Build Docker image
|
|
173
|
+
docker build -t my-app .
|
|
174
|
+
|
|
175
|
+
# Run with Docker Compose
|
|
176
|
+
docker-compose up -d
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 📚 Documentation
|
|
180
|
+
|
|
181
|
+
Each generated project includes:
|
|
182
|
+
- Comprehensive README
|
|
183
|
+
- API documentation (Swagger)
|
|
184
|
+
- Code comments and JSDoc
|
|
185
|
+
- Architecture diagrams
|
|
186
|
+
- Deployment guides
|
|
187
|
+
|
|
188
|
+
## 🤝 Contributing
|
|
189
|
+
|
|
190
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
191
|
+
|
|
192
|
+
### Development Setup
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Clone the repository
|
|
196
|
+
git clone https://github.com/imnayakshubham/build-app-with.git
|
|
197
|
+
|
|
198
|
+
# Install dependencies
|
|
199
|
+
npm install
|
|
200
|
+
|
|
201
|
+
# Run in development mode
|
|
202
|
+
npm run dev
|
|
203
|
+
|
|
204
|
+
# Run tests
|
|
205
|
+
npm test
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 📄 License
|
|
209
|
+
|
|
210
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
211
|
+
|
|
212
|
+
## 🙏 Acknowledgments
|
|
213
|
+
|
|
214
|
+
- **Next.js Team** - For the amazing React framework
|
|
215
|
+
- **Vite Team** - For the lightning-fast build tool
|
|
216
|
+
- **Express.js Team** - For the robust Node.js framework
|
|
217
|
+
- **Fastify Team** - For the high-performance Node.js framework
|
|
218
|
+
- **React Community** - For the incredible ecosystem
|
|
219
|
+
|
|
220
|
+
## 📞 Support
|
|
221
|
+
|
|
222
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/imnayakshubham/build-app-with/issues)
|
|
223
|
+
- 💬 Discussions: [GitHub Discussions](https://github.com/imnayakshubham/build-app-with/discussions)
|
|
224
|
+
|
|
225
|
+
## 🚀 Roadmap
|
|
226
|
+
|
|
227
|
+
- [ ] Vue.js support
|
|
228
|
+
- [ ] Svelte support
|
|
229
|
+
- [ ] Angular support
|
|
230
|
+
- [ ] Microservices architecture
|
|
231
|
+
- [ ] Kubernetes deployment
|
|
232
|
+
- [ ] CI/CD pipeline templates
|
|
233
|
+
- [ ] Monitoring and observability
|
|
234
|
+
- [ ] Performance optimization tools
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
**Made with ❤️ by the [Create New App](https://github.com/imnayakshubham/build-app-with)**
|
|
239
|
+
|
|
240
|
+
*Generate production-ready applications in seconds, not hours.*
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createApp } from '../src/create-app.js';
|
|
4
|
+
import { welcomeMessage } from '../src/utils/messages.js';
|
|
5
|
+
import { logger } from '../src/core/logger.js';
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
welcomeMessage();
|
|
9
|
+
await createApp();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
main().catch((error) => {
|
|
13
|
+
logger.error(`Fatal error: ${error.message}`);
|
|
14
|
+
if (logger.isDevelopment) {
|
|
15
|
+
console.error(error.stack);
|
|
16
|
+
}
|
|
17
|
+
process.exit(1);
|
|
18
|
+
});
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "build-app-with",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Production-grade CLI tool to create modern web applications with Next.js, Vite, Express, and Fastify",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"build-app-with": "./bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node ./bin/cli.js",
|
|
12
|
+
"dev": "node ./bin/cli.js",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"test:coverage": "jest --coverage",
|
|
16
|
+
"lint": "eslint src/ --ext .js,.ts",
|
|
17
|
+
"lint:fix": "eslint src/ --ext .js,.ts --fix",
|
|
18
|
+
"format": "prettier --write src/",
|
|
19
|
+
"build": "echo 'No build step required for CLI tool'",
|
|
20
|
+
"prepublishOnly": "npm run test:core && npm run lint",
|
|
21
|
+
"test:core": "jest --testPathPattern=core"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react",
|
|
25
|
+
"nextjs",
|
|
26
|
+
"vite",
|
|
27
|
+
"express",
|
|
28
|
+
"fastify",
|
|
29
|
+
"nodejs",
|
|
30
|
+
"cli",
|
|
31
|
+
"generator",
|
|
32
|
+
"scaffold",
|
|
33
|
+
"boilerplate",
|
|
34
|
+
"production-ready",
|
|
35
|
+
"typescript",
|
|
36
|
+
"fullstack"
|
|
37
|
+
],
|
|
38
|
+
"author": "imnayakshubham",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/imnayakshubham/build-app-with.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/imnayakshubham/build-app-with/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/imnayakshubham/build-app-with#readme",
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"chalk": "^5.6.0",
|
|
50
|
+
"execa": "^9.6.0",
|
|
51
|
+
"fs-extra": "^11.3.1",
|
|
52
|
+
"inquirer": "^8.2.6",
|
|
53
|
+
"ora": "^8.2.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"eslint": "^8.57.0",
|
|
58
|
+
"prettier": "^3.2.5",
|
|
59
|
+
"@types/jest": "^29.5.12",
|
|
60
|
+
"@babel/core": "^7.23.0",
|
|
61
|
+
"@babel/preset-env": "^7.23.0",
|
|
62
|
+
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
|
|
63
|
+
"babel-jest": "^29.7.0"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.0.0",
|
|
67
|
+
"npm": ">=8.0.0"
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"bin/",
|
|
71
|
+
"src/",
|
|
72
|
+
"index.js",
|
|
73
|
+
"README.md",
|
|
74
|
+
"LICENSE"
|
|
75
|
+
],
|
|
76
|
+
"preferGlobal": true,
|
|
77
|
+
"publishConfig": {
|
|
78
|
+
"access": "public"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for error handler utility
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ProjectGeneratorError,
|
|
7
|
+
ValidationError,
|
|
8
|
+
FileSystemError,
|
|
9
|
+
DependencyError,
|
|
10
|
+
validateProjectName,
|
|
11
|
+
validateFramework
|
|
12
|
+
} from '../../core/error-handler.js';
|
|
13
|
+
|
|
14
|
+
describe('Error Handler', () => {
|
|
15
|
+
describe('ProjectGeneratorError', () => {
|
|
16
|
+
it('should create error with message and code', () => {
|
|
17
|
+
const error = new ProjectGeneratorError('Test error', 'TEST_ERROR');
|
|
18
|
+
expect(error.message).toBe('Test error');
|
|
19
|
+
expect(error.code).toBe('TEST_ERROR');
|
|
20
|
+
expect(error.name).toBe('ProjectGeneratorError');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should create error with details', () => {
|
|
24
|
+
const error = new ProjectGeneratorError('Test error', 'TEST_ERROR', { field: 'test' });
|
|
25
|
+
expect(error.details).toEqual({ field: 'test' });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('ValidationError', () => {
|
|
30
|
+
it('should create validation error', () => {
|
|
31
|
+
const error = new ValidationError('Invalid input', 'projectName');
|
|
32
|
+
expect(error.message).toBe('Invalid input');
|
|
33
|
+
expect(error.code).toBe('VALIDATION_ERROR');
|
|
34
|
+
expect(error.name).toBe('ValidationError');
|
|
35
|
+
expect(error.details).toEqual({ field: 'projectName' });
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('FileSystemError', () => {
|
|
40
|
+
it('should create file system error', () => {
|
|
41
|
+
const error = new FileSystemError('File not found', '/path/to/file');
|
|
42
|
+
expect(error.message).toBe('File not found');
|
|
43
|
+
expect(error.code).toBe('FILE_SYSTEM_ERROR');
|
|
44
|
+
expect(error.name).toBe('FileSystemError');
|
|
45
|
+
expect(error.details).toEqual({ path: '/path/to/file' });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('DependencyError', () => {
|
|
50
|
+
it('should create dependency error', () => {
|
|
51
|
+
const error = new DependencyError('Package not found', 'react');
|
|
52
|
+
expect(error.message).toBe('Package not found');
|
|
53
|
+
expect(error.code).toBe('DEPENDENCY_ERROR');
|
|
54
|
+
expect(error.name).toBe('DependencyError');
|
|
55
|
+
expect(error.details).toEqual({ packageName: 'react' });
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('validateProjectName', () => {
|
|
60
|
+
it('should validate valid project name', () => {
|
|
61
|
+
expect(() => validateProjectName('my-app')).not.toThrow();
|
|
62
|
+
expect(() => validateProjectName('my_app')).not.toThrow();
|
|
63
|
+
expect(() => validateProjectName('my-app-123')).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should throw error for invalid project name', () => {
|
|
67
|
+
expect(() => validateProjectName('')).toThrow(ValidationError);
|
|
68
|
+
expect(() => validateProjectName('my app')).toThrow(ValidationError);
|
|
69
|
+
expect(() => validateProjectName('my@app')).toThrow(ValidationError);
|
|
70
|
+
expect(() => validateProjectName('my.app')).toThrow(ValidationError);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should throw error for too long project name', () => {
|
|
74
|
+
const longName = 'a'.repeat(51);
|
|
75
|
+
expect(() => validateProjectName(longName)).toThrow(ValidationError);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should throw error for non-string input', () => {
|
|
79
|
+
expect(() => validateProjectName(null)).toThrow(ValidationError);
|
|
80
|
+
expect(() => validateProjectName(undefined)).toThrow(ValidationError);
|
|
81
|
+
expect(() => validateProjectName(123)).toThrow(ValidationError);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('validateFramework', () => {
|
|
86
|
+
it('should validate valid framework', () => {
|
|
87
|
+
expect(() => validateFramework('nextjs')).not.toThrow();
|
|
88
|
+
expect(() => validateFramework('vite-react')).not.toThrow();
|
|
89
|
+
expect(() => validateFramework('express')).not.toThrow();
|
|
90
|
+
expect(() => validateFramework('fastify')).not.toThrow();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should throw error for invalid framework', () => {
|
|
94
|
+
expect(() => validateFramework('invalid')).toThrow(ValidationError);
|
|
95
|
+
expect(() => validateFramework('')).toThrow(ValidationError);
|
|
96
|
+
expect(() => validateFramework(null)).toThrow(ValidationError);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for logger utility
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { logger } from '../../core/logger.js';
|
|
6
|
+
|
|
7
|
+
describe('Logger', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('info', () => {
|
|
13
|
+
it('should log info message', () => {
|
|
14
|
+
logger.info('Test info message');
|
|
15
|
+
expect(console.log).toHaveBeenCalledWith('ℹ', 'Test info message');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('success', () => {
|
|
20
|
+
it('should log success message', () => {
|
|
21
|
+
logger.success('Test success message');
|
|
22
|
+
expect(console.log).toHaveBeenCalledWith('✓', 'Test success message');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('warning', () => {
|
|
27
|
+
it('should log warning message', () => {
|
|
28
|
+
logger.warning('Test warning message');
|
|
29
|
+
expect(console.log).toHaveBeenCalledWith('⚠', 'Test warning message');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('error', () => {
|
|
34
|
+
it('should log error message', () => {
|
|
35
|
+
logger.error('Test error message');
|
|
36
|
+
expect(console.error).toHaveBeenCalledWith('✗', 'Test error message');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('startSpinner', () => {
|
|
41
|
+
it('should start spinner with message', () => {
|
|
42
|
+
const spinner = logger.startSpinner('Test spinner');
|
|
43
|
+
expect(spinner).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('stopSpinner', () => {
|
|
48
|
+
it('should stop spinner with success', () => {
|
|
49
|
+
logger.startSpinner('Test spinner');
|
|
50
|
+
logger.stopSpinner(true, 'Success message');
|
|
51
|
+
// Spinner methods are mocked, so we just verify they don't throw
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should stop spinner with failure', () => {
|
|
55
|
+
logger.startSpinner('Test spinner');
|
|
56
|
+
logger.stopSpinner(false, 'Error message');
|
|
57
|
+
// Spinner methods are mocked, so we just verify they don't throw
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('logStep', () => {
|
|
62
|
+
it('should log step with progress', () => {
|
|
63
|
+
logger.logStep(1, 3, 'Test step');
|
|
64
|
+
expect(console.log).toHaveBeenCalledWith('[1/3]', 'Test step');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('logCommand', () => {
|
|
69
|
+
it('should log command when isDevelopment is true', () => {
|
|
70
|
+
// Mock the logger's isDevelopment property
|
|
71
|
+
logger.isDevelopment = true;
|
|
72
|
+
logger.isQuiet = false;
|
|
73
|
+
|
|
74
|
+
logger.logCommand('npm install');
|
|
75
|
+
|
|
76
|
+
// Check for chalk styled output
|
|
77
|
+
expect(console.log).toHaveBeenCalledWith('$', 'npm install');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should not log command when not in development', () => {
|
|
81
|
+
jest.clearAllMocks();
|
|
82
|
+
|
|
83
|
+
// Mock the logger's isDevelopment property
|
|
84
|
+
logger.isDevelopment = false;
|
|
85
|
+
logger.isQuiet = false;
|
|
86
|
+
|
|
87
|
+
logger.logCommand('npm install');
|
|
88
|
+
|
|
89
|
+
// Should not have been called
|
|
90
|
+
expect(console.log).not.toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|