create-pangza 1.0.1 → 2.0.0

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
@@ -13,6 +13,10 @@ npm create pangza@latest -- init my-app
13
13
  交互勾选模块:`orm` / `auth` / `redis` / `log` / `schedule` / `encrypt` / `validate`。
14
14
  勾选 `orm` / `redis` 时会写入 `EnableOrm()` / `EnableRedis()`;未勾选则启动不连库、不因缺配置报错。不生成 `.gitkeep`。
15
15
 
16
+ 初始化还会生成:
17
+ - `application.yaml`:默认 `server.port: 5270`;按所选模块追加 `redis` / `datasource`+`orm` 等
18
+ - `tsconfig.json`:`@/*` → `src/*`(dev:`tsconfig-paths`;build:`tsc-alias`)
19
+
16
20
  ```bash
17
21
  npx create-pangza init my-app --modules=orm,auth,redis --db=mysql
18
22
  ```
package/lib/generate.js CHANGED
@@ -31,7 +31,9 @@ function findProjectRoot(cwd = process.cwd()) {
31
31
  ...(json.dependencies || {}),
32
32
  ...(json.devDependencies || {}),
33
33
  };
34
- if (deps["@pangza/express"]) return dir;
34
+ if (deps["@pangza/express"]) {
35
+ return dir;
36
+ }
35
37
  } catch {
36
38
  /* ignore */
37
39
  }
@@ -59,7 +61,7 @@ function writeFile(filePath, content, { force }) {
59
61
  }
60
62
 
61
63
  function tplEntity({ Pascal, snake }) {
62
- return `import { TableField, TableId, TableName } from "@pangza/express";
64
+ return `import { TableField, TableId, TableName } from "@pangza/orm";
63
65
 
64
66
  @TableName("${snake}")
65
67
  export default class ${Pascal}Entity {
@@ -89,7 +91,7 @@ export default class ${Pascal}Entity {
89
91
  }
90
92
 
91
93
  function tplMapper({ Pascal, fileBase }) {
92
- return `import { Mapper, MapperType } from "@pangza/express";
94
+ return `import { Mapper, MapperType } from "@pangza/orm";
93
95
  import ${Pascal}Entity from "../entity/${fileBase}";
94
96
 
95
97
  @Mapper(${Pascal}Entity)
package/lib/modules.js CHANGED
@@ -1,41 +1,41 @@
1
1
  "use strict";
2
2
 
3
- /** 可选能力模块(当前均由单包 @pangza/express 提供,差异在依赖与脚手架文件) */
3
+ /** ??????????????????????? */
4
4
  const MODULES = [
5
5
  {
6
6
  id: "orm",
7
7
  label: "ORM",
8
- hint: "Db / Mapper / QueryWrapper / 多数据源",
8
+ hint: "Db / Mapper / QueryWrapper / ????",
9
9
  },
10
10
  {
11
11
  id: "auth",
12
12
  label: "Auth",
13
- hint: "登录态、角色权限装饰器(建议同时选 Redis)",
13
+ hint: "????????????????? Redis?",
14
14
  },
15
15
  {
16
16
  id: "redis",
17
17
  label: "Redis",
18
- hint: "缓存、限流、Auth token 存储",
18
+ hint: "??????Auth token ??",
19
19
  },
20
20
  {
21
21
  id: "log",
22
22
  label: "Log",
23
- hint: "操作审计日志装饰器",
23
+ hint: "?????????",
24
24
  },
25
25
  {
26
26
  id: "schedule",
27
27
  label: "Schedule",
28
- hint: "定时任务 (cron)",
28
+ hint: "???? (cron)",
29
29
  },
30
30
  {
31
31
  id: "encrypt",
32
32
  label: "Encrypt",
33
- hint: "AES 等传输加密工具",
33
+ hint: "AES ???????",
34
34
  },
35
35
  {
36
36
  id: "validate",
37
37
  label: "Validate",
38
- hint: "参数校验装饰器",
38
+ hint: "?????????? @pangza/express?",
39
39
  },
40
40
  ];
41
41
 
@@ -81,7 +81,7 @@ const DB_ENV = {
81
81
  /** @param {string[]} moduleIds @param {string} [dbType] */
82
82
  function resolveDependencies(moduleIds, dbType = "mysql") {
83
83
  const deps = {
84
- "@pangza/express": "^1.0.1",
84
+ "@pangza/express": "^2.0.0",
85
85
  cors: "^2.8.5",
86
86
  express: "^5.2.1",
87
87
  inversify: "^8.2.3",
@@ -90,18 +90,28 @@ function resolveDependencies(moduleIds, dbType = "mysql") {
90
90
  const set = new Set(moduleIds);
91
91
 
92
92
  if (set.has("orm")) {
93
+ deps["@pangza/orm"] = "^2.0.0";
93
94
  Object.assign(deps, DB_DEPS[dbType] || DB_DEPS.mysql);
94
95
  }
95
96
  if (set.has("redis") || set.has("auth")) {
97
+ deps["@pangza/redis"] = "^2.0.0";
96
98
  deps.redis = "^6.2.1";
97
99
  }
98
100
  if (set.has("auth")) {
101
+ deps["@pangza/auth"] = "^2.0.0";
99
102
  deps.jsonwebtoken = "^9.0.3";
100
103
  deps.bcryptjs = "^3.0.3";
101
104
  }
105
+ if (set.has("log")) {
106
+ deps["@pangza/log"] = "^2.0.0";
107
+ }
102
108
  if (set.has("schedule")) {
109
+ deps["@pangza/schedule"] = "^2.0.0";
103
110
  deps["node-cron"] = "^4.6.0";
104
111
  }
112
+ if (set.has("encrypt")) {
113
+ deps["@pangza/encrypt"] = "^2.0.0";
114
+ }
105
115
 
106
116
  return deps;
107
117
  }
@@ -142,34 +152,146 @@ function resolveDirs(moduleIds) {
142
152
  return dirs;
143
153
  }
144
154
 
155
+ const DB_YAML = {
156
+ mysql: {
157
+ type: "mysql",
158
+ port: 3306,
159
+ user: "root",
160
+ database: "pangza",
161
+ },
162
+ postgresql: {
163
+ type: "postgresql",
164
+ port: 5432,
165
+ user: "postgres",
166
+ database: "pangza",
167
+ },
168
+ mssql: {
169
+ type: "sqlserver",
170
+ port: 1433,
171
+ user: "sa",
172
+ database: "pangza",
173
+ },
174
+ };
175
+
145
176
  /**
146
- * 生成空项目入口:只起 HTTP;选了 redis/orm 才 Enable*,否则启动不连库。
177
+ * ?? application.yaml??? server.port=5270?
178
+ * @param {string[]} moduleIds
179
+ * @param {string} [dbType]
180
+ */
181
+ function generateApplicationYaml(moduleIds, dbType = "mysql") {
182
+ const set = new Set(moduleIds);
183
+ const lines = [
184
+ "# Generated by create-pangza init",
185
+ "# profile: PANGZA_PROFILE / APP_ENV / NODE_ENV??? development",
186
+ "",
187
+ "server:",
188
+ " port: 5270",
189
+ " trustProxy: false",
190
+ ];
191
+
192
+ if (set.has("redis") || set.has("auth")) {
193
+ lines.push(
194
+ "",
195
+ "redis:",
196
+ " host: 127.0.0.1",
197
+ " port: 6379",
198
+ ' password: ""',
199
+ " db: 0",
200
+ ' keyPrefix: "pangza:"',
201
+ " mode: standalone",
202
+ );
203
+ }
204
+
205
+ if (set.has("orm")) {
206
+ const db = DB_YAML[dbType] || DB_YAML.mysql;
207
+ lines.push(
208
+ "",
209
+ "datasource:",
210
+ " default:",
211
+ ` type: ${db.type}`,
212
+ " host: 127.0.0.1",
213
+ ` port: ${db.port}`,
214
+ ` user: ${db.user}`,
215
+ ' password: ""',
216
+ ` database: ${db.database}`,
217
+ " connectionLimit: 10",
218
+ "",
219
+ "orm:",
220
+ " logicDelete: true",
221
+ " logicDeleteField: delete_flag",
222
+ " logicDeleteValue: 1",
223
+ " logicNotDeleteValue: 0",
224
+ " idType: ASSIGN_ID",
225
+ " mapUnderscoreToCamelCase: true",
226
+ " mapperLocations: []",
227
+ " sqlLog:",
228
+ " enabled: false",
229
+ );
230
+ }
231
+
232
+ if (set.has("encrypt")) {
233
+ lines.push("", "# encrypt: ????????????????????");
234
+ }
235
+
236
+ if (set.has("schedule")) {
237
+ lines.push("", "# schedule: ???? src/schedule?? Application.scan ??");
238
+ }
239
+
240
+ if (set.has("log")) {
241
+ lines.push("", "# log: ?? registry(Log({ writer })) ??????");
242
+ }
243
+
244
+ if (set.has("auth")) {
245
+ lines.push(
246
+ "",
247
+ "# auth: jwtSecret ???? Auth({ ... }) ?????? yaml ????????",
248
+ );
249
+ }
250
+
251
+ lines.push("");
252
+ return lines.join("\n");
253
+ }
254
+
255
+ /**
256
+ * ?????????? HTTP??? redis/orm ? Enable*????????
147
257
  * @param {string[]} moduleIds
148
258
  */
149
259
  function generateMainTs(moduleIds) {
150
260
  const set = new Set(moduleIds);
151
- const named = ["Application", "Logger"];
152
- if (set.has("orm")) named.push("EnableOrm");
153
- if (set.has("redis") || set.has("auth")) named.push("EnableRedis");
154
- if (set.has("auth")) named.push("Auth", "Redis");
155
- if (set.has("log")) named.push("Log");
156
261
 
157
262
  const imports = [
158
263
  'import "reflect-metadata";',
159
264
  'import cors from "cors";',
160
265
  'import { json } from "express";',
161
- `import { ${named.join(", ")} } from "@pangza/express";`,
266
+ 'import { Application, Logger } from "@pangza/express";',
162
267
  ];
163
268
 
269
+ if (set.has("orm")) {
270
+ imports.push('import { EnableOrm } from "@pangza/orm";');
271
+ }
272
+ if (set.has("redis") || set.has("auth")) {
273
+ imports.push('import Redis, { EnableRedis } from "@pangza/redis";');
274
+ }
275
+ if (set.has("auth")) {
276
+ imports.push('import Auth from "@pangza/auth";');
277
+ }
278
+ if (set.has("log")) {
279
+ imports.push('import Log from "@pangza/log";');
280
+ }
281
+
164
282
  const notes = [];
165
283
  if (set.has("schedule")) {
166
- notes.push("// Schedule: 在 src/schedule 编写任务并由扫描加载");
284
+ notes.push(
285
+ "// Schedule: ? src/schedule ???????????@pangza/schedule?",
286
+ );
167
287
  }
168
288
  if (set.has("encrypt")) {
169
- notes.push("// Encrypt: 从 @pangza/express 导入 AESUtil 等");
289
+ notes.push('// Encrypt: import { AESUtil } from "@pangza/encrypt"');
170
290
  }
171
291
  if (set.has("validate")) {
172
- notes.push("// Validate: 在 Controller 参数上使用校验装饰器");
292
+ notes.push(
293
+ "// Validate: ? Controller ????? @pangza/express ?????",
294
+ );
173
295
  }
174
296
 
175
297
  const chain = [
@@ -209,5 +331,6 @@ module.exports = {
209
331
  resolveDependencies,
210
332
  resolveEnvLines,
211
333
  resolveDirs,
334
+ generateApplicationYaml,
212
335
  generateMainTs,
213
336
  };
package/lib/scaffold.js CHANGED
@@ -6,6 +6,7 @@ const {
6
6
  resolveDependencies,
7
7
  resolveEnvLines,
8
8
  resolveDirs,
9
+ generateApplicationYaml,
9
10
  generateMainTs,
10
11
  } = require("./modules");
11
12
 
@@ -64,7 +65,7 @@ function scaffold(opts) {
64
65
  description: "Pangza Express app",
65
66
  scripts: {
66
67
  dev: "ts-node -r tsconfig-paths/register src/main.ts",
67
- build: "tsc -p tsconfig.json",
68
+ build: "tsc -p tsconfig.json && tsc-alias -p tsconfig.json",
68
69
  start: "node dist/main.js",
69
70
  },
70
71
  dependencies: resolveDependencies(modules, dbType),
@@ -73,6 +74,7 @@ function scaffold(opts) {
73
74
  "@types/express": "^5.0.6",
74
75
  "@types/node": "^22.0.0",
75
76
  "ts-node": "^10.9.2",
77
+ "tsc-alias": "^1.8.16",
76
78
  "tsconfig-paths": "^4.2.0",
77
79
  typescript: "^5.9.3",
78
80
  },
@@ -86,6 +88,10 @@ function scaffold(opts) {
86
88
  path.join(targetDir, ".env.example"),
87
89
  resolveEnvLines(modules, dbType).join("\n") + "\n",
88
90
  );
91
+ writeFile(
92
+ path.join(targetDir, "application.yaml"),
93
+ generateApplicationYaml(modules, dbType),
94
+ );
89
95
  writeFile(path.join(targetDir, "src", "main.ts"), generateMainTs(modules));
90
96
 
91
97
  writeFile(
@@ -102,12 +108,14 @@ ${modules.includes("orm") ? `Database: **${dbType}**\n` : ""}
102
108
  ## Run
103
109
 
104
110
  \`\`\`bash
105
- cp .env.example .env
111
+ cp .env.example .env # 可选;端口与库配置以 application.yaml 为准
106
112
  npm install
107
113
  npm run dev
108
114
  \`\`\`
109
115
 
110
- 需要 Redis / 数据库时,请在入口 \`registry(EnableRedis())\` / \`registry(EnableOrm())\`(脚手架勾选对应模块时已自动写入)。
116
+ - 默认端口:\`application.yaml\` → \`server.port: 5270\`
117
+ - 路径别名:\`@/*\` → \`src/*\`(dev 用 tsconfig-paths,build 用 tsc-alias)
118
+ - 需要 Redis / 数据库时,入口已按模块写入 \`EnableRedis()\` / \`EnableOrm()\`
111
119
  `,
112
120
  );
113
121
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-pangza",
3
- "version": "1.0.1",
4
- "description": "Scaffold & generate for @pangza/express (init / g controller|service|mapper|entity|all)",
3
+ "version": "2.0.0",
4
+ "description": "Scaffold & generate for @pangza/* (init / g controller|service|mapper|entity|all)",
5
5
  "bin": {
6
6
  "create-pangza": "./bin/create-pangza.js"
7
7
  },
@@ -4,6 +4,10 @@
4
4
  "module": "CommonJS",
5
5
  "outDir": "dist",
6
6
  "rootDir": "src",
7
+ "baseUrl": ".",
8
+ "paths": {
9
+ "@/*": ["src/*"]
10
+ },
7
11
  "strict": true,
8
12
  "esModuleInterop": true,
9
13
  "skipLibCheck": true,