clwy-express-generator 5.2.1 → 5.2.3

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 CHANGED
@@ -4,13 +4,11 @@
4
4
 
5
5
  **此项目基于 [express-generator](https://github.com/expressjs/generator) 分叉而来,并新增了一些功能特性。**
6
6
 
7
- **其中,ES6 支持的实现参考了 [Dr. Jeff Jackson](https://github.com/drjeffjackson) 提交的 [Pull Request](https://github.com/expressjs/generator/pull/316),并在其基础上进行了进一步优化和调整。**
8
-
9
7
  ## 功能特性
10
8
 
11
9
  - **🚀 ES6 支持**:代码更现代简洁。
12
10
  - **🔀 路由拆分**:独立文件,便于管理维护。
13
- - **🗄️ ORM 支持**:支持 PrismaSequelize ORM。
11
+ - **🗄️ ORM 支持**:支持 SequelizePrisma ORM。
14
12
  - **📁 中间件模块化**:新增文件夹存放中间件。
15
13
  - **🔧 增加环境变量配置**:多环境管理更便捷。
16
14
  - **🔄 集成 nodemon**:开发时自动重启服务。
@@ -28,6 +26,7 @@
28
26
 
29
27
  ```bash
30
28
  $ npx clwy-express-generator --view=ejs --es6 es6-demo
29
+ # 或:npx clwy-express-generator -v=ejs --es6 es6-demo
31
30
  $ cd es6-demo
32
31
  ```
33
32
 
@@ -53,39 +52,53 @@ $ npm start
53
52
  $ docker-compose up -d
54
53
  ```
55
54
 
56
- 默认将启动 MySQL 数据库,PostgreSQL 和 Redis 配置已在 `docker-compose.yml` 中,请根据需求调整。
55
+ 默认将启动 MySQL 数据库,PostgreSQL 和 Redis 配置已在 `docker-compose.yml` 中,请根据需求取消注释。
57
56
 
58
- ### 使用 Prisma
57
+ ### 使用 Sequelize
59
58
 
60
- 创建应用:
59
+ **创建应用:**
61
60
 
62
61
  ```bash
63
- $ npx clwy-express-generator --view=ejs --orm=prisma --es6 es6-prisma-demo
64
- $ cd es6-prisma-demo
62
+ $ npx clwy-express-generator --view=ejs --orm=sequelize --es6 es6-sequelize-demo
63
+ $ cd es6-sequelize-demo
65
64
  $ npm i
66
65
  ```
67
66
 
68
- 初始化数据库客户端:
67
+ **根据需求安装数据库引擎:**
69
68
 
70
69
  ```bash
71
- $ npx prisma generate
70
+ $ npm install --save mysql2 # MySQL
71
+ $ npm install --save pg pg-hstore # Postgres
72
72
  ```
73
73
 
74
- ### 使用 Sequelize
74
+ 项目已默认集成了[clwy-sequelize-cli](https://github.com/clwy-cn/clwy-sequelize-cli),使用以下命令会生成**ES6**风格的模型、迁移和种子文件。
75
75
 
76
- 创建应用:
76
+ **生成模型和迁移文件:**
77
77
 
78
78
  ```bash
79
- $ npx clwy-express-generator --view=ejs --orm=sequelize --es6 es6-sequelize-demo
80
- $ cd es6-sequelize-demo
79
+ $ npx sequelize model:generate --name Article --attributes title:string,content:text
80
+ ```
81
+
82
+ **生成种子文件:**
83
+
84
+ ```bash
85
+ $ npx sequelize seed:generate --name article
86
+ ```
87
+
88
+ ### 使用 Prisma
89
+
90
+ **创建应用:**
91
+
92
+ ```bash
93
+ $ npx clwy-express-generator --view=ejs --orm=prisma --es6 es6-prisma-demo
94
+ $ cd es6-prisma-demo
81
95
  $ npm i
82
96
  ```
83
97
 
84
- 根据需求安装数据库引擎:
98
+ **初始化数据库客户端:**
85
99
 
86
100
  ```bash
87
- $ npm install --save mysql2 # MySQL
88
- $ npm install --save pg pg-hstore # Postgres
101
+ $ npx prisma generate
89
102
  ```
90
103
 
91
104
  ## 命令行选项
@@ -95,7 +108,7 @@ $ npm install --save pg pg-hstore # Postgres
95
108
  --version 输出版本号
96
109
  -v, --view <engine> 添加视图引擎 <engine> 支持 (dust|ejs|hbs|hjs|pug|twig|vash|api)(默认为 ejs)
97
110
  --no-view 使用静态html而不是视图引擎
98
- -o, --orm <orm> 添加 ORM <orm> 支持 (prisma|sequelize)
111
+ -o, --orm <orm> 添加 ORM <orm> 支持 (sequelize|prisma)
99
112
  -c, --css <engine> 添加样式表引擎 <engine> 支持 (less|stylus|compass|sass)(默认为纯 css)
100
113
  --git 添加 .gitignore 文件
101
114
  --es6 生成 ES6 代码和模块类型项目(需要Node 22.x或更高版本)
@@ -108,8 +121,6 @@ $ npm install --save pg pg-hstore # Postgres
108
121
 
109
122
  **This project is forked from [express-generator](https://github.com/expressjs/generator) with additional features.**
110
123
 
111
- **ES6 support is implemented based on the [Pull Request](https://github.com/expressjs/generator/pull/316) submitted by [Dr. Jeff Jackson](https://github.com/drjeffjackson), with further optimizations and adjustments.**
112
-
113
124
  ## Features
114
125
 
115
126
  - **🚀 ES6 Support**: More modern and concise code.
@@ -157,39 +168,56 @@ After installing and starting Docker:
157
168
  $ docker-compose up -d
158
169
  ```
159
170
 
160
- This will start a MySQL database by default. PostgreSQL and Redis configurations are already in `docker-compose.yml`; adjust them according to your needs.
171
+ By default, the MySQL database will be started. PostgreSQL and Redis configurations are already included in
172
+ docker-compose.yml; please uncomment them as needed.
161
173
 
162
- ### Using Prisma
174
+ ### Using Sequelize
163
175
 
164
- Create the application:
176
+ **Create the application:**
165
177
 
166
178
  ```bash
167
- $ npx clwy-express-generator --view=ejs --orm=prisma --es6 es6-prisma-demo
168
- $ cd es6-prisma-demo
179
+ $ npx clwy-express-generator --view=ejs --orm=sequelize --es6 es6-sequelize-demo
180
+ $ cd es6-sequelize-demo
169
181
  $ npm i
170
182
  ```
171
183
 
172
- Initialize the database client:
184
+ **Install the database engine as needed:**
173
185
 
174
186
  ```bash
175
- $ npx prisma generate
187
+ $ npm install --save mysql2 # MySQL
188
+ $ npm install --save pg pg-hstore # Postgres
176
189
  ```
177
190
 
178
- ### Using Sequelize
191
+ The project has [clwy-sequelize-cli](https://github.com/clwy-cn/clwy-sequelize-cli) integrated by default. Using the following commands will generate **ES6-style** models, migrations, and seed files.
179
192
 
180
- Create the application:
193
+ **Generate model and migration files:**
181
194
 
182
195
  ```bash
183
- $ npx clwy-express-generator --view=ejs --orm=sequelize --es6 es6-sequelize-demo
184
- $ cd es6-sequelize-demo
196
+ $ npx sequelize model:generate --name Article --attributes title:string,content:text
197
+ ```
198
+
199
+ **Generate seed file:**
200
+
201
+ ```bash
202
+ $ npx sequelize seed:generate --name article
203
+ ```
204
+
205
+ ### Using Prisma
206
+
207
+ **Create the application:**
208
+
209
+ ```bash
210
+ $ npx clwy-express-generator --view=ejs --orm=prisma --es6 es6-prisma-demo
211
+ # or: npx clwy-express-generator -v=ejs -o=prisma --es6 es6-prisma-demo
212
+
213
+ $ cd es6-prisma-demo
185
214
  $ npm i
186
215
  ```
187
216
 
188
- Install the database engine as needed:
217
+ **Initialize the database client:**
189
218
 
190
219
  ```bash
191
- $ npm install --save mysql2 # MySQL
192
- $ npm install --save pg pg-hstore # Postgres
220
+ $ npx prisma generate
193
221
  ```
194
222
 
195
223
  ## Command Line Options
@@ -199,7 +227,7 @@ This generator can be further configured with the following command line flags.
199
227
  --version Output the version number
200
228
  -v, --view <engine> Add view engine <engine> support (dust|ejs|hbs|hjs|pug|twig|vash|api) (defaults to ejs)
201
229
  --no-view Use static HTML instead of a view engine
202
- -o, --orm <orm> Add ORM <orm> support (prisma|sequelize)
230
+ -o, --orm <orm> Add ORM <orm> support (sequelize|prisma)
203
231
  -c, --css <engine> Add stylesheet engine <engine> support (less|stylus|compass|sass) (defaults to plain css)
204
232
  --git Add .gitignore file
205
233
  --es6 Generate ES6 code and module type project (requires Node 22.x or higher)
@@ -311,6 +311,11 @@ function createApplication(name, dir, options, done) {
311
311
  case 'sequelize':
312
312
  // copy Sequelize templates
313
313
  pkg.dependencies.sequelize = '^6.37.7'
314
+ if (options.es6) {
315
+ pkg.devDependencies['clwy-sequelize-cli'] = '^0.0.1';
316
+ } else {
317
+ pkg.devDependencies['sequelize-cli'] = '^6.6.5';
318
+ }
314
319
 
315
320
  mkdir(dir, 'migrations')
316
321
  mkdir(dir, 'seeders')
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "clwy-express-generator",
3
3
  "description": "Express' application generator",
4
4
  "homepage": "https://github.com/clwy-cn/clwy-express-generator",
5
- "version": "5.2.1",
5
+ "version": "5.2.3",
6
6
  "author": "TJ Holowaychuk <tj@vision-media.ca>",
7
7
  "contributors": [
8
8
  "Aaron Heckmann <aaron.heckmann+github@gmail.com>",