@appthen/cli 1.1.18 → 1.1.20

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 (3) hide show
  1. package/bin/main.js +150 -1
  2. package/dist/index.js +16 -16
  3. package/package.json +4 -2
package/bin/main.js CHANGED
@@ -3,13 +3,37 @@
3
3
  /* eslint-disable prefer-arrow-callback */
4
4
  /* eslint-disable @typescript-eslint/no-require-imports */
5
5
 
6
+ /**
7
+ * 导入包信息,用于获取版本号
8
+ */
6
9
  var pkg = require('../package.json');
7
10
 
11
+ /**
12
+ * 导入commander用于构建CLI命令行工具
13
+ */
8
14
  var program = require('commander');
9
15
 
16
+ // 设置版本信息命令
10
17
  program
11
18
  .version(pkg.version, '-v, --version', 'display version information');
12
19
 
20
+ /**
21
+ * generate命令 - 默认命令
22
+ * 用于从appthen生成代码
23
+ * 必需参数:
24
+ * -p, --id: 项目ID
25
+ * -a, --auth: 认证token
26
+ * 可选参数:
27
+ * -cc, --clear: 清除缓存
28
+ * -o, --output: 指定输出目录,默认为generated
29
+ * -fn, --filter: 过滤文档
30
+ * -fd, --folder: 按文件夹过滤文档
31
+ * -fr, --frame: 代码框架类型(web/app)
32
+ * -env, --env: 低代码环境
33
+ * -c, --cwd: 指定工作目录
34
+ * -q, --quiet: 安静模式,仅输出错误信息
35
+ * -vb, --verbose: 详细模式,输出更多信息
36
+ */
13
37
  program
14
38
  .command('generate', { isDefault: true })
15
39
  .description('Generate code from appthen')
@@ -43,13 +67,19 @@ program
43
67
  });
44
68
  });
45
69
 
70
+ /**
71
+ * watch命令
72
+ * 用于启动监听服务
73
+ * 参数与generate命令基本相同,额外增加:
74
+ * -m, --mode: 监听模式
75
+ * -a, --account: 用户ID
76
+ */
46
77
  program
47
78
  .command('watch')
48
79
  .description('start watch service')
49
80
  .requiredOption('-p, --id <id>', 'project id')
50
81
  .requiredOption('-a, --auth <auth>', 'auth token')
51
82
  .option('-cc, --clear <clear>', 'clear cache')
52
- // .option('-i, --input <input>', 'specify the input schema file')
53
83
  .option('-o, --output <output>', 'specify the output directory', 'generated')
54
84
  .option('-fn, --filter <filter>', 'filter docments')
55
85
  .option('-fd, --folder <folder>', 'filter docments by folder')
@@ -78,6 +108,10 @@ program
78
108
  });
79
109
  });
80
110
 
111
+ /**
112
+ * version命令
113
+ * 显示CLI版本信息
114
+ */
81
115
  program
82
116
  .command('version', { isDefault: false })
83
117
  .description('show cli version')
@@ -86,6 +120,12 @@ program
86
120
  process.exit();
87
121
  });
88
122
 
123
+ /**
124
+ * release命令
125
+ * 发布网站并上传到CDN/FTP/OSS/云存储
126
+ * 必需参数:
127
+ * -c, --cloud: 云存储类型
128
+ */
89
129
  program
90
130
  .command('release', { isDefault: false })
91
131
  .description('release website and upload to cdn / ftp / oss / cloud')
@@ -103,6 +143,12 @@ program
103
143
  });
104
144
  });
105
145
 
146
+ /**
147
+ * release-material命令
148
+ * 发布物料并上传到CDN
149
+ * 必需参数:
150
+ * -a, --auth: 认证token
151
+ */
106
152
  program
107
153
  .command('release-material', { isDefault: false })
108
154
  .description('release material and upload to cdn')
@@ -120,6 +166,13 @@ program
120
166
  });
121
167
  });
122
168
 
169
+ /**
170
+ * create命令
171
+ * 从模板创建新项目
172
+ * 必需参数:
173
+ * -t, --template: 模板名称
174
+ * -f, --folder: 文件夹名称
175
+ */
123
176
  program
124
177
  .command('create', { isDefault: false })
125
178
  .description('Create a new project from template')
@@ -137,4 +190,100 @@ program
137
190
  });
138
191
  });
139
192
 
193
+ /**
194
+ * sync-backend命令
195
+ * 从远程同步后端代码
196
+ * 必需参数:
197
+ * -a, --auth: 认证token
198
+ * 可选参数:
199
+ * -o, --output: 指定输出目录,默认为src/types
200
+ * -m, --mapping: 路径映射配置
201
+ * -cc, --clear: 清除缓存
202
+ * -c, --cwd: 指定工作目录
203
+ * -q, --quiet: 安静模式
204
+ * -vb, --verbose: 详细模式
205
+ */
206
+ program
207
+ .command('sync-backend')
208
+ .description('Sync backend code from remote')
209
+ .requiredOption('-p, --id <id>', 'project id')
210
+ .requiredOption('-a, --auth <auth>', 'auth token')
211
+ .option('-f, --framework <framework>', 'backend language framework', 'fastify')
212
+ .option('-o, --output <output>', 'specify the output directory', 'src/types')
213
+ .option('-m, --mapping <mapping>', 'path mapping configuration')
214
+ .option('-cc, --clear <clear>', 'clear cache')
215
+ .option('-c, --cwd <cwd>', 'specify the working directory', '.')
216
+ .option('-q, --quiet', 'be quiet, do not output anything unless get error', false)
217
+ .option('-vb, --verbose', 'be verbose, output more information', false)
218
+ .action(function doSync(command) {
219
+ var options = command?.opts?.() || {};
220
+ if (options.cwd) {
221
+ process.chdir(options.cwd);
222
+ }
223
+
224
+ require('../dist/index.js')
225
+ .syncBackend(options)
226
+ .then((retCode) => {
227
+ process.exit(retCode);
228
+ });
229
+ });
230
+
231
+ /**
232
+ * deploy-vercel命令
233
+ * 部署Fastify项目到Vercel
234
+ * 必需参数:
235
+ * -p, --project-id: Vercel项目ID
236
+ * -t, --token: Vercel API Token
237
+ * 可选参数:
238
+ * -pn, --project-name: 项目名称
239
+ * -e, --env: 环境变量,格式为 KEY=VALUE
240
+ * -o, --output: 构建输出目录
241
+ * -c, --cwd: 指定工作目录
242
+ * --prod: 部署到生产环境
243
+ */
244
+ program
245
+ .command('deploy-vercel')
246
+ .description('Deploy Fastify project to Vercel')
247
+ .requiredOption('-p, --project-id <projectId>', 'Vercel project ID')
248
+ .requiredOption('-t, --token <token>', 'Vercel API token')
249
+ .option('-pn, --project-name <projectName>', 'project name')
250
+ .option('-e, --env <env...>', 'environment variables (KEY=VALUE)')
251
+ .option('-o, --output <output>', 'build output directory', 'dist')
252
+ .option('-c, --cwd <cwd>', 'specify the working directory', '.')
253
+ .option('--prod', 'deploy to production', false)
254
+ .action(function doDeploy(command) {
255
+ var options = command?.opts?.() || {};
256
+ if (options.cwd) {
257
+ process.chdir(options.cwd);
258
+ }
259
+
260
+ // 处理环境变量
261
+ const env = {};
262
+ if (options.env) {
263
+ options.env.forEach(item => {
264
+ const [key, value] = item.split('=');
265
+ if (key && value) {
266
+ env[key] = value;
267
+ }
268
+ });
269
+ }
270
+
271
+ // 转换配置格式
272
+ const deployConfig = {
273
+ projectId: options.projectId,
274
+ token: options.token,
275
+ name: options.projectName,
276
+ target: options.prod ? 'production' : 'preview',
277
+ outputDir: options.output,
278
+ env
279
+ };
280
+
281
+ require('../dist/index.js')
282
+ .deployToVercel(deployConfig)
283
+ .then((retCode) => {
284
+ process.exit(retCode);
285
+ });
286
+ });
287
+
288
+ // 解析命令行参数
140
289
  program.parse(process.argv);