nsgm-cli 2.1.13 → 2.1.15

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.
Files changed (147) hide show
  1. package/README.md +394 -156
  2. package/client/components/Button.tsx +3 -5
  3. package/client/components/ClientProviders.tsx +29 -0
  4. package/client/components/LanguageSwitcher.tsx +59 -0
  5. package/client/components/SSRSafeAntdProvider.tsx +24 -0
  6. package/client/components/SuppressHydrationWarnings.tsx +55 -0
  7. package/client/components/__tests__/Button.test.tsx +10 -10
  8. package/client/layout/index.tsx +153 -185
  9. package/client/redux/reducers.ts +1 -1
  10. package/client/redux/store.ts +2 -1
  11. package/client/redux/template/manage/actions.ts +77 -88
  12. package/client/redux/template/manage/reducers.ts +25 -37
  13. package/client/redux/template/manage/types.ts +1 -1
  14. package/client/service/template/manage.ts +20 -21
  15. package/client/styled/common.ts +12 -14
  16. package/client/styled/layout/index.ts +234 -120
  17. package/client/styled/template/manage.ts +102 -14
  18. package/client/utils/common.ts +23 -21
  19. package/client/utils/cookie.ts +18 -19
  20. package/client/utils/fetch.ts +64 -100
  21. package/client/utils/i18n.ts +68 -0
  22. package/client/utils/menu.tsx +42 -23
  23. package/client/utils/navigation.ts +58 -0
  24. package/client/utils/sso.ts +74 -84
  25. package/client/utils/suppressWarnings.ts +32 -0
  26. package/eslint.config.js +53 -19
  27. package/generation/README.md +25 -6
  28. package/generation/__tests__/example.test.js +41 -0
  29. package/generation/client/redux/reducers.ts +1 -1
  30. package/generation/client/utils/menu.tsx +36 -23
  31. package/generation/env +3 -0
  32. package/generation/env.example +3 -0
  33. package/generation/eslint.config.js +112 -0
  34. package/generation/gitignore +6 -1
  35. package/generation/jest.config.js +40 -0
  36. package/generation/next.config.js +7 -3
  37. package/generation/package.json +28 -4
  38. package/generation/tsconfig.json +6 -19
  39. package/jest.config.js +23 -6
  40. package/lib/args.js +9 -1
  41. package/lib/cli/app.d.ts +28 -0
  42. package/lib/cli/app.js +99 -0
  43. package/lib/cli/commands/build.d.ts +2 -0
  44. package/lib/cli/commands/build.js +29 -0
  45. package/lib/cli/commands/create.d.ts +2 -0
  46. package/lib/cli/commands/create.js +113 -0
  47. package/lib/cli/commands/delete.d.ts +3 -0
  48. package/lib/cli/commands/delete.js +151 -0
  49. package/lib/cli/commands/export.d.ts +2 -0
  50. package/lib/cli/commands/export.js +42 -0
  51. package/lib/cli/commands/help.d.ts +2 -0
  52. package/lib/cli/commands/help.js +42 -0
  53. package/lib/cli/commands/init.d.ts +2 -0
  54. package/lib/cli/commands/init.js +115 -0
  55. package/lib/cli/commands/server.d.ts +3 -0
  56. package/lib/cli/commands/server.js +26 -0
  57. package/lib/cli/commands/upgrade.d.ts +2 -0
  58. package/lib/cli/commands/upgrade.js +38 -0
  59. package/lib/cli/commands/version.d.ts +2 -0
  60. package/lib/cli/commands/version.js +24 -0
  61. package/lib/cli/index.d.ts +16 -0
  62. package/lib/cli/index.js +33 -0
  63. package/lib/cli/parser.d.ts +22 -0
  64. package/lib/cli/parser.js +115 -0
  65. package/lib/cli/registry.d.ts +33 -0
  66. package/lib/cli/registry.js +81 -0
  67. package/lib/cli/types/project.d.ts +10 -0
  68. package/lib/cli/types/project.js +2 -0
  69. package/lib/cli/types.d.ts +31 -0
  70. package/lib/cli/types.js +20 -0
  71. package/lib/cli/utils/console.d.ts +62 -0
  72. package/lib/cli/utils/console.js +148 -0
  73. package/lib/cli/utils/index.d.ts +2 -0
  74. package/lib/cli/utils/index.js +7 -0
  75. package/lib/cli/utils/prompt.d.ts +83 -0
  76. package/lib/cli/utils/prompt.js +327 -0
  77. package/lib/constants.d.ts +65 -0
  78. package/lib/constants.js +177 -0
  79. package/lib/generate.d.ts +25 -3
  80. package/lib/generate.js +98 -621
  81. package/lib/generate_create.d.ts +9 -0
  82. package/lib/generate_create.js +329 -0
  83. package/lib/generate_delete.d.ts +8 -0
  84. package/lib/generate_delete.js +233 -0
  85. package/lib/generate_init.d.ts +56 -0
  86. package/lib/generate_init.js +612 -0
  87. package/lib/generators/base-generator.d.ts +47 -0
  88. package/lib/generators/base-generator.js +92 -0
  89. package/lib/generators/file-generator.d.ts +48 -0
  90. package/lib/generators/file-generator.js +455 -0
  91. package/lib/generators/generator-factory.d.ts +20 -0
  92. package/lib/generators/generator-factory.js +25 -0
  93. package/lib/generators/i18n-generator.d.ts +51 -0
  94. package/lib/generators/i18n-generator.js +320 -0
  95. package/lib/generators/page-generator.d.ts +45 -0
  96. package/lib/generators/page-generator.js +578 -0
  97. package/lib/generators/resolver-generator.d.ts +14 -0
  98. package/lib/generators/resolver-generator.js +342 -0
  99. package/lib/generators/schema-generator.d.ts +7 -0
  100. package/lib/generators/schema-generator.js +57 -0
  101. package/lib/generators/service-generator.d.ts +11 -0
  102. package/lib/generators/service-generator.js +233 -0
  103. package/lib/generators/sql-generator.d.ts +8 -0
  104. package/lib/generators/sql-generator.js +52 -0
  105. package/lib/index.d.ts +1 -1
  106. package/lib/index.js +14 -173
  107. package/lib/server/csrf.js +9 -16
  108. package/lib/server/db.js +6 -7
  109. package/lib/server/graphql.js +5 -6
  110. package/lib/server/plugins/date.js +1 -1
  111. package/lib/server/utils/graphql-cache.js +3 -3
  112. package/lib/tsconfig.build.tsbuildinfo +1 -1
  113. package/lib/utils/project-config.d.ts +5 -0
  114. package/lib/utils/project-config.js +145 -0
  115. package/lib/utils.js +1 -1
  116. package/next-i18next.config.js +18 -0
  117. package/next.config.js +61 -18
  118. package/package.json +16 -8
  119. package/pages/_app.tsx +77 -33
  120. package/pages/_document.tsx +78 -21
  121. package/pages/_error.tsx +66 -0
  122. package/pages/index.tsx +109 -47
  123. package/pages/login.tsx +66 -41
  124. package/pages/template/manage.tsx +162 -151
  125. package/public/fonts/font-awesome.min.css +4 -0
  126. package/public/fonts/fontawesome-webfont.woff +0 -0
  127. package/public/fonts/fontawesome-webfont.woff2 +0 -0
  128. package/public/locales/en-US/common.json +48 -0
  129. package/public/locales/en-US/home.json +57 -0
  130. package/public/locales/en-US/layout.json +22 -0
  131. package/public/locales/en-US/login.json +13 -0
  132. package/public/locales/en-US/template.json +42 -0
  133. package/public/locales/ja-JP/common.json +48 -0
  134. package/public/locales/ja-JP/home.json +57 -0
  135. package/public/locales/ja-JP/layout.json +22 -0
  136. package/public/locales/ja-JP/login.json +13 -0
  137. package/public/locales/ja-JP/template.json +42 -0
  138. package/public/locales/zh-CN/common.json +48 -0
  139. package/public/locales/zh-CN/home.json +57 -0
  140. package/public/locales/zh-CN/layout.json +22 -0
  141. package/public/locales/zh-CN/login.json +13 -0
  142. package/public/locales/zh-CN/template.json +42 -0
  143. package/public/slbhealthcheck.html +1 -1
  144. package/server/apis/template.js +0 -2
  145. package/server/utils/validation.js +163 -0
  146. package/types/i18next.d.ts +10 -0
  147. package/generation/eslintrc.js +0 -16
package/README.md CHANGED
@@ -1,237 +1,475 @@
1
1
  # NSGM CLI
2
2
 
3
- A full-stack development framework with code template generation capabilities, helping developers efficiently build web applications.
3
+ <div align="center">
4
4
 
5
- ## Tech Stack
5
+ ![NSGM CLI](https://img.shields.io/npm/v/nsgm-cli?style=flat-square&logo=npm)
6
+ ![License](https://img.shields.io/github/license/erishen/nsgm?style=flat-square)
7
+ ![Node.js](https://img.shields.io/node/v/nsgm-cli?style=flat-square&logo=node.js)
8
+ ![Downloads](https://img.shields.io/npm/dm/nsgm-cli?style=flat-square)
6
9
 
7
- - [Next.js](https://github.com/vercel/next.js) - React framework
8
- - [Styled-components](https://github.com/styled-components/styled-components) - CSS-in-JS solution
9
- - [GraphQL](https://graphql.org/) - API query language
10
- - [MySQL](https://www.mysql.com/) - Relational database
10
+ **A powerful full-stack development framework with intelligent code generation**
11
11
 
12
- ## Features
12
+ [Installation](#installation) • [Quick Start](#quick-start) • [Features](#features) • [Documentation](#documentation) • [Contributing](#contributing)
13
13
 
14
- - Full-stack architecture design
15
- - Automatic code template generation
16
- - Rapid development workflow
17
- - Integrated GraphQL API
18
- - MySQL database support
19
- - Secure login system with bcrypt encryption
14
+ </div>
20
15
 
21
- ## Command Line Tools
16
+ ## 🚀 Overview
22
17
 
23
- ### Basic Commands
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.
24
19
 
25
- | Command | Description |
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 |
20
+ ### 🏗️ Architecture
36
21
 
37
- ### Parameter Description
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
+ ```
38
30
 
39
- - **dictionary**: Used with `export`/`init` commands, default value is `webapp`
31
+ ## 🎯 Key Features
40
32
 
41
- ```
42
- nsgm init dictionary=webapp
43
- # or simplified as
44
- nsgm init webapp
45
- ```
33
+ ### 🧙‍♂️ **Intelligent CLI Wizard**
46
34
 
47
- - **controller**: Used with `create`/`delete` commands, required parameter
35
+ - **Smart Mode Detection**: Automatically switches between interactive and command-line modes
36
+ - **Beginner-Friendly**: Step-by-step guided setup for newcomers
37
+ - **Expert-Efficient**: Quick command-line shortcuts for experienced developers
48
38
 
49
- ```
50
- nsgm create math
51
- ```
39
+ ### ⚡ **Rapid Development**
52
40
 
53
- - **action**: Used with `create`/`delete` commands, default value is `manage`, follows the controller
54
- ```
55
- nsgm create math test
56
- ```
41
+ - **Code Generation**: Automatic CRUD operations, API endpoints, and database schemas
42
+ - **Hot Reload**: Instant development feedback
43
+ - **Type Safety**: Full TypeScript support throughout the stack
57
44
 
58
- ## Security Configuration
45
+ ### 🔒 **Production-Ready Security**
59
46
 
60
- For security setup and login configuration, please refer to [SECURITY.md](./SECURITY.md).
47
+ - **CSRF Protection**: Built-in cross-site request forgery prevention
48
+ - **Password Encryption**: bcrypt-based secure authentication
49
+ - **Session Management**: Robust user session handling
50
+ - **CSP Headers**: Content Security Policy implementation
61
51
 
62
- ### Quick Setup
52
+ ### 🏗️ **Modern Tech Stack**
63
53
 
64
- 1. Generate password hash:
54
+ - **Frontend**: Next.js 13+, React 18+, Styled-components, Redux Toolkit
55
+ - **Backend**: Express.js, GraphQL, REST APIs
56
+ - **Database**: MySQL with native drivers
57
+ - **DevTools**: TypeScript, ESLint, Prettier, Jest
65
58
 
66
- ```bash
67
- # Using npm script
68
- npm run generate-password yourSecurePassword
69
- ```
59
+ ## 📦 Installation
70
60
 
71
- 2. Create `.env` file:
61
+ ### Global Installation (Recommended)
72
62
 
73
- ```bash
74
- LOGIN_USERNAME=admin
75
- LOGIN_PASSWORD_HASH=your_generated_hash_here
76
- ```
63
+ ```bash
64
+ # Using npm
65
+ npm install -g nsgm-cli
77
66
 
78
- 3. Make sure `.env` is in your `.gitignore` file.
67
+ # Using yarn
68
+ yarn global add nsgm-cli
79
69
 
80
- **⚠️ Important:** Never commit passwords or `.env` files to version control.
70
+ # Using pnpm
71
+ pnpm add -g nsgm-cli
72
+ ```
81
73
 
82
- ## Project Configuration
74
+ ### Verify Installation
83
75
 
84
- ### next.config.js
76
+ ```bash
77
+ nsgm --version
78
+ # Should output: 2.1.13
79
+ ```
85
80
 
86
- ```javascript
87
- const { nextConfig } = require('nsgm-cli')
88
- const projectConfig = require('./project.config')
81
+ ## 🚀 Quick Start
89
82
 
90
- const { version, prefix, protocol, host } = projectConfig
83
+ ### 1. Initialize Your First Project
91
84
 
92
- module.exports = (phase, defaultConfig) => {
93
- let configObj = nextConfig(phase, defaultConfig, {
94
- version,
95
- prefix,
96
- protocol,
97
- host
98
- })
85
+ ```bash
86
+ # Start the interactive wizard (recommended for beginners)
87
+ nsgm init
99
88
 
100
- return configObj
101
- }
89
+ # Or specify project name directly
90
+ nsgm init my-awesome-app
102
91
  ```
103
92
 
104
- ### mysql.config.js
93
+ The wizard will guide you through:
105
94
 
106
- ```javascript
107
- const { mysqlConfig } = require('nsgm-cli')
108
- const { mysqlOptions } = mysqlConfig
109
- const { user, password, host, port, database } = mysqlOptions
95
+ - ✅ Project name and directory
96
+ - Database configuration
97
+ - Security settings
98
+ - Initial controller setup
110
99
 
111
- module.exports = {
112
- mysqlOptions: {
113
- user,
114
- password,
115
- host,
116
- port,
117
- database
118
- }
119
- }
100
+ ### 2. Environment Setup
101
+
102
+ ```bash
103
+ cd your-project-name
104
+
105
+ # Copy environment template
106
+ cp .env.example .env
120
107
  ```
121
108
 
122
- ### project.config.js
109
+ **Default Login**: `admin/admin123`
123
110
 
124
- ```javascript
125
- const { projectConfig } = require('nsgm-cli')
126
- const pkg = require('./package.json')
111
+ **To change password** (optional):
112
+
113
+ ```bash
114
+ # Generate secure password hash
115
+ npm run generate-password yourNewPassword
116
+
117
+ # Edit .env file with generated hash
118
+ nano .env
119
+ ```
120
+
121
+ ### 3. Start Development
122
+
123
+ ```bash
124
+ # Install dependencies
125
+ npm install
126
+
127
+ # Start development server
128
+ npm run dev
129
+ ```
130
+
131
+ Your application will be available at `http://localhost:3000` with:
132
+
133
+ - 🎛️ Admin dashboard with CRUD interface
134
+ - 📊 Data import/export functionality
135
+ - 🗑️ Batch operations support
136
+ - 🔐 Secure login system (Default: admin/admin123)
137
+
138
+ ## 🛠️ CLI Commands
139
+
140
+ ### Core Commands
141
+
142
+ | Command | Description | Mode | Example |
143
+ | ------------- | ----------------------------- | --------------- | --------------------- |
144
+ | `nsgm init` | Initialize new project | Interactive/CLI | `nsgm init blog-app` |
145
+ | `nsgm create` | Generate controller with CRUD | Interactive/CLI | `nsgm create user` |
146
+ | `nsgm delete` | Remove controller and files | Interactive/CLI | `nsgm delete product` |
147
+ | `nsgm dev` | Start development server | CLI | `nsgm dev` |
148
+ | `nsgm build` | Build for production | CLI | `nsgm build` |
149
+ | `nsgm start` | Start production server | CLI | `nsgm start` |
150
+
151
+ ### Advanced Commands
152
+
153
+ ```bash
154
+ # Database operations
155
+ nsgm deletedb user # Delete controller + database table
127
156
 
128
- const { prefix, protocol, host, port } = projectConfig
129
- const { version } = pkg
157
+ # Project maintenance
158
+ nsgm upgrade # Upgrade project base files
159
+ nsgm export # Export static pages
130
160
 
161
+ # Development tools
162
+ npm run lint # Code linting
163
+ npm run test # Run tests
164
+ npm run test:coverage # Test coverage report
165
+ ```
166
+
167
+ ## 🎨 Generated Controller Features
168
+
169
+ Each controller created with `nsgm create` includes:
170
+
171
+ ### 🔧 **Backend Components**
172
+
173
+ - **GraphQL Schema**: Typed queries and mutations
174
+ - **GraphQL Resolvers**: Business logic implementation
175
+ - **REST API Endpoints**: RESTful service layer
176
+ - **Database Models**: MySQL schema definitions
177
+ - **Data Validation**: Input sanitization and validation
178
+
179
+ ### 🎯 **Frontend Components**
180
+
181
+ - **React Components**: Modern functional components with hooks
182
+ - **Styled Components**: CSS-in-JS styling
183
+ - **Redux Integration**: State management
184
+ - **Form Handling**: Create, edit, and validation forms
185
+ - **Data Tables**: Sortable, filterable data grids
186
+
187
+ ### 📊 **CRUD Operations**
188
+
189
+ - **Create**: Add new records with validation
190
+ - **Read**: List, search, and pagination
191
+ - **Update**: Edit existing records
192
+ - **Delete**: Single and batch deletion
193
+ - **Import/Export**: CSV and JSON data handling
194
+
195
+ ## 🏗️ Project Structure
196
+
197
+ ```
198
+ your-project/
199
+ ├── client/ # Frontend code
200
+ │ ├── components/ # React components
201
+ │ ├── layout/ # Layout components
202
+ │ ├── redux/ # State management
203
+ │ ├── service/ # API services
204
+ │ ├── styled/ # Styled components
205
+ │ └── utils/ # Utility functions
206
+ ├── server/ # Backend code
207
+ │ ├── apis/ # REST API routes
208
+ │ ├── modules/ # GraphQL modules
209
+ │ ├── sql/ # Database scripts
210
+ │ └── utils/ # Server utilities
211
+ ├── pages/ # Next.js pages
212
+ ├── public/ # Static assets
213
+ ├── scripts/ # Build and deployment scripts
214
+ ├── __tests__/ # Test files
215
+ ├── .env.example # Environment template
216
+ ├── next.config.js # Next.js configuration
217
+ ├── mysql.config.js # Database configuration
218
+ └── package.json # Dependencies
219
+ ```
220
+
221
+ ## ⚙️ Configuration
222
+
223
+ ### Environment Variables
224
+
225
+ ```bash
226
+ # .env file
227
+ NODE_ENV=development
228
+ LOGIN_USERNAME=admin
229
+ LOGIN_PASSWORD_HASH=your_generated_hash # Default: admin123
230
+ DATABASE_URL=mysql://user:password@localhost:3306/dbname
231
+
232
+ # Optional
233
+ PORT=3000
234
+ NEXT_PUBLIC_API_URL=http://localhost:3000
235
+ ```
236
+
237
+ ### Database Configuration
238
+
239
+ ```javascript
240
+ // mysql.config.js
131
241
  module.exports = {
132
- version,
133
- prefix,
134
- protocol,
135
- host,
136
- port
242
+ mysqlOptions: {
243
+ host: process.env.DB_HOST || 'localhost',
244
+ port: process.env.DB_PORT || 3306,
245
+ user: process.env.DB_USER || 'root',
246
+ password: process.env.DB_PASSWORD || '',
247
+ database: process.env.DB_NAME || 'nsgm_db',
248
+ },
137
249
  }
138
250
  ```
139
251
 
140
- ## Server Directory Structure
252
+ ## 🔒 Security Setup
141
253
 
142
- The `server` folder in the project root contains the following:
254
+ ### Default Authentication
143
255
 
144
- ### Directory Description
256
+ **Default Login Credentials**: `admin/admin123`
145
257
 
146
- - `apis/` - Stores REST API interfaces
147
- - `modules/` - Stores GraphQL resolvers and schemas
148
- - `plugins/` - Stores GraphQL plugins
149
- - `*.js` - Route files
258
+ ### Custom Password Setup (Optional)
150
259
 
151
- ### Example Code
260
+ ```bash
261
+ # Generate secure hash for custom password
262
+ npm run generate-password yourNewPassword
263
+
264
+ # Add to .env file
265
+ LOGIN_PASSWORD_HASH=your_generated_hash_here
266
+ ```
152
267
 
153
- #### Route File Example (server/csrf-test.js)
268
+ ### CSRF Protection
269
+
270
+ NSGM CLI includes built-in CSRF protection:
154
271
 
155
272
  ```javascript
156
- const express = require('express')
157
- const moment = require('moment')
273
+ // Automatic CSRF token generation
274
+ app.use(csrfProtection)
275
+
276
+ // Custom CSP headers
277
+ app.use(
278
+ createCSPMiddleware({
279
+ directives: {
280
+ defaultSrc: ["'self'"],
281
+ styleSrc: ["'self'", "'unsafe-inline'"],
282
+ scriptSrc: ["'self'"],
283
+ },
284
+ })
285
+ )
286
+ ```
158
287
 
159
- const router = express.Router()
288
+ ## 🧪 Testing
160
289
 
161
- router.use((req, res, next) => {
162
- const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl
163
- console.log(moment().format('YYYY-MM-DD HH:mm:ss') + ' ' + fullUrl)
164
- next()
165
- })
290
+ ```bash
291
+ # Run all tests
292
+ npm test
166
293
 
167
- router.get('/*', (req, res) => {
168
- res.statusCode = 200
169
- res.json({ name: 'TEST' })
170
- })
294
+ # Watch mode
295
+ npm run test:watch
171
296
 
172
- module.exports = router
297
+ # Coverage report
298
+ npm run test:coverage
299
+
300
+ # Lint code
301
+ npm run lint
302
+
303
+ # Format code
304
+ npm run format
173
305
  ```
174
306
 
175
- #### REST API Example (server/apis/hello.js)
307
+ ## 📚 Examples
308
+
309
+ ### Creating a Blog System
310
+
311
+ ```bash
312
+ # 1. Initialize project
313
+ nsgm init my-blog
314
+
315
+ # 2. Create controllers
316
+ cd my-blog
317
+ nsgm create post
318
+ nsgm create category
319
+ nsgm create user
320
+
321
+ # 3. Start development
322
+ npm run dev
323
+ ```
324
+
325
+ ### Adding Custom API Endpoint
176
326
 
177
327
  ```javascript
328
+ // server/apis/custom.js
178
329
  const express = require('express')
179
330
  const router = express.Router()
180
331
 
181
- router.get('/*', (req, res) => {
182
- res.statusCode = 200
183
- res.json({ name: 'Hello' })
332
+ router.get('/stats', (req, res) => {
333
+ res.json({
334
+ totalPosts: 42,
335
+ totalUsers: 15,
336
+ lastUpdate: new Date(),
337
+ })
184
338
  })
185
339
 
186
340
  module.exports = router
187
341
  ```
188
342
 
189
- #### GraphQL Schema Example (server/modules/link/schema.js)
343
+ ### Custom GraphQL Schema
190
344
 
191
345
  ```javascript
346
+ // server/modules/blog/schema.js
192
347
  module.exports = {
193
348
  query: `
194
- link: String
195
- `,
349
+ posts(limit: Int, offset: Int): [Post]
350
+ post(id: ID!): Post
351
+ `,
196
352
  mutation: `
197
- linkUpdate(link: Date): String
198
- `,
199
- subscription: ``,
200
- type: ``
353
+ createPost(title: String!, content: String!): Post
354
+ updatePost(id: ID!, title: String, content: String): Post
355
+ deletePost(id: ID!): Boolean
356
+ `,
357
+ type: `
358
+ type Post {
359
+ id: ID!
360
+ title: String!
361
+ content: String!
362
+ createdAt: Date!
363
+ updatedAt: Date!
364
+ }
365
+ `,
201
366
  }
202
367
  ```
203
368
 
204
- #### GraphQL Resolver Example (server/modules/link/resolver.js)
369
+ ## 🚀 Performance & Production
205
370
 
206
- ```javascript
207
- let localLink = ''
371
+ ### Build Optimization
208
372
 
209
- module.exports = {
210
- link: () => {
211
- return localLink
212
- },
213
- linkUpdate: ({ link }) => {
214
- console.log('link', link)
215
- localLink = link
216
- return localLink
217
- }
218
- }
373
+ ```bash
374
+ # Production build
375
+ npm run build
376
+
377
+ # Analyze bundle size
378
+ npm run analyze
379
+
380
+ # Export static site
381
+ npm run export
219
382
  ```
220
383
 
221
- #### GraphQL Plugin Example (server/plugins/date.js)
384
+ ### Production Deployment
222
385
 
223
- ```javascript
224
- const moment = require('moment')
225
- const { Kind } = require('graphql/language')
226
- const { GraphQLScalarType } = require('graphql')
227
-
228
- const customScalarDate = new GraphQLScalarType({
229
- name: 'Date',
230
- description: 'Date custom scalar type',
231
- parseValue: (value) => moment(value).valueOf(),
232
- serialize: (value) => moment(value).format('YYYY-MM-DD HH:mm:ss:SSS'),
233
- parseLiteral: (ast) => (ast.kind === Kind.INT ? parseInt(ast.value, 10) : null)
234
- })
386
+ ```bash
387
+ # Start production server
388
+ npm start
389
+
390
+ # Or use PM2
391
+ pm2 start npm --name "nsgm-app" -- start
392
+ ```
393
+
394
+ ## 🤝 Contributing
395
+
396
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
397
+
398
+ ### Development Setup
399
+
400
+ ```bash
401
+ # Clone repository
402
+ git clone https://github.com/erishen/nsgm.git
403
+ cd nsgm
235
404
 
236
- module.exports = { Date: customScalarDate }
405
+ # Install dependencies
406
+ npm install
407
+
408
+ # Run tests
409
+ npm test
410
+
411
+ # Build CLI
412
+ npm run tsbuild
413
+ ```
414
+
415
+ ## 📖 Documentation
416
+
417
+ - [Security Guide](SECURITY.md) - Security best practices
418
+ - [API Reference](docs/api.md) - Complete API documentation
419
+ - [Migration Guide](docs/migration.md) - Upgrade instructions
420
+ - [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
421
+
422
+ ## 🐛 Troubleshooting
423
+
424
+ ### Common Issues
425
+
426
+ **Port already in use**
427
+
428
+ ```bash
429
+ # Kill process on port 3000
430
+ lsof -ti:3000 | xargs kill -9
431
+
432
+ # Or use different port
433
+ PORT=3001 npm run dev
434
+ ```
435
+
436
+ **Database connection failed**
437
+
438
+ ```bash
439
+ # Check MySQL service
440
+ sudo systemctl status mysql
441
+
442
+ # Verify credentials in .env
443
+ cat .env | grep DB_
237
444
  ```
445
+
446
+ **Permission denied**
447
+
448
+ ```bash
449
+ # Fix npm permissions
450
+ sudo chown -R $(whoami) ~/.npm
451
+
452
+ # Or use different install location
453
+ npm config set prefix '~/.local'
454
+ ```
455
+
456
+ ## 📄 License
457
+
458
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
459
+
460
+ ## 🙏 Acknowledgments
461
+
462
+ - [Next.js](https://nextjs.org/) - React framework
463
+ - [GraphQL](https://graphql.org/) - Query language
464
+ - [Styled Components](https://styled-components.com/) - CSS-in-JS
465
+ - [MySQL](https://www.mysql.com/) - Relational database
466
+
467
+ ---
468
+
469
+ <div align="center">
470
+
471
+ **Made with ❤️ by the NSGM Team**
472
+
473
+ [GitHub](https://github.com/erishen/nsgm) • [npm](https://www.npmjs.com/package/nsgm-cli) • [Issues](https://github.com/erishen/nsgm/issues)
474
+
475
+ </div>
@@ -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
@@ -0,0 +1,29 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { ThemeProvider } from 'styled-components'
3
+ import { GlobalStyle } from '@/styled/common'
4
+
5
+ interface ClientProvidersProps {
6
+ children: React.ReactNode
7
+ theme: any
8
+ whiteColor?: boolean
9
+ }
10
+
11
+ const ClientProviders: React.FC<ClientProvidersProps> = ({ children, theme, whiteColor = true }) => {
12
+ const [isClient, setIsClient] = useState(false)
13
+
14
+ useEffect(() => {
15
+ // 使用更安全的客户端检测
16
+ setIsClient(true)
17
+ }, [])
18
+
19
+ // 在服务端渲染时,使用一个占位符来保持结构一致性
20
+ // 但不渲染可能引起 useLayoutEffect 警告的组件
21
+ return (
22
+ <ThemeProvider theme={theme}>
23
+ {isClient && <GlobalStyle whiteColor={whiteColor} />}
24
+ {children}
25
+ </ThemeProvider>
26
+ )
27
+ }
28
+
29
+ export default ClientProviders