@cloudbase/cli 2.10.0 → 2.11.0-beta.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.
Files changed (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -53,41 +44,39 @@ let DbListCommand = class DbListCommand extends common_1.Command {
53
44
  desc: (0, i18n_1.t)('列出云端所有数据模型'),
54
45
  };
55
46
  }
56
- execute(envId, log) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const loading = (0, utils_1.loadingFactory)();
59
- if (!envId) {
60
- envId = yield selectEnv();
61
- }
62
- else {
63
- log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
47
+ async execute(envId, log) {
48
+ const loading = (0, utils_1.loadingFactory)();
49
+ if (!envId) {
50
+ envId = await selectEnv();
51
+ }
52
+ else {
53
+ log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
54
+ }
55
+ if (!(await fs_extra_1.default.pathExists('cloudbaserc.json'))) {
56
+ await fs_extra_1.default.writeFile('cloudbaserc.json', JSON.stringify({
57
+ version: '2.0',
58
+ envId
59
+ }, null, 2), 'utf8');
60
+ }
61
+ loading.start((0, i18n_1.t)('数据加载中...'));
62
+ const data = await (0, db_1.listModels)({ envId });
63
+ loading.stop();
64
+ const head = [(0, i18n_1.t)('名称'), (0, i18n_1.t)('标识'), (0, i18n_1.t)('创建时间')];
65
+ const sortData = data.sort((prev, next) => {
66
+ if (prev.Alias > next.Alias) {
67
+ return 1;
64
68
  }
65
- if (!(yield fs_extra_1.default.pathExists('cloudbaserc.json'))) {
66
- yield fs_extra_1.default.writeFile('cloudbaserc.json', JSON.stringify({
67
- version: '2.0',
68
- envId
69
- }, null, 2), 'utf8');
69
+ if (prev.Alias < next.Alias) {
70
+ return -1;
70
71
  }
71
- loading.start((0, i18n_1.t)('数据加载中...'));
72
- const data = yield (0, db_1.listModels)({ envId });
73
- loading.stop();
74
- const head = [(0, i18n_1.t)('名称'), (0, i18n_1.t)('标识'), (0, i18n_1.t)('创建时间')];
75
- const sortData = data.sort((prev, next) => {
76
- if (prev.Alias > next.Alias) {
77
- return 1;
78
- }
79
- if (prev.Alias < next.Alias) {
80
- return -1;
81
- }
82
- return 0;
83
- });
84
- const tableData = sortData.map((item) => [
85
- item.Title,
86
- item.Name,
87
- item.CreatedAt
88
- ]);
89
- (0, utils_1.printHorizontalTable)(head, tableData);
72
+ return 0;
90
73
  });
74
+ const tableData = sortData.map((item) => [
75
+ item.Title,
76
+ item.Name,
77
+ item.CreatedAt
78
+ ]);
79
+ (0, utils_1.printHorizontalTable)(head, tableData);
91
80
  }
92
81
  };
93
82
  __decorate([
@@ -126,66 +115,64 @@ let DbPullCommand = class DbPullCommand extends common_1.Command {
126
115
  desc: (0, i18n_1.t)('从云端拉取多个数据模型到本地'),
127
116
  };
128
117
  }
129
- execute(envId, params, log) {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- if (!(yield fs_extra_1.default.pathExists('tsconfig.json'))) {
132
- yield fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify({
133
- compilerOptions: {
134
- allowJs: true
135
- }
136
- }, null, 2), 'utf8');
137
- }
138
- else {
139
- const config = yield fs_extra_1.default.readJson('tsconfig.json', 'utf8');
140
- (0, lodash_1.set)(config, 'compilerOptions.allowJs', true);
141
- yield fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify(config, null, 2), 'utf8');
142
- }
143
- if (!envId) {
144
- envId = yield selectEnv();
145
- }
146
- else {
147
- log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
148
- }
149
- if (!(yield fs_extra_1.default.pathExists('cloudbaserc.json'))) {
150
- yield fs_extra_1.default.writeFile('cloudbaserc.json', JSON.stringify({
151
- version: '2.0',
152
- envId
153
- }, null, 2), 'utf8');
154
- }
155
- let { name = '', dir } = params;
156
- name = name.split(',').map(item => item.trim()).filter(item => item);
157
- if (!name.length) {
158
- name = yield selectModel(envId);
159
- }
160
- const data = yield (0, db_1.listModels)({
161
- envId,
162
- name
163
- });
164
- const dataModelList = data.map((item) => {
165
- const schema = JSON.parse(item.Schema);
166
- schema.title = item.Title;
167
- return {
168
- name: item.Name,
169
- schema,
170
- title: item.Title
171
- };
172
- });
173
- if (!dir) {
174
- dir = 'database-schemas';
175
- if (!fs_extra_1.default.existsSync(dir)) {
176
- fs_extra_1.default.mkdirSync(dir);
118
+ async execute(envId, params, log) {
119
+ if (!(await fs_extra_1.default.pathExists('tsconfig.json'))) {
120
+ await fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify({
121
+ compilerOptions: {
122
+ allowJs: true
177
123
  }
178
- dataModelList.forEach((item) => {
179
- const fileName = `${dir}/${item.name}.json`;
180
- fs_extra_1.default.writeFileSync(fileName, JSON.stringify(item.schema, null, 4));
181
- log.success((0, i18n_1.t)('同步数据模型成功。文件名称:{{fileName}}', { fileName }));
182
- });
183
- }
184
- const dts = yield (0, dts_1.generateDataModelDTS)(dataModelList);
185
- const dtsFileName = 'cloud-models.d.ts';
186
- yield fs_extra_1.default.writeFile(dtsFileName, dts);
187
- log.success((0, i18n_1.t)('同步数据模型类型定义文件成功,调用 SDK 时可支持智能字段提示。文件名称:{{dtsFileName}}', { dtsFileName }));
124
+ }, null, 2), 'utf8');
125
+ }
126
+ else {
127
+ const config = await fs_extra_1.default.readJson('tsconfig.json', 'utf8');
128
+ (0, lodash_1.set)(config, 'compilerOptions.allowJs', true);
129
+ await fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify(config, null, 2), 'utf8');
130
+ }
131
+ if (!envId) {
132
+ envId = await selectEnv();
133
+ }
134
+ else {
135
+ log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
136
+ }
137
+ if (!(await fs_extra_1.default.pathExists('cloudbaserc.json'))) {
138
+ await fs_extra_1.default.writeFile('cloudbaserc.json', JSON.stringify({
139
+ version: '2.0',
140
+ envId
141
+ }, null, 2), 'utf8');
142
+ }
143
+ let { name = '', dir } = params;
144
+ name = name.split(',').map(item => item.trim()).filter(item => item);
145
+ if (!name.length) {
146
+ name = await selectModel(envId);
147
+ }
148
+ const data = await (0, db_1.listModels)({
149
+ envId,
150
+ name
188
151
  });
152
+ const dataModelList = data.map((item) => {
153
+ const schema = JSON.parse(item.Schema);
154
+ schema.title = item.Title;
155
+ return {
156
+ name: item.Name,
157
+ schema,
158
+ title: item.Title
159
+ };
160
+ });
161
+ if (!dir) {
162
+ dir = 'database-schemas';
163
+ if (!fs_extra_1.default.existsSync(dir)) {
164
+ fs_extra_1.default.mkdirSync(dir);
165
+ }
166
+ dataModelList.forEach((item) => {
167
+ const fileName = `${dir}/${item.name}.json`;
168
+ fs_extra_1.default.writeFileSync(fileName, JSON.stringify(item.schema, null, 4));
169
+ log.success((0, i18n_1.t)('同步数据模型成功。文件名称:{{fileName}}', { fileName }));
170
+ });
171
+ }
172
+ const dts = await (0, dts_1.generateDataModelDTS)(dataModelList);
173
+ const dtsFileName = 'cloud-models.d.ts';
174
+ await fs_extra_1.default.writeFile(dtsFileName, dts);
175
+ log.success((0, i18n_1.t)('同步数据模型类型定义文件成功,调用 SDK 时可支持智能字段提示。文件名称:{{dtsFileName}}', { dtsFileName }));
189
176
  }
190
177
  };
191
178
  __decorate([
@@ -225,96 +212,94 @@ let DbPushCommand = class DbPushCommand extends common_1.Command {
225
212
  desc: (0, i18n_1.t)('将本地数据模型推送到云端'),
226
213
  };
227
214
  }
228
- execute(envId, params, log) {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- if (!envId) {
231
- envId = yield selectEnv();
215
+ async execute(envId, params, log) {
216
+ if (!envId) {
217
+ envId = await selectEnv();
218
+ }
219
+ else {
220
+ log.info((0, i18n_1.t)('使用环境 Id:{{envId}}', { envId }));
221
+ }
222
+ let { name = '', dir } = params;
223
+ name = name.split(',').map(item => item.trim()).filter(item => item);
224
+ if (!dir) {
225
+ dir = 'database-schemas';
226
+ if (!fs_extra_1.default.existsSync(dir)) {
227
+ throw new error_1.CloudBaseError((0, i18n_1.t)('目录 {{dir}} 不存在,请指定正确的目录', { dir }));
232
228
  }
233
- else {
234
- log.info((0, i18n_1.t)('使用环境 Id:{{envId}}', { envId }));
235
- }
236
- let { name = '', dir } = params;
237
- name = name.split(',').map(item => item.trim()).filter(item => item);
238
- if (!dir) {
239
- dir = 'database-schemas';
240
- if (!fs_extra_1.default.existsSync(dir)) {
241
- throw new error_1.CloudBaseError((0, i18n_1.t)('目录 {{dir}} 不存在,请指定正确的目录', { dir }));
229
+ }
230
+ if (!name.length) {
231
+ name = fs_extra_1.default.readdirSync(dir).map(item => item.replace('.json', ''));
232
+ }
233
+ if (!name.length) {
234
+ throw new error_1.CloudBaseError((0, i18n_1.t)('目录 {{dir}} 中没有找到任何数据模型', { dir }));
235
+ }
236
+ const ids = [];
237
+ for (const modelName of name) {
238
+ log.info((0, i18n_1.t)('开始检查数据模型 {{modelName}}', { modelName }));
239
+ const modelPath = path_1.default.join(process.cwd(), dir, `${modelName}.json`);
240
+ const model = require(modelPath);
241
+ const existModel = await (0, db_1.getModel)({
242
+ envId,
243
+ name: modelName
244
+ });
245
+ if (existModel) {
246
+ const confirm = await inquirer_1.default.prompt([
247
+ {
248
+ type: 'confirm',
249
+ name: 'confirm',
250
+ message: (0, i18n_1.t)('数据模型 {{modelName}} 已存在,是否更新?', { modelName })
251
+ }
252
+ ]);
253
+ if (!confirm.confirm) {
254
+ log.info((0, i18n_1.t)('跳过更新数据模型 {{modelName}}', { modelName }));
255
+ continue;
242
256
  }
243
- }
244
- if (!name.length) {
245
- name = fs_extra_1.default.readdirSync(dir).map(item => item.replace('.json', ''));
246
- }
247
- if (!name.length) {
248
- throw new error_1.CloudBaseError((0, i18n_1.t)('目录 {{dir}} 中没有找到任何数据模型', { dir }));
249
- }
250
- const ids = [];
251
- for (const modelName of name) {
252
- log.info((0, i18n_1.t)('开始检查数据模型 {{modelName}}', { modelName }));
253
- const modelPath = path_1.default.join(process.cwd(), dir, `${modelName}.json`);
254
- const model = require(modelPath);
255
- const existModel = yield (0, db_1.getModel)({
257
+ await (0, db_1.updateModel)({
256
258
  envId,
257
- name: modelName
259
+ id: existModel.Id,
260
+ title: model.title || existModel.Title,
261
+ schema: model
258
262
  });
259
- if (existModel) {
260
- const confirm = yield inquirer_1.default.prompt([
261
- {
262
- type: 'confirm',
263
- name: 'confirm',
264
- message: (0, i18n_1.t)('数据模型 {{modelName}} 已存在,是否更新?', { modelName })
265
- }
266
- ]);
267
- if (!confirm.confirm) {
268
- log.info((0, i18n_1.t)('跳过更新数据模型 {{modelName}}', { modelName }));
269
- continue;
270
- }
271
- yield (0, db_1.updateModel)({
272
- envId,
273
- id: existModel.Id,
274
- title: model.title || existModel.Title,
275
- schema: model
276
- });
277
- ids.push(existModel.Id);
278
- const link = (0, utils_1.genClickableLink)(`${utils_1.EUrl.CloudAdmin}/#/management/data-model/${existModel.Id}`);
279
- log.success((0, i18n_1.t)('更新数据模型 {{modelName}} 成功,点击查看 {{link}}', { modelName, link }));
280
- }
281
- else {
282
- const confirm = yield inquirer_1.default.prompt([
283
- {
284
- type: 'confirm',
285
- name: 'confirm',
286
- message: (0, i18n_1.t)('数据模型 {{modelName}} 不存在,是否创建?', { modelName })
287
- }
288
- ]);
289
- if (!confirm.confirm) {
290
- log.info((0, i18n_1.t)('跳过创建数据模型 {{modelName}}', { modelName }));
291
- continue;
292
- }
293
- const createModelRes = yield (0, db_1.createModel)({
294
- envId,
295
- name: modelName,
296
- title: model.title || modelName,
297
- schema: model
298
- });
299
- ids.push(createModelRes.Id);
300
- const link = (0, utils_1.genClickableLink)(`${utils_1.EUrl.CloudAdmin}/#/management/data-model/${createModelRes.Id}}`);
301
- log.success((0, i18n_1.t)('创建数据模型 {{modelName}} 成功, 点击查看 {{link}}', { modelName, link }));
302
- }
263
+ ids.push(existModel.Id);
264
+ const link = (0, utils_1.genClickableLink)(`${utils_1.EUrl.CloudAdmin}/#/management/data-model/${existModel.Id}`);
265
+ log.success((0, i18n_1.t)('更新数据模型 {{modelName}} 成功,点击查看 {{link}}', { modelName, link }));
303
266
  }
304
- const confirmPublish = yield inquirer_1.default.prompt([
305
- {
306
- type: 'confirm',
307
- name: 'confirm',
308
- message: (0, i18n_1.t)('数据模型已经导入成功,是否发布?')
267
+ else {
268
+ const confirm = await inquirer_1.default.prompt([
269
+ {
270
+ type: 'confirm',
271
+ name: 'confirm',
272
+ message: (0, i18n_1.t)('数据模型 {{modelName}} 不存在,是否创建?', { modelName })
273
+ }
274
+ ]);
275
+ if (!confirm.confirm) {
276
+ log.info((0, i18n_1.t)('跳过创建数据模型 {{modelName}}', { modelName }));
277
+ continue;
309
278
  }
310
- ]);
311
- if (confirmPublish.confirm) {
312
- const publishRes = yield (0, db_1.publishModel)({
279
+ const createModelRes = await (0, db_1.createModel)({
313
280
  envId,
314
- ids
281
+ name: modelName,
282
+ title: model.title || modelName,
283
+ schema: model
315
284
  });
285
+ ids.push(createModelRes.Id);
286
+ const link = (0, utils_1.genClickableLink)(`${utils_1.EUrl.CloudAdmin}/#/management/data-model/${createModelRes.Id}}`);
287
+ log.success((0, i18n_1.t)('创建数据模型 {{modelName}} 成功, 点击查看 {{link}}', { modelName, link }));
316
288
  }
317
- });
289
+ }
290
+ const confirmPublish = await inquirer_1.default.prompt([
291
+ {
292
+ type: 'confirm',
293
+ name: 'confirm',
294
+ message: (0, i18n_1.t)('数据模型已经导入成功,是否发布?')
295
+ }
296
+ ]);
297
+ if (confirmPublish.confirm) {
298
+ const publishRes = await (0, db_1.publishModel)({
299
+ envId,
300
+ ids
301
+ });
302
+ }
318
303
  }
319
304
  };
320
305
  __decorate([
@@ -330,67 +315,63 @@ DbPushCommand = __decorate([
330
315
  (0, common_1.ICommand)()
331
316
  ], DbPushCommand);
332
317
  exports.DbPushCommand = DbPushCommand;
333
- function selectEnv() {
334
- return __awaiter(this, void 0, void 0, function* () {
335
- const data = yield (0, env_1.listEnvs)();
336
- const sortData = data.sort((prev, next) => {
337
- if (prev.Alias > next.Alias) {
338
- return 1;
339
- }
340
- if (prev.Alias < next.Alias) {
341
- return -1;
342
- }
343
- return 0;
344
- });
345
- const choices = sortData.map((item) => {
346
- return {
347
- name: `${item.Alias || item.EnvId} (${item.EnvId}) ${item.Status === 'NORMAL' ? (0, i18n_1.t)('正常') : (0, i18n_1.t)('不可用')}`,
348
- value: item.EnvId,
349
- short: item.envId
350
- };
351
- });
352
- const questions = [
353
- {
354
- type: 'list',
355
- name: 'env',
356
- message: (0, i18n_1.t)('请先选择一个云开发环境'),
357
- choices: choices
358
- }
359
- ];
360
- const answers = yield inquirer_1.default.prompt(questions);
361
- return answers.env;
318
+ async function selectEnv() {
319
+ const data = await (0, env_1.listEnvs)();
320
+ const sortData = data.sort((prev, next) => {
321
+ if (prev.Alias > next.Alias) {
322
+ return 1;
323
+ }
324
+ if (prev.Alias < next.Alias) {
325
+ return -1;
326
+ }
327
+ return 0;
328
+ });
329
+ const choices = sortData.map((item) => {
330
+ return {
331
+ name: `${item.Alias || item.EnvId} (${item.EnvId}) ${item.Status === 'NORMAL' ? (0, i18n_1.t)('正常') : (0, i18n_1.t)('不可用')}`,
332
+ value: item.EnvId,
333
+ short: item.envId
334
+ };
362
335
  });
336
+ const questions = [
337
+ {
338
+ type: 'list',
339
+ name: 'env',
340
+ message: (0, i18n_1.t)('请先选择一个云开发环境'),
341
+ choices: choices
342
+ }
343
+ ];
344
+ const answers = await inquirer_1.default.prompt(questions);
345
+ return answers.env;
363
346
  }
364
- function selectModel(envId) {
365
- return __awaiter(this, void 0, void 0, function* () {
366
- const data = yield (0, db_1.listModels)({
367
- envId
368
- });
369
- const sortData = data.sort((prev, next) => {
370
- if (prev.CreatedAt > next.CreatedAt) {
371
- return 1;
372
- }
373
- if (prev.CreatedAt < next.CreatedAt) {
374
- return -1;
375
- }
376
- return 0;
377
- });
378
- const choices = sortData.map((item) => {
379
- return {
380
- name: `${item.Title} (${item.Name})`,
381
- value: item.Name,
382
- short: item.Name
383
- };
384
- });
385
- const questions = [
386
- {
387
- type: 'checkbox',
388
- name: 'model',
389
- message: (0, i18n_1.t)('请选择数据模型'),
390
- choices: choices
391
- }
392
- ];
393
- const answers = yield inquirer_1.default.prompt(questions);
394
- return answers.model;
347
+ async function selectModel(envId) {
348
+ const data = await (0, db_1.listModels)({
349
+ envId
350
+ });
351
+ const sortData = data.sort((prev, next) => {
352
+ if (prev.CreatedAt > next.CreatedAt) {
353
+ return 1;
354
+ }
355
+ if (prev.CreatedAt < next.CreatedAt) {
356
+ return -1;
357
+ }
358
+ return 0;
359
+ });
360
+ const choices = sortData.map((item) => {
361
+ return {
362
+ name: `${item.Title} (${item.Name})`,
363
+ value: item.Name,
364
+ short: item.Name
365
+ };
395
366
  });
367
+ const questions = [
368
+ {
369
+ type: 'checkbox',
370
+ name: 'model',
371
+ message: (0, i18n_1.t)('请选择数据模型'),
372
+ choices: choices
373
+ }
374
+ ];
375
+ const answers = await inquirer_1.default.prompt(questions);
376
+ return answers.model;
396
377
  }
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.EnvRenameCommand = exports.EnvListCommand = void 0;
25
16
  const common_1 = require("../common");
@@ -40,36 +31,34 @@ let EnvListCommand = class EnvListCommand extends common_1.Command {
40
31
  requiredEnvId: false
41
32
  };
42
33
  }
43
- execute(log) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const loading = (0, utils_1.loadingFactory)();
46
- loading.start((0, i18n_1.t)('数据加载中...'));
47
- const data = yield (0, env_1.listEnvs)();
48
- loading.stop();
49
- const head = [(0, i18n_1.t)('名称'), (0, i18n_1.t)('环境 Id'), (0, i18n_1.t)('套餐版本'), (0, i18n_1.t)('来源'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('环境状态')];
50
- const sortData = data.sort((prev, next) => {
51
- if (prev.Alias > next.Alias) {
52
- return 1;
53
- }
54
- if (prev.Alias < next.Alias) {
55
- return -1;
56
- }
57
- return 0;
58
- });
59
- const tableData = sortData.map((item) => [
60
- item.Alias,
61
- item.EnvId,
62
- item.PackageName || (0, i18n_1.t)('按量计费'),
63
- item.Source === constants_1.EnvSource.MINIAPP ? (0, i18n_1.t)('小程序') : (0, i18n_1.t)('云开发'),
64
- item.CreateTime,
65
- item.Status === 'NORMAL' ? (0, i18n_1.t)('正常') : (0, i18n_1.t)('不可用')
66
- ]);
67
- (0, utils_1.printHorizontalTable)(head, tableData);
68
- const unavailableEnv = data.find((item) => item.Status === 'UNAVAILABLE');
69
- if (unavailableEnv) {
70
- log.warn((0, i18n_1.t)('您的环境中存在不可用的环境:[{{envId}}],请留意!', { envId: unavailableEnv.EnvId }));
34
+ async execute(log) {
35
+ const loading = (0, utils_1.loadingFactory)();
36
+ loading.start((0, i18n_1.t)('数据加载中...'));
37
+ const data = await (0, env_1.listEnvs)();
38
+ loading.stop();
39
+ const head = [(0, i18n_1.t)('名称'), (0, i18n_1.t)('环境 Id'), (0, i18n_1.t)('套餐版本'), (0, i18n_1.t)('来源'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('环境状态')];
40
+ const sortData = data.sort((prev, next) => {
41
+ if (prev.Alias > next.Alias) {
42
+ return 1;
71
43
  }
44
+ if (prev.Alias < next.Alias) {
45
+ return -1;
46
+ }
47
+ return 0;
72
48
  });
49
+ const tableData = sortData.map((item) => [
50
+ item.Alias,
51
+ item.EnvId,
52
+ item.PackageName || (0, i18n_1.t)('按量计费'),
53
+ item.Source === constants_1.EnvSource.MINIAPP ? (0, i18n_1.t)('小程序') : (0, i18n_1.t)('云开发'),
54
+ item.CreateTime,
55
+ item.Status === 'NORMAL' ? (0, i18n_1.t)('正常') : (0, i18n_1.t)('不可用')
56
+ ]);
57
+ (0, utils_1.printHorizontalTable)(head, tableData);
58
+ const unavailableEnv = data.find((item) => item.Status === 'UNAVAILABLE');
59
+ if (unavailableEnv) {
60
+ log.warn((0, i18n_1.t)('您的环境中存在不可用的环境:[{{envId}}],请留意!', { envId: unavailableEnv.EnvId }));
61
+ }
73
62
  }
74
63
  };
75
64
  __decorate([
@@ -99,19 +88,17 @@ let EnvRenameCommand = class EnvRenameCommand extends common_1.Command {
99
88
  requiredEnvId: false
100
89
  };
101
90
  }
102
- execute(envId, params, log) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- log.verbose(params);
105
- const name = params === null || params === void 0 ? void 0 : params[0];
106
- if (!name) {
107
- throw new error_1.CloudBaseError((0, i18n_1.t)('环境别名不能为空!'));
108
- }
109
- yield (0, env_1.updateEnvInfo)({
110
- envId: envId,
111
- alias: name
112
- });
113
- log.success((0, i18n_1.t)('更新环境别名成功!'));
91
+ async execute(envId, params, log) {
92
+ log.verbose(params);
93
+ const name = params === null || params === void 0 ? void 0 : params[0];
94
+ if (!name) {
95
+ throw new error_1.CloudBaseError((0, i18n_1.t)('环境别名不能为空!'));
96
+ }
97
+ await (0, env_1.updateEnvInfo)({
98
+ envId: envId,
99
+ alias: name
114
100
  });
101
+ log.success((0, i18n_1.t)('更新环境别名成功!'));
115
102
  }
116
103
  };
117
104
  __decorate([