nsgm-cli 2.1.13 → 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 +370 -155
- 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 -6
- 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 +24 -3
- 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 -173
- 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,237 +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
|
-
|
|
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)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
11
15
|
|
|
12
|
-
##
|
|
16
|
+
## 🚀 Overview
|
|
13
17
|
|
|
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
|
|
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.
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
### 🏗️ Architecture
|
|
22
21
|
|
|
23
|
-
|
|
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
|
+
```
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
| --------------- | --------------------------------------- |
|
|
27
|
-
| `nsgm init` | Initialize project |
|
|
28
|
-
| `nsgm upgrade` | Upgrade project base files |
|
|
29
|
-
| `nsgm create` | Create template page |
|
|
30
|
-
| `nsgm delete` | Delete template page |
|
|
31
|
-
| `nsgm deletedb` | Delete template page and database table |
|
|
32
|
-
| `nsgm dev` | Development mode |
|
|
33
|
-
| `nsgm start` | Production mode |
|
|
34
|
-
| `nsgm build` | Build project |
|
|
35
|
-
| `nsgm export` | Export static pages |
|
|
31
|
+
## 🎯 Key Features
|
|
36
32
|
|
|
37
|
-
###
|
|
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
|
|
38
37
|
|
|
39
|
-
|
|
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
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
46
48
|
|
|
47
|
-
|
|
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
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
nsgm create math
|
|
51
|
-
```
|
|
55
|
+
## 📦 Installation
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
nsgm create math test
|
|
56
|
-
```
|
|
57
|
+
### Global Installation (Recommended)
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
```bash
|
|
60
|
+
# Using npm
|
|
61
|
+
npm install -g nsgm-cli
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
# Using yarn
|
|
64
|
+
yarn global add nsgm-cli
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
# Using pnpm
|
|
67
|
+
pnpm add -g nsgm-cli
|
|
68
|
+
```
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
### Verify Installation
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
```bash
|
|
73
|
+
nsgm --version
|
|
74
|
+
# Should output: 2.1.13
|
|
75
|
+
```
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
## 🚀 Quick Start
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
LOGIN_USERNAME=admin
|
|
75
|
-
LOGIN_PASSWORD_HASH=your_generated_hash_here
|
|
76
|
-
```
|
|
79
|
+
### 1. Initialize Your First Project
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
```bash
|
|
82
|
+
# Start the interactive wizard (recommended for beginners)
|
|
83
|
+
nsgm init
|
|
79
84
|
|
|
80
|
-
|
|
85
|
+
# Or specify project name directly
|
|
86
|
+
nsgm init my-awesome-app
|
|
87
|
+
```
|
|
81
88
|
|
|
82
|
-
|
|
89
|
+
The wizard will guide you through:
|
|
90
|
+
- ✅ Project name and directory
|
|
91
|
+
- ✅ Database configuration
|
|
92
|
+
- ✅ Security settings
|
|
93
|
+
- ✅ Initial controller setup
|
|
83
94
|
|
|
84
|
-
###
|
|
95
|
+
### 2. Environment Setup
|
|
85
96
|
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
const projectConfig = require('./project.config')
|
|
97
|
+
```bash
|
|
98
|
+
cd your-project-name
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
# Copy environment template
|
|
101
|
+
cp .env.example .env
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
version,
|
|
95
|
-
prefix,
|
|
96
|
-
protocol,
|
|
97
|
-
host
|
|
98
|
-
})
|
|
103
|
+
# Generate secure password hash
|
|
104
|
+
npm run generate-password your-secure-password
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
# Edit .env file with generated hash
|
|
107
|
+
nano .env
|
|
102
108
|
```
|
|
103
109
|
|
|
104
|
-
###
|
|
110
|
+
### 3. Start Development
|
|
105
111
|
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
110
156
|
|
|
157
|
+
Each controller created with `nsgm create` includes:
|
|
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
|
|
111
226
|
module.exports = {
|
|
112
227
|
mysqlOptions: {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
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'
|
|
118
233
|
}
|
|
119
234
|
}
|
|
120
235
|
```
|
|
121
236
|
|
|
122
|
-
|
|
237
|
+
## 🔒 Security Setup
|
|
123
238
|
|
|
124
|
-
|
|
125
|
-
const { projectConfig } = require('nsgm-cli')
|
|
126
|
-
const pkg = require('./package.json')
|
|
239
|
+
### Password Generation
|
|
127
240
|
|
|
128
|
-
|
|
129
|
-
|
|
241
|
+
```bash
|
|
242
|
+
# Generate secure hash
|
|
243
|
+
npm run generate-password your-secure-password
|
|
130
244
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
prefix,
|
|
134
|
-
protocol,
|
|
135
|
-
host,
|
|
136
|
-
port
|
|
137
|
-
}
|
|
245
|
+
# Add to .env file
|
|
246
|
+
LOGIN_PASSWORD_HASH=your_generated_hash_here
|
|
138
247
|
```
|
|
139
248
|
|
|
140
|
-
|
|
249
|
+
### CSRF Protection
|
|
141
250
|
|
|
142
|
-
|
|
251
|
+
NSGM CLI includes built-in CSRF protection:
|
|
143
252
|
|
|
144
|
-
|
|
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
|
+
```
|
|
145
266
|
|
|
146
|
-
|
|
147
|
-
- `modules/` - Stores GraphQL resolvers and schemas
|
|
148
|
-
- `plugins/` - Stores GraphQL plugins
|
|
149
|
-
- `*.js` - Route files
|
|
267
|
+
## 🧪 Testing
|
|
150
268
|
|
|
151
|
-
|
|
269
|
+
```bash
|
|
270
|
+
# Run all tests
|
|
271
|
+
npm test
|
|
152
272
|
|
|
153
|
-
|
|
273
|
+
# Watch mode
|
|
274
|
+
npm run test:watch
|
|
154
275
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const moment = require('moment')
|
|
276
|
+
# Coverage report
|
|
277
|
+
npm run test:coverage
|
|
158
278
|
|
|
159
|
-
|
|
279
|
+
# Lint code
|
|
280
|
+
npm run lint
|
|
160
281
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
next()
|
|
165
|
-
})
|
|
282
|
+
# Format code
|
|
283
|
+
npm run format
|
|
284
|
+
```
|
|
166
285
|
|
|
167
|
-
|
|
168
|
-
res.statusCode = 200
|
|
169
|
-
res.json({ name: 'TEST' })
|
|
170
|
-
})
|
|
286
|
+
## 📚 Examples
|
|
171
287
|
|
|
172
|
-
|
|
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
|
|
173
302
|
```
|
|
174
303
|
|
|
175
|
-
|
|
304
|
+
### Adding Custom API Endpoint
|
|
176
305
|
|
|
177
306
|
```javascript
|
|
307
|
+
// server/apis/custom.js
|
|
178
308
|
const express = require('express')
|
|
179
309
|
const router = express.Router()
|
|
180
310
|
|
|
181
|
-
router.get('
|
|
182
|
-
res.
|
|
183
|
-
|
|
311
|
+
router.get('/stats', (req, res) => {
|
|
312
|
+
res.json({
|
|
313
|
+
totalPosts: 42,
|
|
314
|
+
totalUsers: 15,
|
|
315
|
+
lastUpdate: new Date()
|
|
316
|
+
})
|
|
184
317
|
})
|
|
185
318
|
|
|
186
319
|
module.exports = router
|
|
187
320
|
```
|
|
188
321
|
|
|
189
|
-
|
|
322
|
+
### Custom GraphQL Schema
|
|
190
323
|
|
|
191
324
|
```javascript
|
|
325
|
+
// server/modules/blog/schema.js
|
|
192
326
|
module.exports = {
|
|
193
327
|
query: `
|
|
194
|
-
|
|
195
|
-
|
|
328
|
+
posts(limit: Int, offset: Int): [Post]
|
|
329
|
+
post(id: ID!): Post
|
|
330
|
+
`,
|
|
196
331
|
mutation: `
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
+
`
|
|
201
345
|
}
|
|
202
346
|
```
|
|
203
347
|
|
|
204
|
-
|
|
348
|
+
## 🚀 Performance & Production
|
|
205
349
|
|
|
206
|
-
|
|
207
|
-
let localLink = ''
|
|
350
|
+
### Build Optimization
|
|
208
351
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
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
|
|
219
361
|
```
|
|
220
362
|
|
|
221
|
-
|
|
363
|
+
### Production Deployment
|
|
222
364
|
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
|
374
|
+
|
|
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
|
|
235
389
|
|
|
236
|
-
|
|
390
|
+
# Build CLI
|
|
391
|
+
npm run tsbuild
|
|
237
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
|
+
})
|