nsgm-cli 2.1.12 → 2.1.14
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/README.md +369 -163
- package/client/components/Button.tsx +3 -5
- package/client/components/__tests__/Button.test.tsx +10 -10
- package/client/layout/index.tsx +149 -137
- package/client/redux/reducers.ts +1 -1
- package/client/redux/store.ts +2 -1
- package/client/redux/template/manage/actions.ts +77 -88
- package/client/redux/template/manage/reducers.ts +25 -37
- package/client/redux/template/manage/types.ts +1 -1
- package/client/service/template/manage.ts +20 -21
- package/client/styled/common.ts +12 -13
- package/client/styled/layout/index.ts +19 -19
- package/client/styled/template/manage.ts +14 -13
- package/client/utils/common.ts +23 -21
- package/client/utils/cookie.ts +18 -19
- package/client/utils/fetch.ts +64 -100
- package/client/utils/menu.tsx +16 -3
- package/client/utils/sso.ts +74 -84
- package/eslint.config.js +38 -1
- package/generation/README.md +25 -18
- package/generation/__tests__/example.test.js +41 -0
- package/generation/client/utils/menu.tsx +9 -2
- package/generation/env.example +3 -0
- package/generation/eslint.config.js +112 -0
- package/generation/gitignore +6 -1
- package/generation/jest.config.js +40 -0
- package/generation/package.json +25 -4
- package/jest.config.js +23 -6
- package/lib/args.js +9 -1
- package/lib/cli/app.d.ts +28 -0
- package/lib/cli/app.js +99 -0
- package/lib/cli/commands/build.d.ts +2 -0
- package/lib/cli/commands/build.js +29 -0
- package/lib/cli/commands/create.d.ts +2 -0
- package/lib/cli/commands/create.js +113 -0
- package/lib/cli/commands/delete.d.ts +3 -0
- package/lib/cli/commands/delete.js +151 -0
- package/lib/cli/commands/export.d.ts +2 -0
- package/lib/cli/commands/export.js +42 -0
- package/lib/cli/commands/help.d.ts +2 -0
- package/lib/cli/commands/help.js +42 -0
- package/lib/cli/commands/init.d.ts +2 -0
- package/lib/cli/commands/init.js +115 -0
- package/lib/cli/commands/server.d.ts +3 -0
- package/lib/cli/commands/server.js +26 -0
- package/lib/cli/commands/upgrade.d.ts +2 -0
- package/lib/cli/commands/upgrade.js +38 -0
- package/lib/cli/commands/version.d.ts +2 -0
- package/lib/cli/commands/version.js +24 -0
- package/lib/cli/index.d.ts +16 -0
- package/lib/cli/index.js +33 -0
- package/lib/cli/parser.d.ts +22 -0
- package/lib/cli/parser.js +115 -0
- package/lib/cli/registry.d.ts +33 -0
- package/lib/cli/registry.js +81 -0
- package/lib/cli/types/project.d.ts +10 -0
- package/lib/cli/types/project.js +2 -0
- package/lib/cli/types.d.ts +31 -0
- package/lib/cli/types.js +20 -0
- package/lib/cli/utils/console.d.ts +62 -0
- package/lib/cli/utils/console.js +148 -0
- package/lib/cli/utils/index.d.ts +2 -0
- package/lib/cli/utils/index.js +7 -0
- package/lib/cli/utils/prompt.d.ts +83 -0
- package/lib/cli/utils/prompt.js +368 -0
- package/lib/constants.d.ts +58 -0
- package/lib/constants.js +162 -0
- package/lib/generate.d.ts +25 -3
- package/lib/generate.js +97 -621
- package/lib/generate_create.d.ts +9 -0
- package/lib/generate_create.js +326 -0
- package/lib/generate_delete.d.ts +8 -0
- package/lib/generate_delete.js +156 -0
- package/lib/generate_init.d.ts +50 -0
- package/lib/generate_init.js +492 -0
- package/lib/generators/base-generator.d.ts +47 -0
- package/lib/generators/base-generator.js +92 -0
- package/lib/generators/generator-factory.d.ts +20 -0
- package/lib/generators/generator-factory.js +25 -0
- package/lib/generators/page-generator.d.ts +41 -0
- package/lib/generators/page-generator.js +552 -0
- package/lib/generators/resolver-generator.d.ts +12 -0
- package/lib/generators/resolver-generator.js +303 -0
- package/lib/generators/schema-generator.d.ts +7 -0
- package/lib/generators/schema-generator.js +57 -0
- package/lib/generators/service-generator.d.ts +7 -0
- package/lib/generators/service-generator.js +119 -0
- package/lib/generators/sql-generator.d.ts +8 -0
- package/lib/generators/sql-generator.js +52 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -193
- package/lib/server/csrf.js +9 -16
- package/lib/server/db.js +6 -7
- package/lib/server/graphql.js +5 -6
- package/lib/server/plugins/date.js +1 -1
- package/lib/server/utils/graphql-cache.js +3 -3
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +5 -0
- package/lib/utils/project-config.js +145 -0
- package/lib/utils.js +1 -1
- package/next.config.js +12 -8
- package/package.json +10 -7
- package/pages/_app.tsx +23 -28
- package/pages/_document.tsx +39 -19
- package/pages/index.tsx +84 -39
- package/pages/login.tsx +21 -21
- package/pages/template/manage.tsx +114 -89
- package/public/fonts/font-awesome.min.css +4 -0
- package/public/fonts/fontawesome-webfont.woff +0 -0
- package/public/fonts/fontawesome-webfont.woff2 +0 -0
- package/public/slbhealthcheck.html +1 -1
- package/server/apis/template.js +0 -2
- package/generation/eslintrc.js +0 -16
package/README.md
CHANGED
|
@@ -1,246 +1,452 @@
|
|
|
1
1
|
# NSGM CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [
|
|
10
|
-
- [MySQL](https://www.mysql.com/) - Relational database
|
|
10
|
+
**A powerful full-stack development framework with intelligent code generation**
|
|
11
|
+
|
|
12
|
+
[Installation](#installation) • [Quick Start](#quick-start) • [Features](#features) • [Documentation](#documentation) • [Contributing](#contributing)
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
</div>
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
- Automatic code template generation
|
|
16
|
-
- Rapid development workflow
|
|
17
|
-
- Integrated GraphQL API
|
|
18
|
-
- MySQL database support
|
|
19
|
-
- Secure login system with bcrypt encryption
|
|
16
|
+
## 🚀 Overview
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
NSGM CLI is a comprehensive full-stack development framework that combines the power of modern web technologies with intelligent code generation capabilities. It helps developers rapidly build scalable web applications through an interactive CLI wizard and automated code templates.
|
|
22
19
|
|
|
23
|
-
###
|
|
20
|
+
### 🏗️ Architecture
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| `nsgm dev` | Development mode |
|
|
34
|
-
| `nsgm start` | Production mode |
|
|
35
|
-
| `nsgm build` | Build project |
|
|
36
|
-
| `nsgm export` | Export static pages |
|
|
22
|
+
```
|
|
23
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
24
|
+
│ Frontend │ │ Backend │ │ Database │
|
|
25
|
+
│ Next.js │◄──►│ Express.js │◄──►│ MySQL │
|
|
26
|
+
│ React │ │ GraphQL │ │ Native SQL │
|
|
27
|
+
│ Styled-Comp │ │ REST API │ │ Relations │
|
|
28
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
29
|
+
```
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
## 🎯 Key Features
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
### 🧙♂️ **Intelligent CLI Wizard**
|
|
34
|
+
- **Smart Mode Detection**: Automatically switches between interactive and command-line modes
|
|
35
|
+
- **Beginner-Friendly**: Step-by-step guided setup for newcomers
|
|
36
|
+
- **Expert-Efficient**: Quick command-line shortcuts for experienced developers
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
38
|
+
### ⚡ **Rapid Development**
|
|
39
|
+
- **Code Generation**: Automatic CRUD operations, API endpoints, and database schemas
|
|
40
|
+
- **Hot Reload**: Instant development feedback
|
|
41
|
+
- **Type Safety**: Full TypeScript support throughout the stack
|
|
47
42
|
|
|
48
|
-
- **
|
|
43
|
+
### 🔒 **Production-Ready Security**
|
|
44
|
+
- **CSRF Protection**: Built-in cross-site request forgery prevention
|
|
45
|
+
- **Password Encryption**: bcrypt-based secure authentication
|
|
46
|
+
- **Session Management**: Robust user session handling
|
|
47
|
+
- **CSP Headers**: Content Security Policy implementation
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
### 🏗️ **Modern Tech Stack**
|
|
50
|
+
- **Frontend**: Next.js 13+, React 18+, Styled-components, Redux Toolkit
|
|
51
|
+
- **Backend**: Express.js, GraphQL, REST APIs
|
|
52
|
+
- **Database**: MySQL with native drivers
|
|
53
|
+
- **DevTools**: TypeScript, ESLint, Prettier, Jest
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
```
|
|
56
|
-
nsgm create math test
|
|
57
|
-
```
|
|
55
|
+
## 📦 Installation
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
nsgm password yourSecurePassword
|
|
62
|
-
```
|
|
57
|
+
### Global Installation (Recommended)
|
|
63
58
|
|
|
64
|
-
|
|
59
|
+
```bash
|
|
60
|
+
# Using npm
|
|
61
|
+
npm install -g nsgm-cli
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
# Using yarn
|
|
64
|
+
yarn global add nsgm-cli
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
# Using pnpm
|
|
67
|
+
pnpm add -g nsgm-cli
|
|
68
|
+
```
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
### Verify Installation
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
# Or using nsgm directly
|
|
77
|
-
nsgm password yourSecurePassword
|
|
78
|
-
```
|
|
72
|
+
```bash
|
|
73
|
+
nsgm --version
|
|
74
|
+
# Should output: 2.1.13
|
|
75
|
+
```
|
|
79
76
|
|
|
80
|
-
|
|
77
|
+
## 🚀 Quick Start
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
LOGIN_USERNAME=admin
|
|
84
|
-
LOGIN_PASSWORD_HASH=your_generated_hash_here
|
|
85
|
-
```
|
|
79
|
+
### 1. Initialize Your First Project
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
```bash
|
|
82
|
+
# Start the interactive wizard (recommended for beginners)
|
|
83
|
+
nsgm init
|
|
88
84
|
|
|
89
|
-
|
|
85
|
+
# Or specify project name directly
|
|
86
|
+
nsgm init my-awesome-app
|
|
87
|
+
```
|
|
90
88
|
|
|
91
|
-
|
|
89
|
+
The wizard will guide you through:
|
|
90
|
+
- ✅ Project name and directory
|
|
91
|
+
- ✅ Database configuration
|
|
92
|
+
- ✅ Security settings
|
|
93
|
+
- ✅ Initial controller setup
|
|
92
94
|
|
|
93
|
-
###
|
|
95
|
+
### 2. Environment Setup
|
|
94
96
|
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
const projectConfig = require('./project.config')
|
|
97
|
+
```bash
|
|
98
|
+
cd your-project-name
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
# Copy environment template
|
|
101
|
+
cp .env.example .env
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
version,
|
|
104
|
-
prefix,
|
|
105
|
-
protocol,
|
|
106
|
-
host
|
|
107
|
-
})
|
|
103
|
+
# Generate secure password hash
|
|
104
|
+
npm run generate-password your-secure-password
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
# Edit .env file with generated hash
|
|
107
|
+
nano .env
|
|
111
108
|
```
|
|
112
109
|
|
|
113
|
-
###
|
|
110
|
+
### 3. Start Development
|
|
114
111
|
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
```bash
|
|
113
|
+
# Install dependencies
|
|
114
|
+
npm install
|
|
115
|
+
|
|
116
|
+
# Start development server
|
|
117
|
+
npm run dev
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Your application will be available at `http://localhost:3000` with:
|
|
121
|
+
- 🎛️ Admin dashboard with CRUD interface
|
|
122
|
+
- 📊 Data import/export functionality
|
|
123
|
+
- 🗑️ Batch operations support
|
|
124
|
+
- 🔐 Secure login system
|
|
125
|
+
|
|
126
|
+
## 🛠️ CLI Commands
|
|
127
|
+
|
|
128
|
+
### Core Commands
|
|
129
|
+
|
|
130
|
+
| Command | Description | Mode | Example |
|
|
131
|
+
|---------|-------------|------|---------|
|
|
132
|
+
| `nsgm init` | Initialize new project | Interactive/CLI | `nsgm init blog-app` |
|
|
133
|
+
| `nsgm create` | Generate controller with CRUD | Interactive/CLI | `nsgm create user` |
|
|
134
|
+
| `nsgm delete` | Remove controller and files | Interactive/CLI | `nsgm delete product` |
|
|
135
|
+
| `nsgm dev` | Start development server | CLI | `nsgm dev` |
|
|
136
|
+
| `nsgm build` | Build for production | CLI | `nsgm build` |
|
|
137
|
+
| `nsgm start` | Start production server | CLI | `nsgm start` |
|
|
138
|
+
|
|
139
|
+
### Advanced Commands
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Database operations
|
|
143
|
+
nsgm deletedb user # Delete controller + database table
|
|
144
|
+
|
|
145
|
+
# Project maintenance
|
|
146
|
+
nsgm upgrade # Upgrade project base files
|
|
147
|
+
nsgm export # Export static pages
|
|
148
|
+
|
|
149
|
+
# Development tools
|
|
150
|
+
npm run lint # Code linting
|
|
151
|
+
npm run test # Run tests
|
|
152
|
+
npm run test:coverage # Test coverage report
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 🎨 Generated Controller Features
|
|
156
|
+
|
|
157
|
+
Each controller created with `nsgm create` includes:
|
|
119
158
|
|
|
159
|
+
### 🔧 **Backend Components**
|
|
160
|
+
- **GraphQL Schema**: Typed queries and mutations
|
|
161
|
+
- **GraphQL Resolvers**: Business logic implementation
|
|
162
|
+
- **REST API Endpoints**: RESTful service layer
|
|
163
|
+
- **Database Models**: MySQL schema definitions
|
|
164
|
+
- **Data Validation**: Input sanitization and validation
|
|
165
|
+
|
|
166
|
+
### 🎯 **Frontend Components**
|
|
167
|
+
- **React Components**: Modern functional components with hooks
|
|
168
|
+
- **Styled Components**: CSS-in-JS styling
|
|
169
|
+
- **Redux Integration**: State management
|
|
170
|
+
- **Form Handling**: Create, edit, and validation forms
|
|
171
|
+
- **Data Tables**: Sortable, filterable data grids
|
|
172
|
+
|
|
173
|
+
### 📊 **CRUD Operations**
|
|
174
|
+
- **Create**: Add new records with validation
|
|
175
|
+
- **Read**: List, search, and pagination
|
|
176
|
+
- **Update**: Edit existing records
|
|
177
|
+
- **Delete**: Single and batch deletion
|
|
178
|
+
- **Import/Export**: CSV and JSON data handling
|
|
179
|
+
|
|
180
|
+
## 🏗️ Project Structure
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
your-project/
|
|
184
|
+
├── client/ # Frontend code
|
|
185
|
+
│ ├── components/ # React components
|
|
186
|
+
│ ├── layout/ # Layout components
|
|
187
|
+
│ ├── redux/ # State management
|
|
188
|
+
│ ├── service/ # API services
|
|
189
|
+
│ ├── styled/ # Styled components
|
|
190
|
+
│ └── utils/ # Utility functions
|
|
191
|
+
├── server/ # Backend code
|
|
192
|
+
│ ├── apis/ # REST API routes
|
|
193
|
+
│ ├── modules/ # GraphQL modules
|
|
194
|
+
│ ├── sql/ # Database scripts
|
|
195
|
+
│ └── utils/ # Server utilities
|
|
196
|
+
├── pages/ # Next.js pages
|
|
197
|
+
├── public/ # Static assets
|
|
198
|
+
├── scripts/ # Build and deployment scripts
|
|
199
|
+
├── __tests__/ # Test files
|
|
200
|
+
├── .env.example # Environment template
|
|
201
|
+
├── next.config.js # Next.js configuration
|
|
202
|
+
├── mysql.config.js # Database configuration
|
|
203
|
+
└── package.json # Dependencies
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## ⚙️ Configuration
|
|
207
|
+
|
|
208
|
+
### Environment Variables
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# .env file
|
|
212
|
+
NODE_ENV=development
|
|
213
|
+
LOGIN_USERNAME=admin
|
|
214
|
+
LOGIN_PASSWORD_HASH=your_generated_hash
|
|
215
|
+
DATABASE_URL=mysql://user:password@localhost:3306/dbname
|
|
216
|
+
|
|
217
|
+
# Optional
|
|
218
|
+
PORT=3000
|
|
219
|
+
NEXT_PUBLIC_API_URL=http://localhost:3000
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Database Configuration
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
// mysql.config.js
|
|
120
226
|
module.exports = {
|
|
121
227
|
mysqlOptions: {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
database
|
|
228
|
+
host: process.env.DB_HOST || 'localhost',
|
|
229
|
+
port: process.env.DB_PORT || 3306,
|
|
230
|
+
user: process.env.DB_USER || 'root',
|
|
231
|
+
password: process.env.DB_PASSWORD || '',
|
|
232
|
+
database: process.env.DB_NAME || 'nsgm_db'
|
|
127
233
|
}
|
|
128
234
|
}
|
|
129
235
|
```
|
|
130
236
|
|
|
131
|
-
|
|
237
|
+
## 🔒 Security Setup
|
|
132
238
|
|
|
133
|
-
|
|
134
|
-
const { projectConfig } = require('nsgm-cli')
|
|
135
|
-
const pkg = require('./package.json')
|
|
239
|
+
### Password Generation
|
|
136
240
|
|
|
137
|
-
|
|
138
|
-
|
|
241
|
+
```bash
|
|
242
|
+
# Generate secure hash
|
|
243
|
+
npm run generate-password your-secure-password
|
|
139
244
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
prefix,
|
|
143
|
-
protocol,
|
|
144
|
-
host,
|
|
145
|
-
port
|
|
146
|
-
}
|
|
245
|
+
# Add to .env file
|
|
246
|
+
LOGIN_PASSWORD_HASH=your_generated_hash_here
|
|
147
247
|
```
|
|
148
248
|
|
|
149
|
-
|
|
249
|
+
### CSRF Protection
|
|
150
250
|
|
|
151
|
-
|
|
251
|
+
NSGM CLI includes built-in CSRF protection:
|
|
152
252
|
|
|
153
|
-
|
|
253
|
+
```javascript
|
|
254
|
+
// Automatic CSRF token generation
|
|
255
|
+
app.use(csrfProtection)
|
|
256
|
+
|
|
257
|
+
// Custom CSP headers
|
|
258
|
+
app.use(createCSPMiddleware({
|
|
259
|
+
directives: {
|
|
260
|
+
defaultSrc: ["'self'"],
|
|
261
|
+
styleSrc: ["'self'", "'unsafe-inline'"],
|
|
262
|
+
scriptSrc: ["'self'"]
|
|
263
|
+
}
|
|
264
|
+
}))
|
|
265
|
+
```
|
|
154
266
|
|
|
155
|
-
|
|
156
|
-
- `modules/` - Stores GraphQL resolvers and schemas
|
|
157
|
-
- `plugins/` - Stores GraphQL plugins
|
|
158
|
-
- `*.js` - Route files
|
|
267
|
+
## 🧪 Testing
|
|
159
268
|
|
|
160
|
-
|
|
269
|
+
```bash
|
|
270
|
+
# Run all tests
|
|
271
|
+
npm test
|
|
161
272
|
|
|
162
|
-
|
|
273
|
+
# Watch mode
|
|
274
|
+
npm run test:watch
|
|
163
275
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const moment = require('moment')
|
|
276
|
+
# Coverage report
|
|
277
|
+
npm run test:coverage
|
|
167
278
|
|
|
168
|
-
|
|
279
|
+
# Lint code
|
|
280
|
+
npm run lint
|
|
169
281
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
next()
|
|
174
|
-
})
|
|
282
|
+
# Format code
|
|
283
|
+
npm run format
|
|
284
|
+
```
|
|
175
285
|
|
|
176
|
-
|
|
177
|
-
res.statusCode = 200
|
|
178
|
-
res.json({ name: 'TEST' })
|
|
179
|
-
})
|
|
286
|
+
## 📚 Examples
|
|
180
287
|
|
|
181
|
-
|
|
288
|
+
### Creating a Blog System
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
# 1. Initialize project
|
|
292
|
+
nsgm init my-blog
|
|
293
|
+
|
|
294
|
+
# 2. Create controllers
|
|
295
|
+
cd my-blog
|
|
296
|
+
nsgm create post
|
|
297
|
+
nsgm create category
|
|
298
|
+
nsgm create user
|
|
299
|
+
|
|
300
|
+
# 3. Start development
|
|
301
|
+
npm run dev
|
|
182
302
|
```
|
|
183
303
|
|
|
184
|
-
|
|
304
|
+
### Adding Custom API Endpoint
|
|
185
305
|
|
|
186
306
|
```javascript
|
|
307
|
+
// server/apis/custom.js
|
|
187
308
|
const express = require('express')
|
|
188
309
|
const router = express.Router()
|
|
189
310
|
|
|
190
|
-
router.get('
|
|
191
|
-
res.
|
|
192
|
-
|
|
311
|
+
router.get('/stats', (req, res) => {
|
|
312
|
+
res.json({
|
|
313
|
+
totalPosts: 42,
|
|
314
|
+
totalUsers: 15,
|
|
315
|
+
lastUpdate: new Date()
|
|
316
|
+
})
|
|
193
317
|
})
|
|
194
318
|
|
|
195
319
|
module.exports = router
|
|
196
320
|
```
|
|
197
321
|
|
|
198
|
-
|
|
322
|
+
### Custom GraphQL Schema
|
|
199
323
|
|
|
200
324
|
```javascript
|
|
325
|
+
// server/modules/blog/schema.js
|
|
201
326
|
module.exports = {
|
|
202
327
|
query: `
|
|
203
|
-
|
|
204
|
-
|
|
328
|
+
posts(limit: Int, offset: Int): [Post]
|
|
329
|
+
post(id: ID!): Post
|
|
330
|
+
`,
|
|
205
331
|
mutation: `
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
332
|
+
createPost(title: String!, content: String!): Post
|
|
333
|
+
updatePost(id: ID!, title: String, content: String): Post
|
|
334
|
+
deletePost(id: ID!): Boolean
|
|
335
|
+
`,
|
|
336
|
+
type: `
|
|
337
|
+
type Post {
|
|
338
|
+
id: ID!
|
|
339
|
+
title: String!
|
|
340
|
+
content: String!
|
|
341
|
+
createdAt: Date!
|
|
342
|
+
updatedAt: Date!
|
|
343
|
+
}
|
|
344
|
+
`
|
|
210
345
|
}
|
|
211
346
|
```
|
|
212
347
|
|
|
213
|
-
|
|
348
|
+
## 🚀 Performance & Production
|
|
214
349
|
|
|
215
|
-
|
|
216
|
-
let localLink = ''
|
|
350
|
+
### Build Optimization
|
|
217
351
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
352
|
+
```bash
|
|
353
|
+
# Production build
|
|
354
|
+
npm run build
|
|
355
|
+
|
|
356
|
+
# Analyze bundle size
|
|
357
|
+
npm run analyze
|
|
358
|
+
|
|
359
|
+
# Export static site
|
|
360
|
+
npm run export
|
|
228
361
|
```
|
|
229
362
|
|
|
230
|
-
|
|
363
|
+
### Production Deployment
|
|
231
364
|
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
serialize: (value) => moment(value).format('YYYY-MM-DD HH:mm:ss:SSS'),
|
|
242
|
-
parseLiteral: (ast) => (ast.kind === Kind.INT ? parseInt(ast.value, 10) : null)
|
|
243
|
-
})
|
|
365
|
+
```bash
|
|
366
|
+
# Start production server
|
|
367
|
+
npm start
|
|
368
|
+
|
|
369
|
+
# Or use PM2
|
|
370
|
+
pm2 start npm --name "nsgm-app" -- start
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## 🤝 Contributing
|
|
244
374
|
|
|
245
|
-
|
|
375
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
376
|
+
|
|
377
|
+
### Development Setup
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
# Clone repository
|
|
381
|
+
git clone https://github.com/erishen/nsgm.git
|
|
382
|
+
cd nsgm
|
|
383
|
+
|
|
384
|
+
# Install dependencies
|
|
385
|
+
npm install
|
|
386
|
+
|
|
387
|
+
# Run tests
|
|
388
|
+
npm test
|
|
389
|
+
|
|
390
|
+
# Build CLI
|
|
391
|
+
npm run tsbuild
|
|
246
392
|
```
|
|
393
|
+
|
|
394
|
+
## 📖 Documentation
|
|
395
|
+
|
|
396
|
+
- [Security Guide](SECURITY.md) - Security best practices
|
|
397
|
+
- [API Reference](docs/api.md) - Complete API documentation
|
|
398
|
+
- [Migration Guide](docs/migration.md) - Upgrade instructions
|
|
399
|
+
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
|
|
400
|
+
|
|
401
|
+
## 🐛 Troubleshooting
|
|
402
|
+
|
|
403
|
+
### Common Issues
|
|
404
|
+
|
|
405
|
+
**Port already in use**
|
|
406
|
+
```bash
|
|
407
|
+
# Kill process on port 3000
|
|
408
|
+
lsof -ti:3000 | xargs kill -9
|
|
409
|
+
|
|
410
|
+
# Or use different port
|
|
411
|
+
PORT=3001 npm run dev
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**Database connection failed**
|
|
415
|
+
```bash
|
|
416
|
+
# Check MySQL service
|
|
417
|
+
sudo systemctl status mysql
|
|
418
|
+
|
|
419
|
+
# Verify credentials in .env
|
|
420
|
+
cat .env | grep DB_
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
**Permission denied**
|
|
424
|
+
```bash
|
|
425
|
+
# Fix npm permissions
|
|
426
|
+
sudo chown -R $(whoami) ~/.npm
|
|
427
|
+
|
|
428
|
+
# Or use different install location
|
|
429
|
+
npm config set prefix '~/.local'
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
## 📄 License
|
|
433
|
+
|
|
434
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
435
|
+
|
|
436
|
+
## 🙏 Acknowledgments
|
|
437
|
+
|
|
438
|
+
- [Next.js](https://nextjs.org/) - React framework
|
|
439
|
+
- [GraphQL](https://graphql.org/) - Query language
|
|
440
|
+
- [Styled Components](https://styled-components.com/) - CSS-in-JS
|
|
441
|
+
- [MySQL](https://www.mysql.com/) - Relational database
|
|
442
|
+
|
|
443
|
+
---
|
|
444
|
+
|
|
445
|
+
<div align="center">
|
|
446
|
+
|
|
447
|
+
**Made with ❤️ by the NSGM Team**
|
|
448
|
+
|
|
449
|
+
[GitHub](https://github.com/erishen/nsgm) • [npm](https://www.npmjs.com/package/nsgm-cli) • [Issues](https://github.com/erishen/nsgm/issues)
|
|
450
|
+
|
|
451
|
+
</div>
|
|
452
|
+
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// src/components/Button.js
|
|
2
|
-
import React from 'react'
|
|
2
|
+
import React from 'react'
|
|
3
3
|
|
|
4
|
-
const Button = ({ onClick, children }) =>
|
|
5
|
-
<button onClick={onClick}>{children}</button>
|
|
6
|
-
);
|
|
4
|
+
const Button = ({ onClick, children }) => <button onClick={onClick}>{children}</button>
|
|
7
5
|
|
|
8
|
-
export default Button
|
|
6
|
+
export default Button
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/components/Button.test.js
|
|
2
|
-
import { render, screen, fireEvent } from '@testing-library/react'
|
|
3
|
-
import Button from '../Button'
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react'
|
|
3
|
+
import Button from '../Button'
|
|
4
4
|
|
|
5
5
|
test('renders button with text', () => {
|
|
6
|
-
render(<Button>Click me</Button>)
|
|
7
|
-
expect(screen.getByText('Click me')).toBeInTheDocument()
|
|
8
|
-
})
|
|
6
|
+
render(<Button>Click me</Button>)
|
|
7
|
+
expect(screen.getByText('Click me')).toBeInTheDocument()
|
|
8
|
+
})
|
|
9
9
|
|
|
10
10
|
test('calls onClick when clicked', () => {
|
|
11
|
-
const handleClick = jest.fn()
|
|
12
|
-
render(<Button onClick={handleClick}>Click me</Button>)
|
|
13
|
-
fireEvent.click(screen.getByText('Click me'))
|
|
14
|
-
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
15
|
-
})
|
|
11
|
+
const handleClick = jest.fn()
|
|
12
|
+
render(<Button onClick={handleClick}>Click me</Button>)
|
|
13
|
+
fireEvent.click(screen.getByText('Click me'))
|
|
14
|
+
expect(handleClick).toHaveBeenCalledTimes(1)
|
|
15
|
+
})
|