@cloudbase/cli 2.5.1-alpha.1 → 2.5.1-alpha.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/lib/commands/lowcode/app.js +117 -2
- package/lib/utils/dts.js +8 -1
- package/package.json +1 -1
- package/types/commands/lowcode/app.d.ts +13 -0
|
@@ -58,7 +58,8 @@ 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
|
+
const lodash_1 = require("lodash");
|
|
62
63
|
const common_1 = require("../common");
|
|
63
64
|
const decorators_1 = require("../../decorators");
|
|
64
65
|
const utils_1 = require("./utils");
|
|
@@ -66,6 +67,8 @@ const utils_2 = require("../../utils");
|
|
|
66
67
|
const cloud_api_1 = require("@cloudbase/cloud-api");
|
|
67
68
|
const toolbox_1 = require("@cloudbase/toolbox");
|
|
68
69
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
70
|
+
const os_1 = __importDefault(require("os"));
|
|
71
|
+
const path_1 = __importDefault(require("path"));
|
|
69
72
|
const dts_1 = require("../../utils/dts");
|
|
70
73
|
let lowcodeCli;
|
|
71
74
|
if (process.argv.includes('lowcode')) {
|
|
@@ -344,12 +347,23 @@ let ModelTypeSync = class ModelTypeSync extends common_1.Command {
|
|
|
344
347
|
envId: ctx.envId
|
|
345
348
|
}, null, 2), 'utf8');
|
|
346
349
|
}
|
|
350
|
+
if (!(yield fs_extra_1.default.pathExists('tsconfig.json'))) {
|
|
351
|
+
yield fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify({
|
|
352
|
+
compilerOptions: {
|
|
353
|
+
allowJs: true
|
|
354
|
+
}
|
|
355
|
+
}, null, 2), 'utf8');
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
const config = yield fs_extra_1.default.readJson('tsconfig.json', 'utf8');
|
|
359
|
+
(0, lodash_1.set)(config, 'compilerOptions.allowJs', true);
|
|
360
|
+
yield fs_extra_1.default.writeFile('tsconfig.json', JSON.stringify(config, null, 2), 'utf8');
|
|
361
|
+
}
|
|
347
362
|
const cloudService = yield getCloudServiceInstance(ctx);
|
|
348
363
|
const datasourceList = yield cloudService.lowcode.request('DescribeDataSourceList', {
|
|
349
364
|
EnvId: ctx.envId,
|
|
350
365
|
PageIndex: 1,
|
|
351
366
|
PageSize: 1000,
|
|
352
|
-
DbInstanceType: 'FLEXDB',
|
|
353
367
|
QuerySystemModel: true,
|
|
354
368
|
QueryConnector: 0
|
|
355
369
|
});
|
|
@@ -379,6 +393,107 @@ ModelTypeSync = __decorate([
|
|
|
379
393
|
(0, common_1.ICommand)({ supportPrivate: true })
|
|
380
394
|
], ModelTypeSync);
|
|
381
395
|
exports.ModelTypeSync = ModelTypeSync;
|
|
396
|
+
let TemplateSync = class TemplateSync extends common_1.Command {
|
|
397
|
+
get options() {
|
|
398
|
+
return {
|
|
399
|
+
cmd: 'template',
|
|
400
|
+
childCmd: 'sync',
|
|
401
|
+
options: [
|
|
402
|
+
{
|
|
403
|
+
flags: '--envId <envId>',
|
|
404
|
+
desc: '环境 ID'
|
|
405
|
+
}
|
|
406
|
+
],
|
|
407
|
+
desc: '同步官方模板应用内容',
|
|
408
|
+
requiredEnvId: true
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
execute(ctx, log, options) {
|
|
412
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
413
|
+
log.info('同步中...');
|
|
414
|
+
const envId = 'lowcode-5g5llxbq5bc9299e';
|
|
415
|
+
const fileDir = path_1.default.resolve(os_1.default.tmpdir(), 'templates');
|
|
416
|
+
yield fs_extra_1.default.ensureDir(fileDir);
|
|
417
|
+
yield fs_extra_1.default.rmdir(fileDir, { recursive: true });
|
|
418
|
+
yield fs_extra_1.default.ensureDir(fileDir);
|
|
419
|
+
const cloudService = yield getCloudServiceInstance(ctx);
|
|
420
|
+
let total = Infinity;
|
|
421
|
+
let currentTotal = 0;
|
|
422
|
+
const limit = 50;
|
|
423
|
+
const files = [];
|
|
424
|
+
let count = 1;
|
|
425
|
+
while (currentTotal < total) {
|
|
426
|
+
const solutionListResult = yield cloudService.lowcode.request('DescribeSolutionList', {
|
|
427
|
+
Limit: limit,
|
|
428
|
+
Offset: currentTotal,
|
|
429
|
+
KeyWords: '',
|
|
430
|
+
EnvId: envId,
|
|
431
|
+
TypeList: ['SELFBUILD', 'TPLEXPORT']
|
|
432
|
+
});
|
|
433
|
+
const solutionList = solutionListResult.SolutionInfoList;
|
|
434
|
+
const handledSolutionList = yield Promise.all(solutionList.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
const solution = yield cloudService.lowcode.request('DescribeSolution', {
|
|
436
|
+
EnvId: envId,
|
|
437
|
+
SolutionId: item.SolutionId
|
|
438
|
+
});
|
|
439
|
+
if (solution.SolutionAppInfos.length > 0) {
|
|
440
|
+
const appIds = solution.SolutionAppInfos.map((item) => item.AppId);
|
|
441
|
+
const apps = yield Promise.all(appIds.map((appId) => __awaiter(this, void 0, void 0, function* () {
|
|
442
|
+
var _a, _b, _c, _d, _e;
|
|
443
|
+
try {
|
|
444
|
+
let result = yield cloudService.lowcode.request('DescribeHistoryListByAppId', {
|
|
445
|
+
WeAppId: appId,
|
|
446
|
+
PageNum: 1,
|
|
447
|
+
PageSize: 1
|
|
448
|
+
});
|
|
449
|
+
result = yield cloudService.lowcode.request('DescribeAppHistoryPreSignUrl', {
|
|
450
|
+
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],
|
|
451
|
+
HttpMethod: 'get',
|
|
452
|
+
WeAppsId: appId
|
|
453
|
+
});
|
|
454
|
+
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);
|
|
455
|
+
return { appId, content: result };
|
|
456
|
+
}
|
|
457
|
+
catch (e) {
|
|
458
|
+
return { appId, error: e.message };
|
|
459
|
+
}
|
|
460
|
+
})));
|
|
461
|
+
return {
|
|
462
|
+
name: item.Name,
|
|
463
|
+
solutionId: item.SolutionId,
|
|
464
|
+
version: item.Version,
|
|
465
|
+
apps
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
})));
|
|
472
|
+
const filePath = path_1.default.resolve(fileDir, `templates_${count}.json`);
|
|
473
|
+
yield fs_extra_1.default.writeFile(filePath, JSON.stringify(handledSolutionList, null, 2), 'utf8');
|
|
474
|
+
files.push(filePath);
|
|
475
|
+
total = solutionListResult.TotalCount;
|
|
476
|
+
currentTotal += limit;
|
|
477
|
+
count += 1;
|
|
478
|
+
}
|
|
479
|
+
log.success(`同步官方模板应用内容已完成. 文件路径:`);
|
|
480
|
+
log.success(files.join('\n'));
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
__decorate([
|
|
485
|
+
(0, decorators_1.InjectParams)(),
|
|
486
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
487
|
+
__param(1, (0, decorators_1.Log)()),
|
|
488
|
+
__param(2, (0, decorators_1.ArgsOptions)()),
|
|
489
|
+
__metadata("design:type", Function),
|
|
490
|
+
__metadata("design:paramtypes", [Object, decorators_1.Logger, Object]),
|
|
491
|
+
__metadata("design:returntype", Promise)
|
|
492
|
+
], TemplateSync.prototype, "execute", null);
|
|
493
|
+
TemplateSync = __decorate([
|
|
494
|
+
(0, common_1.ICommand)({ supportPrivate: true })
|
|
495
|
+
], TemplateSync);
|
|
496
|
+
exports.TemplateSync = TemplateSync;
|
|
382
497
|
function getCloudServiceInstance(ctx) {
|
|
383
498
|
return __awaiter(this, void 0, void 0, function* () {
|
|
384
499
|
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
|
@@ -79,3 +79,16 @@ export declare class ModelTypeSync extends Command {
|
|
|
79
79
|
};
|
|
80
80
|
execute(ctx: ICommandContext, log: Logger, options: any): Promise<void>;
|
|
81
81
|
}
|
|
82
|
+
export declare class TemplateSync extends Command {
|
|
83
|
+
get options(): {
|
|
84
|
+
cmd: string;
|
|
85
|
+
childCmd: string;
|
|
86
|
+
options: {
|
|
87
|
+
flags: string;
|
|
88
|
+
desc: string;
|
|
89
|
+
}[];
|
|
90
|
+
desc: string;
|
|
91
|
+
requiredEnvId: boolean;
|
|
92
|
+
};
|
|
93
|
+
execute(ctx: ICommandContext, log: Logger, options: any): Promise<void>;
|
|
94
|
+
}
|