@cloudbase/cli 2.5.1-alpha.2 → 2.5.1-alpha.4

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.
@@ -134,7 +134,7 @@ class Command extends events_1.EventEmitter {
134
134
  }
135
135
  }
136
136
  createProgram(instance, deprecate, newCmd) {
137
- const { cmd, desc, options, requiredEnvId = true, withoutAuth = false } = this.options;
137
+ const { cmd, desc, options, requiredEnvId = true, withoutAuth = false, autoRunLogin = false } = this.options;
138
138
  instance.storeOptionsAsProperties(false);
139
139
  options.forEach((option) => {
140
140
  const { hideHelp } = option;
@@ -161,7 +161,13 @@ class Command extends events_1.EventEmitter {
161
161
  loginState = (yield utils_1.authSupevisor.getLoginState());
162
162
  }
163
163
  if (!withoutAuth && !loginState) {
164
- throw new error_1.CloudBaseError('无有效身份信息,请使用 cloudbase login 登录');
164
+ if (autoRunLogin) {
165
+ console.log(chalk_1.default.bold.yellowBright('无有效身份信息,将自动为您打开授权页面。授权成功后请再重新执行命令'));
166
+ yield commander_1.program.parseAsync(['node', 'tcb', 'login']);
167
+ }
168
+ else {
169
+ throw new error_1.CloudBaseError('无有效身份信息,请使用 cloudbase login 登录');
170
+ }
165
171
  }
166
172
  if (!envId && requiredEnvId) {
167
173
  throw new error_1.CloudBaseError('未识别到有效的环境 Id,请使用 cloudbaserc 配置文件进行操作或通过 -e 参数指定环境 Id');
@@ -58,7 +58,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
58
58
  return (mod && mod.__esModule) ? mod : { "default": mod };
59
59
  };
60
60
  Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.ModelTypeSync = exports.LowCodeDeployApp = exports.LowCodeBuildAppConfig = exports.LowCodePreviewApp = exports.LowCodeBuildApp = exports.LowCodeWatch = void 0;
61
+ exports.TemplateSync = exports.ModelTypeSync = exports.LowCodeDeployApp = exports.LowCodeBuildAppConfig = exports.LowCodePreviewApp = exports.LowCodeBuildApp = exports.LowCodeWatch = void 0;
62
62
  const lodash_1 = require("lodash");
63
63
  const common_1 = require("../common");
64
64
  const decorators_1 = require("../../decorators");
@@ -67,6 +67,8 @@ const utils_2 = require("../../utils");
67
67
  const cloud_api_1 = require("@cloudbase/cloud-api");
68
68
  const toolbox_1 = require("@cloudbase/toolbox");
69
69
  const fs_extra_1 = __importDefault(require("fs-extra"));
70
+ const os_1 = __importDefault(require("os"));
71
+ const path_1 = __importDefault(require("path"));
70
72
  const dts_1 = require("../../utils/dts");
71
73
  let lowcodeCli;
72
74
  if (process.argv.includes('lowcode')) {
@@ -333,7 +335,8 @@ let ModelTypeSync = class ModelTypeSync extends common_1.Command {
333
335
  }
334
336
  ],
335
337
  desc: '同步数据模型类型定义文件',
336
- requiredEnvId: true
338
+ requiredEnvId: true,
339
+ autoRunLogin: true
337
340
  };
338
341
  }
339
342
  execute(ctx, log, options) {
@@ -362,7 +365,6 @@ let ModelTypeSync = class ModelTypeSync extends common_1.Command {
362
365
  EnvId: ctx.envId,
363
366
  PageIndex: 1,
364
367
  PageSize: 1000,
365
- DbInstanceType: 'FLEXDB',
366
368
  QuerySystemModel: true,
367
369
  QueryConnector: 0
368
370
  });
@@ -392,6 +394,107 @@ ModelTypeSync = __decorate([
392
394
  (0, common_1.ICommand)({ supportPrivate: true })
393
395
  ], ModelTypeSync);
394
396
  exports.ModelTypeSync = ModelTypeSync;
397
+ let TemplateSync = class TemplateSync extends common_1.Command {
398
+ get options() {
399
+ return {
400
+ cmd: 'template',
401
+ childCmd: 'sync',
402
+ options: [
403
+ {
404
+ flags: '--envId <envId>',
405
+ desc: '环境 ID'
406
+ }
407
+ ],
408
+ desc: '同步官方模板应用内容',
409
+ requiredEnvId: true
410
+ };
411
+ }
412
+ execute(ctx, log, options) {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ log.info('同步中...');
415
+ const envId = 'lowcode-5g5llxbq5bc9299e';
416
+ const fileDir = path_1.default.resolve(os_1.default.tmpdir(), 'templates');
417
+ yield fs_extra_1.default.ensureDir(fileDir);
418
+ yield fs_extra_1.default.rmdir(fileDir, { recursive: true });
419
+ yield fs_extra_1.default.ensureDir(fileDir);
420
+ const cloudService = yield getCloudServiceInstance(ctx);
421
+ let total = Infinity;
422
+ let currentTotal = 0;
423
+ const limit = 50;
424
+ const files = [];
425
+ let count = 1;
426
+ while (currentTotal < total) {
427
+ const solutionListResult = yield cloudService.lowcode.request('DescribeSolutionList', {
428
+ Limit: limit,
429
+ Offset: currentTotal,
430
+ KeyWords: '',
431
+ EnvId: envId,
432
+ TypeList: ['SELFBUILD', 'TPLEXPORT']
433
+ });
434
+ const solutionList = solutionListResult.SolutionInfoList;
435
+ const handledSolutionList = yield Promise.all(solutionList.map((item) => __awaiter(this, void 0, void 0, function* () {
436
+ const solution = yield cloudService.lowcode.request('DescribeSolution', {
437
+ EnvId: envId,
438
+ SolutionId: item.SolutionId
439
+ });
440
+ if (solution.SolutionAppInfos.length > 0) {
441
+ const appIds = solution.SolutionAppInfos.map((item) => item.AppId);
442
+ const apps = yield Promise.all(appIds.map((appId) => __awaiter(this, void 0, void 0, function* () {
443
+ var _a, _b, _c, _d, _e;
444
+ try {
445
+ let result = yield cloudService.lowcode.request('DescribeHistoryListByAppId', {
446
+ WeAppId: appId,
447
+ PageNum: 1,
448
+ PageSize: 1
449
+ });
450
+ result = yield cloudService.lowcode.request('DescribeAppHistoryPreSignUrl', {
451
+ HisIds: [(_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.Data) === null || _a === void 0 ? void 0 : _a.List) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.Id],
452
+ HttpMethod: 'get',
453
+ WeAppsId: appId
454
+ });
455
+ result = yield (0, toolbox_1.fetch)((_e = (_d = result === null || result === void 0 ? void 0 : result.Data) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.UploadUrl);
456
+ return { appId, content: result };
457
+ }
458
+ catch (e) {
459
+ return { appId, error: e.message };
460
+ }
461
+ })));
462
+ return {
463
+ name: item.Name,
464
+ solutionId: item.SolutionId,
465
+ version: item.Version,
466
+ apps
467
+ };
468
+ }
469
+ else {
470
+ return null;
471
+ }
472
+ })));
473
+ const filePath = path_1.default.resolve(fileDir, `templates_${count}.json`);
474
+ yield fs_extra_1.default.writeFile(filePath, JSON.stringify(handledSolutionList, null, 2), 'utf8');
475
+ files.push(filePath);
476
+ total = solutionListResult.TotalCount;
477
+ currentTotal += limit;
478
+ count += 1;
479
+ }
480
+ log.success(`同步官方模板应用内容已完成. 文件路径:`);
481
+ log.success(files.join('\n'));
482
+ });
483
+ }
484
+ };
485
+ __decorate([
486
+ (0, decorators_1.InjectParams)(),
487
+ __param(0, (0, decorators_1.CmdContext)()),
488
+ __param(1, (0, decorators_1.Log)()),
489
+ __param(2, (0, decorators_1.ArgsOptions)()),
490
+ __metadata("design:type", Function),
491
+ __metadata("design:paramtypes", [Object, decorators_1.Logger, Object]),
492
+ __metadata("design:returntype", Promise)
493
+ ], TemplateSync.prototype, "execute", null);
494
+ TemplateSync = __decorate([
495
+ (0, common_1.ICommand)({ supportPrivate: true })
496
+ ], TemplateSync);
497
+ exports.TemplateSync = TemplateSync;
395
498
  function getCloudServiceInstance(ctx) {
396
499
  return __awaiter(this, void 0, void 0, function* () {
397
500
  let credential;
package/lib/utils/dts.js CHANGED
@@ -34,7 +34,7 @@ ${dtsList
34
34
  /**
35
35
  * 数据模型:${item.title}
36
36
  */
37
- ${item.name}: DataModelMethods<${getModelInterfaceName(item.name)}>;`;
37
+ ${_toValidFieldName(item.name)}: DataModelMethods<${getModelInterfaceName(item.name)}>;`;
38
38
  })
39
39
  .join('\n')}
40
40
  }
@@ -130,6 +130,13 @@ declare global {
130
130
  }
131
131
  });
132
132
  }
133
+ function _toValidFieldName(name) {
134
+ let result = name.replace(/[^a-zA-Z0-9_$]/g, '_');
135
+ if (/^[0-9]/.test(result)) {
136
+ result = '_' + result;
137
+ }
138
+ return result;
139
+ }
133
140
  function getModelInterfaceName(name) {
134
141
  if (!name)
135
142
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.5.1-alpha.2",
3
+ "version": "2.5.1-alpha.4",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@ export interface ICommandOptions {
18
18
  desc: string;
19
19
  requiredEnvId?: boolean;
20
20
  withoutAuth?: boolean;
21
+ autoRunLogin?: boolean;
21
22
  }
22
23
  interface ICommandDecoratorOptions {
23
24
  supportPrivate: boolean | 'only';
@@ -67,6 +67,20 @@ export declare class LowCodeDeployApp extends Command {
67
67
  execute(ctx: ICommandContext, log: Logger, options: any): Promise<void>;
68
68
  }
69
69
  export declare class ModelTypeSync extends Command {
70
+ get options(): {
71
+ cmd: string;
72
+ childCmd: string;
73
+ options: {
74
+ flags: string;
75
+ desc: string;
76
+ }[];
77
+ desc: string;
78
+ requiredEnvId: boolean;
79
+ autoRunLogin: boolean;
80
+ };
81
+ execute(ctx: ICommandContext, log: Logger, options: any): Promise<void>;
82
+ }
83
+ export declare class TemplateSync extends Command {
70
84
  get options(): {
71
85
  cmd: string;
72
86
  childCmd: string;