nsgm-cli 2.1.7 → 2.1.9
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 +106 -58
- package/generation/README.md +147 -16
- package/lib/generate.js +299 -379
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +110 -0
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,28 +1,62 @@
|
|
|
1
1
|
# NSGM CLI
|
|
2
|
-
|
|
3
|
-
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
|
|
3
|
+
A full-stack development framework with code template generation capabilities, helping developers efficiently build web applications.
|
|
4
|
+
|
|
5
|
+
## Tech Stack
|
|
6
|
+
|
|
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
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Full-stack architecture design
|
|
15
|
+
- Automatic code template generation
|
|
16
|
+
- Rapid development workflow
|
|
17
|
+
- Integrated GraphQL API
|
|
18
|
+
- MySQL database support
|
|
19
|
+
|
|
20
|
+
## Command Line Tools
|
|
21
|
+
|
|
22
|
+
### Basic Commands
|
|
23
|
+
|
|
24
|
+
| Command | Description |
|
|
25
|
+
|------|------|
|
|
26
|
+
| `nsgm init` | Initialize project |
|
|
27
|
+
| `nsgm upgrade` | Upgrade project base files |
|
|
28
|
+
| `nsgm create` | Create template page |
|
|
29
|
+
| `nsgm delete` | Delete template page |
|
|
30
|
+
| `nsgm deletedb` | Delete template page and database table |
|
|
31
|
+
| `nsgm dev` | Development mode |
|
|
32
|
+
| `nsgm start` | Production mode |
|
|
33
|
+
| `nsgm build` | Build project |
|
|
34
|
+
| `nsgm export` | Export static pages |
|
|
35
|
+
|
|
36
|
+
### Parameter Description
|
|
37
|
+
|
|
38
|
+
- **dictionary**: Used with `export`/`init` commands, default value is `webapp`
|
|
39
|
+
```
|
|
40
|
+
nsgm init dictionary=webapp
|
|
41
|
+
# or simplified as
|
|
42
|
+
nsgm init webapp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- **controller**: Used with `create`/`delete` commands, required parameter
|
|
46
|
+
```
|
|
47
|
+
nsgm create math
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **action**: Used with `create`/`delete` commands, default value is `manage`, follows the controller
|
|
51
|
+
```
|
|
52
|
+
nsgm create math test
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Project Configuration
|
|
56
|
+
|
|
57
|
+
### next.config.js
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
26
60
|
const { nextConfig } = require('nsgm-cli')
|
|
27
61
|
const projectConfig = require('./project.config')
|
|
28
62
|
|
|
@@ -37,8 +71,9 @@ module.exports = (phase, defaultConfig) => {
|
|
|
37
71
|
}
|
|
38
72
|
```
|
|
39
73
|
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
### mysql.config.js
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
42
77
|
const { mysqlConfig } = require('nsgm-cli')
|
|
43
78
|
const { mysqlOptions } = mysqlConfig
|
|
44
79
|
const { user, password, host, port, database } = mysqlOptions
|
|
@@ -54,8 +89,9 @@ module.exports = {
|
|
|
54
89
|
}
|
|
55
90
|
```
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
### project.config.js
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
59
95
|
const { projectConfig } = require('nsgm-cli')
|
|
60
96
|
const pkg = require('./package.json')
|
|
61
97
|
|
|
@@ -71,34 +107,44 @@ module.exports = {
|
|
|
71
107
|
}
|
|
72
108
|
```
|
|
73
109
|
|
|
74
|
-
##
|
|
75
|
-
- apis 存放 Rest Api
|
|
76
|
-
- modules 存放 graphql 的 resolver 和 schema
|
|
77
|
-
- plugins 存放 graphql 的 plugin
|
|
78
|
-
- *.js 举例: test.js => 用于响应 /test/*, ${prefix}/test/* 请求
|
|
110
|
+
## Server Directory Structure
|
|
79
111
|
|
|
80
|
-
|
|
81
|
-
const express = require('express')
|
|
82
|
-
const moment = require('moment')
|
|
112
|
+
The `server` folder in the project root contains the following:
|
|
83
113
|
|
|
84
|
-
|
|
114
|
+
### Directory Description
|
|
85
115
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
116
|
+
- `apis/` - Stores REST API interfaces
|
|
117
|
+
- `modules/` - Stores GraphQL resolvers and schemas
|
|
118
|
+
- `plugins/` - Stores GraphQL plugins
|
|
119
|
+
- `*.js` - Route files, e.g., `test.js` handles requests to `/test/*` and `${prefix}/test/*`
|
|
91
120
|
|
|
92
|
-
|
|
93
|
-
res.statusCode = 200
|
|
94
|
-
res.json({ name: 'TEST' })
|
|
95
|
-
})
|
|
121
|
+
### Example Code
|
|
96
122
|
|
|
97
|
-
|
|
98
|
-
```
|
|
123
|
+
#### Route File Example (server/test.js)
|
|
99
124
|
|
|
100
|
-
|
|
125
|
+
```javascript
|
|
126
|
+
const express = require('express')
|
|
127
|
+
const moment = require('moment')
|
|
128
|
+
|
|
129
|
+
const router = express.Router()
|
|
130
|
+
|
|
131
|
+
router.use((req, res, next) => {
|
|
132
|
+
const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl
|
|
133
|
+
console.log(moment().format('YYYY-MM-DD HH:mm:ss') + ' ' + fullUrl)
|
|
134
|
+
next()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
router.get('/*', (req, res) => {
|
|
138
|
+
res.statusCode = 200
|
|
139
|
+
res.json({ name: 'TEST' })
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
module.exports = router
|
|
101
143
|
```
|
|
144
|
+
|
|
145
|
+
#### REST API Example (server/apis/hello.js)
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
102
148
|
const express = require('express')
|
|
103
149
|
const router = express.Router()
|
|
104
150
|
|
|
@@ -110,8 +156,9 @@ router.get('/*', (req, res) => {
|
|
|
110
156
|
module.exports = router
|
|
111
157
|
```
|
|
112
158
|
|
|
113
|
-
|
|
114
|
-
|
|
159
|
+
#### GraphQL Schema Example (server/modules/link/schema.js)
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
115
162
|
module.exports = {
|
|
116
163
|
query: `
|
|
117
164
|
link: String
|
|
@@ -124,15 +171,16 @@ module.exports = {
|
|
|
124
171
|
}
|
|
125
172
|
```
|
|
126
173
|
|
|
127
|
-
|
|
128
|
-
|
|
174
|
+
#### GraphQL Resolver Example (server/modules/link/resolver.js)
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
129
177
|
let localLink = ''
|
|
130
178
|
|
|
131
179
|
module.exports = {
|
|
132
180
|
link: () => {
|
|
133
181
|
return localLink
|
|
134
182
|
},
|
|
135
|
-
linkUpdate: ({ link }) =>{
|
|
183
|
+
linkUpdate: ({ link }) => {
|
|
136
184
|
console.log('link', link)
|
|
137
185
|
localLink = link
|
|
138
186
|
return localLink
|
|
@@ -140,8 +188,9 @@ module.exports = {
|
|
|
140
188
|
}
|
|
141
189
|
```
|
|
142
190
|
|
|
143
|
-
|
|
144
|
-
|
|
191
|
+
#### GraphQL Plugin Example (server/plugins/date.js)
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
145
194
|
const moment = require('moment')
|
|
146
195
|
const { Kind } = require('graphql/language')
|
|
147
196
|
const { GraphQLScalarType } = require('graphql')
|
|
@@ -157,5 +206,4 @@ const customScalarDate = new GraphQLScalarType({
|
|
|
157
206
|
})
|
|
158
207
|
|
|
159
208
|
module.exports = { Date: customScalarDate }
|
|
160
|
-
```
|
|
161
|
-
|
|
209
|
+
```
|
package/generation/README.md
CHANGED
|
@@ -1,16 +1,147 @@
|
|
|
1
|
-
# NSGM
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
# 欢迎使用 NSGM 项目
|
|
2
|
+
|
|
3
|
+
这是一个由 NSGM CLI 创建的全栈开发项目,集成了 Next.js、Styled-components、GraphQL 和 MySQL 技术栈。
|
|
4
|
+
|
|
5
|
+
## 技术栈
|
|
6
|
+
|
|
7
|
+
- [Next.js](https://github.com/vercel/next.js) - React 框架
|
|
8
|
+
- [Styled-components](https://github.com/styled-components/styled-components) - CSS-in-JS 解决方案
|
|
9
|
+
- [GraphQL](https://graphql.org/) - API 查询语言
|
|
10
|
+
- [MySQL](https://www.mysql.com/) - 关系型数据库
|
|
11
|
+
|
|
12
|
+
## 快速入门
|
|
13
|
+
|
|
14
|
+
### 开发命令
|
|
15
|
+
|
|
16
|
+
| 命令 | 说明 |
|
|
17
|
+
|---------|-------------|
|
|
18
|
+
| `npm run dev` | 开发模式 |
|
|
19
|
+
| `npm run start` | 生产模式 |
|
|
20
|
+
| `npm run build` | 编译项目 |
|
|
21
|
+
| `npm run export` | 导出静态页面 |
|
|
22
|
+
|
|
23
|
+
### 代码生成命令
|
|
24
|
+
|
|
25
|
+
| 命令 | 说明 |
|
|
26
|
+
|---------|-------------|
|
|
27
|
+
| `npm run create` | 创建模板页面 |
|
|
28
|
+
| `npm run delete` | 删除模板页面 |
|
|
29
|
+
|
|
30
|
+
### 项目维护命令
|
|
31
|
+
|
|
32
|
+
| 命令 | 说明 |
|
|
33
|
+
|---------|-------------|
|
|
34
|
+
| `npm run upgrade` | 升级项目基础文件 |
|
|
35
|
+
|
|
36
|
+
## 参数说明
|
|
37
|
+
|
|
38
|
+
### controller
|
|
39
|
+
- 用于 `create`/`delete` 命令
|
|
40
|
+
- 必填参数
|
|
41
|
+
- 示例:
|
|
42
|
+
```
|
|
43
|
+
npm run create math
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### action
|
|
47
|
+
- 用于 `create`/`delete` 命令
|
|
48
|
+
- 默认值为 `manage`
|
|
49
|
+
- 跟在 controller 参数后面
|
|
50
|
+
- 示例:
|
|
51
|
+
```
|
|
52
|
+
npm run create math test
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### dictionary
|
|
56
|
+
- 用于 `export` 命令
|
|
57
|
+
- 默认值为 `webapp`
|
|
58
|
+
- 示例:
|
|
59
|
+
```
|
|
60
|
+
npm run export dictionary=webapp
|
|
61
|
+
# 或简化为
|
|
62
|
+
npm run export webapp
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 项目结构
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
├── components/ # 公共组件
|
|
69
|
+
├── pages/ # 页面文件
|
|
70
|
+
│ ├── api/ # API 路由
|
|
71
|
+
│ └── [controller]/ # 控制器页面
|
|
72
|
+
├── public/ # 静态资源
|
|
73
|
+
├── server/ # 服务端代码
|
|
74
|
+
│ ├── apis/ # REST API 接口
|
|
75
|
+
│ ├── modules/ # GraphQL 解析器和模式
|
|
76
|
+
│ └── plugins/ # GraphQL 插件
|
|
77
|
+
├── styles/ # 全局样式
|
|
78
|
+
├── next.config.js # Next.js 配置
|
|
79
|
+
├── mysql.config.js # MySQL 配置
|
|
80
|
+
└── project.config.js # 项目配置
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 配置文件
|
|
84
|
+
|
|
85
|
+
### next.config.js
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
const { nextConfig } = require('nsgm-cli')
|
|
89
|
+
const projectConfig = require('./project.config')
|
|
90
|
+
|
|
91
|
+
const { version, prefix, protocol, host } = projectConfig
|
|
92
|
+
|
|
93
|
+
module.exports = (phase, defaultConfig) => {
|
|
94
|
+
let configObj = nextConfig(phase, defaultConfig, {
|
|
95
|
+
version, prefix, protocol, host
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return configObj
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### mysql.config.js
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
const { mysqlConfig } = require('nsgm-cli')
|
|
106
|
+
const { mysqlOptions } = mysqlConfig
|
|
107
|
+
const { user, password, host, port, database } = mysqlOptions
|
|
108
|
+
|
|
109
|
+
module.exports = {
|
|
110
|
+
mysqlOptions: {
|
|
111
|
+
user,
|
|
112
|
+
password,
|
|
113
|
+
host,
|
|
114
|
+
port,
|
|
115
|
+
database
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### project.config.js
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
const { projectConfig } = require('nsgm-cli')
|
|
124
|
+
const pkg = require('./package.json')
|
|
125
|
+
|
|
126
|
+
const { prefix, protocol, host, port } = projectConfig
|
|
127
|
+
const { version } = pkg
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
version,
|
|
131
|
+
prefix,
|
|
132
|
+
protocol,
|
|
133
|
+
host,
|
|
134
|
+
port
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 开发指南
|
|
139
|
+
|
|
140
|
+
1. **创建新页面**:使用 `npm run create [controller] [action]` 命令
|
|
141
|
+
2. **启动开发服务器**:运行 `npm run dev`
|
|
142
|
+
3. **构建生产版本**:运行 `npm run build` 然后 `npm run start`
|
|
143
|
+
4. **导出静态网站**:运行 `npm run export`
|
|
144
|
+
|
|
145
|
+
## 更多资源
|
|
146
|
+
|
|
147
|
+
更多详细信息,请参考 [NSGM CLI 文档](https://github.com/erishen/nsgm-cli)。
|