@cloudbase/cli 2.7.0 → 2.7.2

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 (65) hide show
  1. package/.yarn/cache/@cloudbase-functions-framework-npm-1.16.0-41dc856d93-3bf3eadd4d.zip +0 -0
  2. package/.yarn/cache/@cloudbase-functions-typings-npm-1.2.1-f4e86def53-824b723926.zip +0 -0
  3. package/.yarn/cache/@cloudbase-manager-node-npm-4.3.2-91c22bb573-054b334bea.zip +0 -0
  4. package/.yarn/cache/@dotenvx-dotenvx-npm-1.45.1-117b6b2203-70e478d2f5.zip +0 -0
  5. package/.yarn/cache/@ecies-ciphers-npm-0.2.3-7acdacd689-fdf01fd5e6.zip +0 -0
  6. package/.yarn/cache/@noble-ciphers-npm-1.3.0-73a7db337f-19722c3547.zip +0 -0
  7. package/.yarn/cache/@noble-curves-npm-1.9.2-2584df26a7-bac582aefe.zip +0 -0
  8. package/.yarn/cache/@noble-hashes-npm-1.8.0-a397449e64-c94e98b941.zip +0 -0
  9. package/.yarn/cache/@types-koa-send-npm-4.1.6-803aa0a977-d46d207f1d.zip +0 -0
  10. package/.yarn/cache/@types-koa-static-npm-4.0.4-72ad58a98a-99087a9b6f.zip +0 -0
  11. package/.yarn/cache/anymatch-npm-1.3.2-a0b3155e35-b197f2adb8.zip +0 -0
  12. package/.yarn/cache/arr-diff-npm-2.0.0-448f410f30-b56e8d34e8.zip +0 -0
  13. package/.yarn/cache/array-unique-npm-0.2.1-f86f13725c-899deaf07a.zip +0 -0
  14. package/.yarn/cache/braces-npm-1.8.5-ce7bb29796-9ea4fb6af8.zip +0 -0
  15. package/.yarn/cache/chokidar-npm-1.7.0-a3b03416e2-96b2319b1d.zip +0 -0
  16. package/.yarn/cache/commander-npm-11.1.0-56e979613c-fd1a8557c6.zip +0 -0
  17. package/.yarn/cache/cpx-npm-1.5.0-ebb9af3acb-0a63ea121f.zip +0 -0
  18. package/.yarn/cache/eciesjs-npm-0.4.15-887ec6fb15-133a0ded69.zip +0 -0
  19. package/.yarn/cache/expand-brackets-npm-0.1.5-8e035b7cb7-71b2971027.zip +0 -0
  20. package/.yarn/cache/expand-range-npm-1.8.2-9c37166fb5-ca773ec068.zip +0 -0
  21. package/.yarn/cache/extglob-npm-0.3.2-77ca6e5250-c1c8d5365f.zip +0 -0
  22. package/.yarn/cache/fdir-npm-6.4.6-52922d4c25-fe9f301490.zip +0 -0
  23. package/.yarn/cache/filename-regex-npm-2.0.1-c999dfa72c-ac181f8184.zip +0 -0
  24. package/.yarn/cache/fill-range-npm-2.2.4-274c7401db-ee7cb386c9.zip +0 -0
  25. package/.yarn/cache/find-index-npm-0.1.1-d2f5fcf886-bf445157a4.zip +0 -0
  26. package/.yarn/cache/for-own-npm-0.1.5-cb55c5cc60-07eb0a2e98.zip +0 -0
  27. package/.yarn/cache/glob-base-npm-0.3.0-974af68137-d0e3054a7d.zip +0 -0
  28. package/.yarn/cache/glob-parent-npm-2.0.0-43401abb76-734fc461d9.zip +0 -0
  29. package/.yarn/cache/glob2base-npm-0.0.12-c0fe508825-277bbfee5b.zip +0 -0
  30. package/.yarn/cache/is-core-module-npm-2.16.1-a54837229e-6ec5b3c42d.zip +0 -0
  31. package/.yarn/cache/is-dotfile-npm-1.0.3-009416f290-5257760d99.zip +0 -0
  32. package/.yarn/cache/is-equal-shallow-npm-0.1.3-b7ae87b9cd-1a296b660b.zip +0 -0
  33. package/.yarn/cache/is-extglob-npm-1.0.0-6d00ab629f-5eea8517fe.zip +0 -0
  34. package/.yarn/cache/is-glob-npm-2.0.1-f316041d6e-089f5f9364.zip +0 -0
  35. package/.yarn/cache/is-number-npm-2.1.0-d1e978f60f-d80e041a43.zip +0 -0
  36. package/.yarn/cache/is-number-npm-4.0.0-27432edbd5-e71962a5ae.zip +0 -0
  37. package/.yarn/cache/is-posix-bracket-npm-0.1.1-b1ce5d8aba-8a6391b41e.zip +0 -0
  38. package/.yarn/cache/is-primitive-npm-2.0.0-f3606beda7-4d63fe952e.zip +0 -0
  39. package/.yarn/cache/math-random-npm-1.0.4-4cb7e85188-9edf31ea33.zip +0 -0
  40. package/.yarn/cache/micromatch-npm-2.3.11-dec7c96510-562681808a.zip +0 -0
  41. package/.yarn/cache/object-treeify-npm-1.1.33-2273de9233-3af7f88934.zip +0 -0
  42. package/.yarn/cache/object.omit-npm-2.0.1-f19cf0d87c-581de24e16.zip +0 -0
  43. package/.yarn/cache/parse-glob-npm-3.0.4-8cc6318690-447bc442d7.zip +0 -0
  44. package/.yarn/cache/preserve-npm-0.2.0-6217a135d1-dd31d4fd0e.zip +0 -0
  45. package/.yarn/cache/randomatic-npm-3.1.1-149177375b-1952baed71.zip +0 -0
  46. package/.yarn/cache/regex-cache-npm-0.4.4-ef2672a5a0-fdaf756fbd.zip +0 -0
  47. package/.yarn/cache/resolve-npm-1.22.10-d6fd9cdec7-ab7a32ff40.zip +0 -0
  48. package/.yarn/cache/resolve-patch-d29ff41c85-8aac1e4e46.zip +0 -0
  49. package/.yarn/cache/shell-quote-npm-1.8.3-b29f851134-550dd84e67.zip +0 -0
  50. package/.yarn/cache/subarg-npm-1.0.0-05f4a18d07-8359df72e9.zip +0 -0
  51. package/.yarn/cache/which-npm-4.0.0-dd31cd4928-f17e84c042.zip +0 -0
  52. package/.yarn/install-state.gz +0 -0
  53. package/lib/commands/cloudrun/base.js +246 -15
  54. package/lib/commands/cloudrun/cloudrun-run-ui/index.html +185 -0
  55. package/lib/commands/common.js +4 -1
  56. package/lib/commands/fun/base.js +0 -19
  57. package/lib/commands/utils.js +87 -1
  58. package/lib/help.js +1 -2
  59. package/package.json +6 -5
  60. package/types/commands/cloudrun/base.d.ts +15 -0
  61. package/types/commands/common.d.ts +1 -0
  62. package/types/commands/utils.d.ts +11 -0
  63. package/.yarn/cache/@cloudbase-functions-framework-npm-1.5.0-651c5fbeb7-ce80851a29.zip +0 -0
  64. package/.yarn/cache/@cloudbase-functions-typings-npm-1.0.0-a75d6d59dc-fd1dc5350d.zip +0 -0
  65. package/.yarn/cache/@cloudbase-manager-node-npm-4.3.0-3b5a1c2b90-570060cdc6.zip +0 -0
Binary file
@@ -24,17 +24,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.getCloudrunService = void 0;
27
+ exports.CloudRunRunCommand = exports.CloudRunDeployCommand = exports.CloudRunDeleteCommand = exports.CloudRunDownloadCommand = exports.CloudRunListCommand = exports.CloudRunInitCommand = exports.getCloudrunService = void 0;
28
+ const functions_framework_1 = require("@cloudbase/functions-framework");
28
29
  const iac_core_1 = require("@cloudbase/iac-core");
29
30
  const manager_node_1 = __importDefault(require("@cloudbase/manager-node"));
30
31
  const toolbox_1 = require("@cloudbase/toolbox");
31
32
  const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
32
33
  const chalk_1 = __importDefault(require("chalk"));
33
34
  const cli_table3_1 = __importDefault(require("cli-table3"));
35
+ const fs_extra_1 = __importDefault(require("fs-extra"));
34
36
  const inquirer_1 = __importDefault(require("inquirer"));
37
+ const nodemon_1 = __importDefault(require("nodemon"));
38
+ const open_1 = __importDefault(require("open"));
35
39
  const ora_1 = __importDefault(require("ora"));
36
40
  const path_1 = __importDefault(require("path"));
37
- const fs_extra_1 = __importDefault(require("fs-extra"));
38
41
  const decorators_1 = require("../../decorators");
39
42
  const utils_1 = require("../../utils");
40
43
  const common_1 = require("../common");
@@ -127,6 +130,10 @@ let CloudRunInitCommand = class CloudRunInitCommand extends common_1.Command {
127
130
  template,
128
131
  targetPath: targetDir
129
132
  });
133
+ yield (0, utils_2.upsertCloudbaserc)(path_1.default.resolve(targetDir, serviceName), {
134
+ envId,
135
+ cloudrun: { name: serviceName }
136
+ });
130
137
  spinner.succeed('项目初始化成功');
131
138
  console.log(chalk_1.default.green(`项目路径:${projectDir}`));
132
139
  }
@@ -273,6 +280,7 @@ let CloudRunDownloadCommand = class CloudRunDownloadCommand extends common_1.Com
273
280
  };
274
281
  }
275
282
  execute(ctx, envId, log, options) {
283
+ var _a;
276
284
  return __awaiter(this, void 0, void 0, function* () {
277
285
  let { serviceName, targetPath, force } = options;
278
286
  let targetDir = path_1.default.resolve(targetPath || process.cwd());
@@ -285,12 +293,18 @@ let CloudRunDownloadCommand = class CloudRunDownloadCommand extends common_1.Com
285
293
  if (!serviceName) {
286
294
  let defaultName = '';
287
295
  if (maybeInProject) {
288
- const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
289
- if (shortName) {
290
- defaultName = shortName;
296
+ const config = yield (0, utils_2.getCloudbaserc)(targetDir);
297
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
298
+ defaultName = config['cloudrun']['name'];
291
299
  }
292
300
  else {
293
- defaultName = path_1.default.basename(targetDir);
301
+ const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
302
+ if (shortName) {
303
+ defaultName = shortName;
304
+ }
305
+ else {
306
+ defaultName = path_1.default.basename(targetDir);
307
+ }
294
308
  }
295
309
  }
296
310
  serviceName = yield _inputServiceName(defaultName);
@@ -319,6 +333,10 @@ let CloudRunDownloadCommand = class CloudRunDownloadCommand extends common_1.Com
319
333
  serverName: serviceName,
320
334
  targetPath: targetDir
321
335
  });
336
+ yield (0, utils_2.upsertCloudbaserc)(targetDir, {
337
+ envId,
338
+ cloudrun: { name: serviceName }
339
+ });
322
340
  log.success(`云托管服务 ${serviceName} 代码已成功下载到: ${targetDir}`);
323
341
  }
324
342
  catch (e) {
@@ -373,6 +391,7 @@ let CloudRunDeleteCommand = class CloudRunDeleteCommand extends common_1.Command
373
391
  };
374
392
  }
375
393
  execute(ctx, envId, log, options) {
394
+ var _a;
376
395
  return __awaiter(this, void 0, void 0, function* () {
377
396
  let { serviceName, force } = options;
378
397
  if (!envId) {
@@ -381,7 +400,12 @@ let CloudRunDeleteCommand = class CloudRunDeleteCommand extends common_1.Command
381
400
  log.info(`当前环境:${envId}`);
382
401
  const cloudrunService = yield getCloudrunService(envId);
383
402
  if (!serviceName) {
384
- serviceName = yield _inputServiceName();
403
+ const config = yield (0, utils_2.getCloudbaserc)(process.cwd());
404
+ let detaultName = '';
405
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
406
+ detaultName = config['cloudrun']['name'];
407
+ }
408
+ serviceName = yield _inputServiceName(detaultName);
385
409
  }
386
410
  if (!force) {
387
411
  const answers = yield inquirer_1.default.prompt([
@@ -462,7 +486,7 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
462
486
  };
463
487
  }
464
488
  execute(ctx, envId, log, options) {
465
- var _a;
489
+ var _a, _b;
466
490
  return __awaiter(this, void 0, void 0, function* () {
467
491
  let { serviceName, source, force, port } = options;
468
492
  const targetDir = path_1.default.resolve(source || process.cwd());
@@ -470,18 +494,23 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
470
494
  const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(targetDir));
471
495
  if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
472
496
  envId = envConfig.envId;
473
- log.info(`当前环境 Id:${envId}`);
474
497
  }
475
498
  else {
476
499
  envId = yield _selectEnv();
477
500
  }
478
501
  }
479
- else {
480
- log.info(`当前环境 Id:${envId}`);
481
- }
502
+ log.info(`当前环境 Id:${envId}`);
482
503
  if (!serviceName) {
483
- const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
484
- serviceName = yield _inputServiceName(shortName);
504
+ let defaultName = '';
505
+ const config = yield (0, utils_2.getCloudbaserc)(targetDir);
506
+ if ((_a = config === null || config === void 0 ? void 0 : config['cloudrun']) === null || _a === void 0 ? void 0 : _a['name']) {
507
+ defaultName = config['cloudrun']['name'];
508
+ }
509
+ else {
510
+ const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
511
+ defaultName = shortName;
512
+ }
513
+ serviceName = yield _inputServiceName(defaultName);
485
514
  }
486
515
  if (!force) {
487
516
  const answers = yield inquirer_1.default.prompt([
@@ -507,7 +536,7 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
507
536
  let serverType;
508
537
  try {
509
538
  const details = yield cloudrunService.detail({ serverName: serviceName });
510
- serverType = (_a = details.BaseInfo) === null || _a === void 0 ? void 0 : _a.ServerType;
539
+ serverType = (_b = details.BaseInfo) === null || _b === void 0 ? void 0 : _b.ServerType;
511
540
  }
512
541
  catch (e) {
513
542
  const dockerfilePath = path_1.default.join(targetDir, 'Dockerfile');
@@ -544,6 +573,10 @@ let CloudRunDeployCommand = class CloudRunDeployCommand extends common_1.Command
544
573
  }, function (message) {
545
574
  (0, utils_2.trackCallback)(message, log);
546
575
  });
576
+ yield (0, utils_2.upsertCloudbaserc)(targetDir, {
577
+ envId,
578
+ cloudrun: { name: serviceName }
579
+ });
547
580
  const { envId: _envId, name, resourceType: _resourceType } = res === null || res === void 0 ? void 0 : res.data;
548
581
  (0, utils_2.trackCallback)({
549
582
  details: `请打开链接查看部署状态: https://tcb.cloud.tencent.com/dev?envId=${_envId}#/platform-run/service/detail?serverName=${name}&tabId=deploy&envId=${_envId}`
@@ -615,6 +648,204 @@ CloudRunDeployCommand = __decorate([
615
648
  (0, common_1.ICommand)()
616
649
  ], CloudRunDeployCommand);
617
650
  exports.CloudRunDeployCommand = CloudRunDeployCommand;
651
+ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
652
+ get options() {
653
+ return {
654
+ cmd: 'cloudrun',
655
+ childCmd: 'run',
656
+ allowUnknownOption: true,
657
+ options: [
658
+ {
659
+ flags: '--runMode <runMode>',
660
+ desc: `运行模式,可选值: normal(普通函数) | agent(函数式 Agent),默认值: normal`
661
+ },
662
+ {
663
+ flags: '--agentId <agentId>',
664
+ desc: `在 agent 模式下需要提供 Agent ID 进行调试`
665
+ },
666
+ {
667
+ flags: '-e, --envId <envId>',
668
+ desc: '环境 ID'
669
+ },
670
+ {
671
+ flags: '--port <port>',
672
+ desc: `监听的端口,默认为 3000
673
+ `
674
+ },
675
+ {
676
+ flags: '-w, --watch',
677
+ desc: `是否启用热重启模式,如启用,将会在文件变更时自动重启服务,默认为 false
678
+ `
679
+ },
680
+ {
681
+ flags: '--dry-run',
682
+ desc: `是否不启动服务,只验证代码可以正常加载,默认为 false
683
+ `
684
+ },
685
+ {
686
+ flags: '--logDirname <logDirname>',
687
+ desc: `日志文件目录,默认为 ./logs
688
+ `
689
+ },
690
+ {
691
+ flags: '--functionsConfigFile <functionsConfigFile>',
692
+ desc: `多函数定义配置文件,默认为 ./cloudbase-functions.json。
693
+ 环境变量: FUNCTIONS_CONFIG_FILE
694
+ `
695
+ },
696
+ {
697
+ flags: '--loadAllFunctions',
698
+ desc: `是否加载 "functionsRoot" 目录中的所有函数。默认为 false
699
+ `
700
+ },
701
+ {
702
+ flags: '--extendedContext <extendedContext>',
703
+ desc: `用于解析 context.extendedContext 的值。""表示该功能已关闭。默认值为 null
704
+ 示例:--extendedContext '{"a":1,"b":2}'
705
+ 环境变量:EXTENDED_CONTEXT
706
+ `
707
+ }
708
+ ],
709
+ requiredEnvId: false,
710
+ desc: '本地运行函数型云托管服务(不支持容器型云托管服务)'
711
+ };
712
+ }
713
+ execute(envId, logger, ctx, options) {
714
+ return __awaiter(this, void 0, void 0, function* () {
715
+ debugger;
716
+ let { runMode = 'normal', agentId } = options;
717
+ const type = runMode;
718
+ console.log(chalk_1.default.green(`当前运行模式: ${type}`));
719
+ if (!process.argv.some((arg) => arg.includes('--dotEnvFilePath='))) {
720
+ process.argv.push('--dotEnvFilePath=.env.local');
721
+ }
722
+ const args = process.argv.slice(2);
723
+ const watchFlag = ['--watch', '-w'];
724
+ const defaultIgnoreFiles = ['logs/*.*'];
725
+ if (!envId) {
726
+ const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(process.cwd()));
727
+ if (envConfig === null || envConfig === void 0 ? void 0 : envConfig.envId) {
728
+ envId = envConfig.envId;
729
+ }
730
+ else {
731
+ envId = yield _selectEnv();
732
+ }
733
+ }
734
+ logger.info(`当前环境 Id:${envId}`);
735
+ if (type === 'agent') {
736
+ if (!agentId) {
737
+ const answers = yield inquirer_1.default.prompt([
738
+ {
739
+ type: 'input',
740
+ name: 'agentId',
741
+ message: `请输入 Agent ID:`,
742
+ validate: (val) => {
743
+ return val.trim() ? true : 'Agent ID 不能为空';
744
+ }
745
+ }
746
+ ]);
747
+ agentId = answers.agentId;
748
+ }
749
+ logger.info(`当前 Agent ID: ${agentId}`);
750
+ }
751
+ const credential = yield (0, utils_2.getCredential)(ctx, options);
752
+ process.env.EXTENDED_CONTEXT = JSON.stringify({
753
+ tmpSecret: {
754
+ secretId: credential.secretId,
755
+ secretKey: credential.secretKey,
756
+ token: credential.token
757
+ },
758
+ source: 'local_dev',
759
+ envId,
760
+ accessToken: `Bearer ${yield (0, utils_2.fetchAccessToken)({
761
+ envId,
762
+ secretId: credential.secretId,
763
+ secretKey: credential.secretKey,
764
+ token: credential.token
765
+ })}`
766
+ });
767
+ process.env.STATIC_SERVE_ROOT = __dirname;
768
+ process.env.ENABLE_CORS = 'true';
769
+ process.env.ALLOWED_ORIGINS = '*';
770
+ const port = options.port || process.env.PORT || 3000;
771
+ if (watchFlag.some((flag) => args.includes(flag))) {
772
+ const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
773
+ const nodemonInstance = (0, nodemon_1.default)({
774
+ script: '',
775
+ exec: `${process.argv[1]} ${cmd} --envId=${envId} --runMode=${type} --agentId=${agentId}`,
776
+ watchOptions: {
777
+ usePolling: true,
778
+ ignorePermissionErrors: true,
779
+ ignored: defaultIgnoreFiles.join(','),
780
+ persistent: true,
781
+ interval: 500
782
+ },
783
+ env: {
784
+ FROM_NODEMON: 'true'
785
+ }
786
+ })
787
+ .on('start', () => __awaiter(this, void 0, void 0, function* () {
788
+ logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
789
+ if (!nodemonInstance._firstStartDone) {
790
+ nodemonInstance._firstStartDone = true;
791
+ this.openDebugApp(type, port, envId, agentId);
792
+ }
793
+ }))
794
+ .on('quit', (e) => {
795
+ logger.info(`Nodemon quit with code ${e}.`);
796
+ process.exit(0);
797
+ })
798
+ .on('restart', (e) => {
799
+ var _a, _b;
800
+ logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
801
+ })
802
+ .on('log', (e) => {
803
+ logger.info(`[nodemon ${e.type}] ${e.message}`);
804
+ })
805
+ .on('crash', () => {
806
+ logger.error(`Server crashed.`);
807
+ process.exit(1);
808
+ })
809
+ .on('exit', (e) => {
810
+ logger.info(`Server exited with code ${e}.`);
811
+ });
812
+ }
813
+ else {
814
+ (0, functions_framework_1.runCLI)();
815
+ if (!process.env.FROM_NODEMON) {
816
+ this.openDebugApp(type, port, envId, agentId);
817
+ }
818
+ }
819
+ });
820
+ }
821
+ openDebugApp(type, port, envId, agentId) {
822
+ setTimeout(() => {
823
+ let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
824
+ if (type === 'agent') {
825
+ url += `&agentId=${agentId}`;
826
+ console.log(chalk_1.default.green(`点击 [${url}] 可以打开 Agent 调试应用`));
827
+ }
828
+ else {
829
+ console.log(chalk_1.default.green(`点击 [${url}] 可以打开函数调试面板`));
830
+ }
831
+ (0, open_1.default)(url, { wait: false });
832
+ }, 3000);
833
+ }
834
+ };
835
+ __decorate([
836
+ (0, decorators_1.InjectParams)(),
837
+ __param(0, (0, decorators_1.EnvId)()),
838
+ __param(1, (0, decorators_1.Log)()),
839
+ __param(2, (0, decorators_1.CmdContext)()),
840
+ __param(3, (0, decorators_1.ArgsOptions)()),
841
+ __metadata("design:type", Function),
842
+ __metadata("design:paramtypes", [String, decorators_1.Logger, Object, Object]),
843
+ __metadata("design:returntype", Promise)
844
+ ], CloudRunRunCommand.prototype, "execute", null);
845
+ CloudRunRunCommand = __decorate([
846
+ (0, common_1.ICommand)()
847
+ ], CloudRunRunCommand);
848
+ exports.CloudRunRunCommand = CloudRunRunCommand;
618
849
  function _selectEnv() {
619
850
  return __awaiter(this, void 0, void 0, function* () {
620
851
  return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
@@ -0,0 +1,185 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Cloudrun Debug Panel</title>
8
+ <script src="https://weda.cloud.tencent.com/third-party/axios.min.js"></script>
9
+ </head>
10
+
11
+ <body style="height: 100vh;">
12
+ <iframe srcdoc="<!DOCTYPE html>
13
+ <head>
14
+ <meta charset=&quot;UTF-8&quot;>
15
+ <meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;>
16
+ <title>Http Client</title>
17
+ </head>
18
+ <body>
19
+ <div id=&quot;app&quot;></div>
20
+ <script>
21
+ window.addEventListener('message', (event) => {
22
+ if (event.data.type === 'loadScript') {
23
+ const script = document.createElement('script');
24
+ script.src = event.data.url;
25
+ document.body.appendChild(script);
26
+ }
27
+ });
28
+ </script>
29
+ </body>
30
+ </html>" style="width: 100%; height: 100%; border: none;"></iframe>
31
+
32
+ <script>
33
+ // 获取当前页面的 URL 参数
34
+ const urlParams = new URLSearchParams(window.location.search);
35
+ const type = urlParams.get('type'); // 获取 type 参数
36
+ const agentId = urlParams.get('agentId'); // 获取 agentId 参数
37
+ const envId = urlParams.get('envId'); // 获取 envId 参数
38
+ const port = urlParams.get('port'); // 获取 port 参数
39
+
40
+ // 监听来自VSCode扩展的消息
41
+ window.addEventListener('message', (event) => {
42
+ const message = event.data;
43
+
44
+ if (message.type === 'request') {
45
+ handleRequest(message, iframe.contentWindow);
46
+ }
47
+
48
+ // 处理ready类型的消息
49
+ if (message.type === 'ready') {
50
+ iframe.contentWindow.postMessage({
51
+ success: true,
52
+ id: message.id,
53
+ data: {
54
+ url: `http://127.0.0.1:${port}${type === 'agent' ? `/v1/aibot/bots/${agentId}/send-message` : ''}`,
55
+ resourceType: 'FunctionV2',
56
+ body: type === "agent" ? { botId: agentId, msg: 'hi', searchEnable: false, files: [] } : {},
57
+ defaultType: type === 'agent' ? 'AGENT' : 'HTTP',
58
+ agentConfig: {
59
+ uin: '',
60
+ envId,
61
+ ibotId: agentId,
62
+ },
63
+ }
64
+ });
65
+ }
66
+ });
67
+
68
+ const iframe = document.querySelector('iframe');
69
+ iframe.addEventListener('load', () => {
70
+ try {
71
+ const iframeWindow = iframe.contentWindow;
72
+ window.setState = (state) => { }
73
+ iframeWindow.acquireVsCodeApi = () => window
74
+ iframeWindow.postMessage({
75
+ type: 'loadScript',
76
+ url: 'https://weda.cloud.tencent.com/code_studio_webview/app.js'
77
+ }, '*');
78
+ } catch (error) {
79
+ console.error('挂载vscodeRef失败:', error);
80
+ }
81
+ });
82
+
83
+ // 在head中添加axios和URLParse的CDN引用
84
+ const HTTP_METHODS = {
85
+ GET: 'get',
86
+ POST: 'post',
87
+ PUT: 'put',
88
+ PATCH: 'patch',
89
+ DELETE: 'delete',
90
+ HEAD: 'head',
91
+ OPTIONS: 'options'
92
+ };
93
+
94
+ function getRequestConfig(state) {
95
+ const url = new URL(state.url);
96
+
97
+ if (!url.protocol) {
98
+ url.protocol = 'http:';
99
+ }
100
+
101
+ const headers = {};
102
+ state.request.headers.forEach(({ key, value, checked }) => {
103
+ if (checked) {
104
+ headers[key] = value;
105
+ }
106
+ });
107
+
108
+ const config = {
109
+ url: url.href,
110
+ method: state.method,
111
+ headers,
112
+ params: JSON.parse(JSON.stringify(state.request.params)),
113
+ validateStatus: () => true,
114
+ paramsSerializer: function (params) {
115
+ const param = {};
116
+ params.forEach((i) => {
117
+ if (!i.checked) {
118
+ return;
119
+ }
120
+ param[i.key] = i.value;
121
+ });
122
+ return new URLSearchParams(param).toString();
123
+ }
124
+ };
125
+
126
+ if (![HTTP_METHODS.GET, HTTP_METHODS.DELETE, HTTP_METHODS.OPTIONS].includes(state.method)) {
127
+ const type = state.request.body.type;
128
+ let body = state.request.body[type];
129
+ let data;
130
+
131
+ if (type === 'X_WWW_FORM_URLENCODED') {
132
+ data = body
133
+ .filter(i => i.checked)
134
+ .map(i => `${encodeURIComponent(i.key)}=${encodeURIComponent(i.value)}`)
135
+ .join('&');
136
+ }
137
+
138
+ if (type === 'RAW') {
139
+ try {
140
+ data = JSON.parse(body.value);
141
+ } catch (e) {
142
+ throw new Error('JSON 格式错误');
143
+ }
144
+ }
145
+
146
+ if (data) {
147
+ config.data = data;
148
+ }
149
+ }
150
+
151
+ return config;
152
+ }
153
+
154
+ async function handleRequest({ id, payload }, panel) {
155
+ let message;
156
+
157
+ try {
158
+ const config = getRequestConfig(payload);
159
+ const { data, status, statusText, headers } = await axios(config);
160
+
161
+ message = {
162
+ success: true,
163
+ id,
164
+ data: {
165
+ data: typeof data === 'object' ? JSON.stringify(data) : data,
166
+ status,
167
+ statusText,
168
+ headers,
169
+ },
170
+ };
171
+ } catch (e) {
172
+ message = {
173
+ success: false,
174
+ id,
175
+ error: { message: e.message },
176
+ };
177
+ }
178
+
179
+ panel.postMessage(message);
180
+ }
181
+
182
+ </script>
183
+ </body>
184
+
185
+ </html>
@@ -113,7 +113,10 @@ class Command extends events_1.EventEmitter {
113
113
  }
114
114
  }
115
115
  createProgram(instance, deprecate, newCmd) {
116
- const { cmd, childCmd, desc, options, requiredEnvId = true, withoutAuth = false, autoRunLogin = false } = this.options;
116
+ const { cmd, childCmd, desc, options, requiredEnvId = true, withoutAuth = false, autoRunLogin = false, allowUnknownOption = false } = this.options;
117
+ if (allowUnknownOption) {
118
+ instance.allowUnknownOption();
119
+ }
117
120
  instance.storeOptionsAsProperties(false);
118
121
  options.forEach((option) => {
119
122
  const { hideHelp } = option;
@@ -153,25 +153,6 @@ let FunDeployCommand = class FunDeployCommand extends common_1.Command {
153
153
  return;
154
154
  }
155
155
  }
156
- const loadResult = yield (0, functions_framework_1.loadFunctions)({
157
- target,
158
- sourceLocation: source,
159
- multiFunctionsConfig
160
- });
161
- if (Array.isArray(loadResult)) {
162
- for (const loadItem of loadResult) {
163
- if (!(loadItem === null || loadItem === void 0 ? void 0 : loadItem.userFunction)) {
164
- log.error(`加载函数 ${loadItem === null || loadItem === void 0 ? void 0 : loadItem.name} 失败: "${loadItem === null || loadItem === void 0 ? void 0 : loadItem.reason}"`);
165
- return;
166
- }
167
- }
168
- }
169
- else {
170
- if (!(loadResult === null || loadResult === void 0 ? void 0 : loadResult.userFunction)) {
171
- log.error(`验证加载云函数失败: ${loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason}`);
172
- return;
173
- }
174
- }
175
156
  if (!envId) {
176
157
  envId = yield _selectEnv();
177
158
  }
@@ -8,15 +8,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
24
  };
14
25
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getCredential = exports.trackCallback = exports.isDirectoryEmptyOrNotExists = exports.getPackageJsonName = exports.selectEnv = void 0;
26
+ exports.getCloudbaserc = exports.upsertCloudbaserc = exports.fetchAccessToken = exports.getCredential = exports.trackCallback = exports.isDirectoryEmptyOrNotExists = exports.getPackageJsonName = exports.selectEnv = void 0;
16
27
  const fs_1 = require("@cloudbase/iac-core/lib/src/fs");
28
+ const signature_nodejs_1 = require("@cloudbase/signature-nodejs");
17
29
  const fs_extra_1 = require("fs-extra");
18
30
  const inquirer_1 = __importDefault(require("inquirer"));
19
31
  const lodash_1 = require("lodash");
32
+ const node_fetch_1 = __importDefault(require("node-fetch"));
33
+ const path_1 = __importDefault(require("path"));
20
34
  const env_1 = require("../env");
21
35
  const utils_1 = require("../utils");
22
36
  const constants_1 = require("./constants");
@@ -100,3 +114,75 @@ function getCredential(ctx, options) {
100
114
  });
101
115
  }
102
116
  exports.getCredential = getCredential;
117
+ function fetchAccessToken(params) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const { envId, secretId, secretKey, token } = params;
120
+ const domain = `${envId}.api.tcloudbasegateway.com`;
121
+ const url = `https://${domain}/auth/v1/token/clientCredential`;
122
+ const method = 'POST';
123
+ const body = {
124
+ grant_type: 'client_credentials'
125
+ };
126
+ const now = Date.now();
127
+ const requiredHeaders = {
128
+ Host: domain,
129
+ 'Content-Type': 'application/json'
130
+ };
131
+ const { authorization, timestamp } = (0, signature_nodejs_1.sign)({
132
+ secretId,
133
+ secretKey,
134
+ method,
135
+ url,
136
+ params: body,
137
+ headers: requiredHeaders,
138
+ timestamp: Math.floor(now / 1000) - 1,
139
+ withSignedParams: false,
140
+ isCloudApi: true
141
+ });
142
+ const tokenResponse = yield (0, node_fetch_1.default)(url, {
143
+ method,
144
+ headers: Object.assign(Object.assign({}, requiredHeaders), { Authorization: `${authorization}, Timestamp=${timestamp}, Token=${token}` }),
145
+ body: JSON.stringify(body)
146
+ });
147
+ const res = yield tokenResponse.json();
148
+ return res === null || res === void 0 ? void 0 : res.access_token;
149
+ });
150
+ }
151
+ exports.fetchAccessToken = fetchAccessToken;
152
+ function upsertCloudbaserc(projectPath, inputData) {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ const { envId } = inputData, rest = __rest(inputData, ["envId"]);
155
+ const configPath = path_1.default.resolve(projectPath, 'cloudbaserc.json');
156
+ const defaultConfig = {
157
+ version: '2.0',
158
+ envId: envId || '{{envId}}',
159
+ $schema: 'https://framework-1258016615.tcloudbaseapp.com/schema/latest.json'
160
+ };
161
+ try {
162
+ const fileExists = yield (0, fs_extra_1.pathExists)(configPath);
163
+ if (!fileExists) {
164
+ const initialConfig = Object.assign(Object.assign({}, defaultConfig), rest);
165
+ yield (0, fs_extra_1.writeJson)(configPath, initialConfig, { spaces: 2 });
166
+ return;
167
+ }
168
+ const existingConfig = yield (0, fs_extra_1.readJson)(configPath);
169
+ const mergedConfig = (0, lodash_1.merge)(existingConfig, inputData);
170
+ yield (0, fs_extra_1.writeJson)(configPath, mergedConfig, { spaces: 2 });
171
+ }
172
+ catch (error) {
173
+ throw new Error(`更新 cloudbaserc.json 失败: ${error instanceof Error ? error.message : String(error)}`);
174
+ }
175
+ });
176
+ }
177
+ exports.upsertCloudbaserc = upsertCloudbaserc;
178
+ function getCloudbaserc(projectPath) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ try {
181
+ return yield (0, utils_1.getCloudBaseConfig)(path_1.default.resolve(projectPath, 'cloudbaserc.json'));
182
+ }
183
+ catch (e) {
184
+ return {};
185
+ }
186
+ });
187
+ }
188
+ exports.getCloudbaserc = getCloudbaserc;
package/lib/help.js CHANGED
@@ -21,8 +21,7 @@ const outputHelpInfo = () => {
21
21
  service [cmd] HTTP 访问服务管理操作
22
22
  run:deprecated [cmd] 云托管环境管理操作 (BAAS 或 RUN 类型环境)
23
23
  run [cmd] 云托管环境管理操作 (TCBR 类型环境)
24
- cloudrun [cmd] 云托管服务管理操作(新版云开发平台)
25
- cloudrunfunction [cmd] 云函数 2.0 服务管理操作`;
24
+ cloudrun [cmd] 云托管服务管理操作(新版云开发平台)`;
26
25
  const options = `
27
26
  选项
28
27
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "build": "rimraf lib types && tsc --resolveJsonModule",
7
+ "build": "rimraf lib types && tsc --resolveJsonModule && cpx \"src/**/*.html\" lib",
8
8
  "watch": "rimraf lib types && tsc -w",
9
- "dev": "rimraf lib types && tsc -w",
9
+ "dev": "rimraf lib types && cpx \"src/**/*.html\" lib && tsc -w",
10
10
  "eslint": "eslint \"./**/*.ts\"",
11
11
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --forceExit --detectOpenHandles --coverage --verbose --testTimeout=10000",
12
12
  "tsc": "tsc",
@@ -33,10 +33,10 @@
33
33
  "dependencies": {
34
34
  "@cloudbase/cloud-api": "^0.5.5",
35
35
  "@cloudbase/framework-core": "^1.9.7",
36
- "@cloudbase/functions-framework": "^1.5.0",
36
+ "@cloudbase/functions-framework": "1.16.0",
37
37
  "@cloudbase/iac-core": "0.0.3-alpha.10",
38
38
  "@cloudbase/lowcode-cli": "^0.22.2",
39
- "@cloudbase/manager-node": "4.3.0",
39
+ "@cloudbase/manager-node": "4.3.2",
40
40
  "@cloudbase/toolbox": "^0.7.5",
41
41
  "address": "^1.1.2",
42
42
  "camelcase-keys": "^7.0.2",
@@ -84,6 +84,7 @@
84
84
  "@types/webpack-dev-server": "^3.11.1",
85
85
  "@typescript-eslint/eslint-plugin": "^4.8.1",
86
86
  "@typescript-eslint/parser": "^4.8.1",
87
+ "cpx": "^1.5.0",
87
88
  "eslint": "^7.14.0",
88
89
  "eslint-config-alloy": "^3.8.2",
89
90
  "husky": "^3.0.9",
@@ -138,3 +138,18 @@ export declare class CloudRunDeployCommand extends Command {
138
138
  port?: number;
139
139
  }): Promise<void>;
140
140
  }
141
+ export declare class CloudRunRunCommand extends Command {
142
+ get options(): {
143
+ cmd: string;
144
+ childCmd: string;
145
+ allowUnknownOption: boolean;
146
+ options: {
147
+ flags: string;
148
+ desc: string;
149
+ }[];
150
+ requiredEnvId: boolean;
151
+ desc: string;
152
+ };
153
+ execute(envId: string, logger: Logger, ctx: any, options: any): Promise<void>;
154
+ private openDebugApp;
155
+ }
@@ -9,6 +9,7 @@ interface ICommandOption {
9
9
  export interface ICommandOptions {
10
10
  deprecateCmd?: string;
11
11
  cmd: string;
12
+ allowUnknownOption?: boolean;
12
13
  childCmd?: string | {
13
14
  cmd: string;
14
15
  desc: string;
@@ -9,3 +9,14 @@ export declare function getPackageJsonName(pkgPath: string): Promise<{
9
9
  export declare function isDirectoryEmptyOrNotExists(dirPath: string): Promise<boolean>;
10
10
  export declare function trackCallback(message: any, log: Logger): void;
11
11
  export declare function getCredential(ctx: any, options: any): Promise<any>;
12
+ export declare function fetchAccessToken(params: {
13
+ envId: string;
14
+ secretId: string;
15
+ secretKey: string;
16
+ token?: string;
17
+ }): Promise<any>;
18
+ export declare function upsertCloudbaserc(projectPath: string, inputData: {
19
+ envId?: string;
20
+ [key: string]: any;
21
+ }): Promise<void>;
22
+ export declare function getCloudbaserc(projectPath: string): Promise<{}>;