@cloudbase/cli 2.7.6 → 2.7.7

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.
@@ -1,10 +1,33 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
2
18
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
19
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
20
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
21
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
22
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
23
  };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
8
31
  var __metadata = (this && this.__metadata) || function (k, v) {
9
32
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
33
  };
@@ -32,6 +55,7 @@ const toolbox_1 = require("@cloudbase/toolbox");
32
55
  const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
33
56
  const chalk_1 = __importDefault(require("chalk"));
34
57
  const cli_table3_1 = __importDefault(require("cli-table3"));
58
+ const execa_1 = __importDefault(require("execa"));
35
59
  const fs_extra_1 = __importDefault(require("fs-extra"));
36
60
  const inquirer_1 = __importDefault(require("inquirer"));
37
61
  const nodemon_1 = __importDefault(require("nodemon"));
@@ -786,12 +810,14 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
786
810
  },
787
811
  env: {
788
812
  FROM_NODEMON: 'true'
789
- }
813
+ },
814
+ ext: 'js,mjs,cjs,json,ts,yaml,yml'
790
815
  })
791
816
  .on('start', () => __awaiter(this, void 0, void 0, function* () {
792
817
  logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
793
818
  if (!nodemonInstance._firstStartDone) {
794
819
  nodemonInstance._firstStartDone = true;
820
+ this.checkAndRunTsc();
795
821
  this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
796
822
  }
797
823
  }))
@@ -816,14 +842,35 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
816
842
  }
817
843
  else {
818
844
  (0, functions_framework_1.runCLI)();
819
- if (!process.env.FROM_NODEMON && openDebugPanel) {
820
- this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
845
+ if (!process.env.FROM_NODEMON) {
846
+ this.checkAndRunTsc();
847
+ if (openDebugPanel) {
848
+ this.openDebugApp(type, port, envId, agentId, openDebugPanel !== 'false');
849
+ }
821
850
  }
822
851
  }
823
852
  });
824
853
  }
854
+ checkAndRunTsc() {
855
+ var _a;
856
+ return __awaiter(this, void 0, void 0, function* () {
857
+ const tsConfigPath = path_1.default.join(process.cwd(), 'tsconfig.json');
858
+ if (yield fs_extra_1.default.exists(tsConfigPath)) {
859
+ const child = (0, execa_1.default)('npx', ['tsc', '-w'], {
860
+ cwd: process.cwd(),
861
+ stdio: 'pipe'
862
+ });
863
+ (_a = child.stderr) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
864
+ console.log(data.toString());
865
+ });
866
+ child.on('exit', (code) => {
867
+ console.log(`子进程退出,退出码 ${code}`);
868
+ });
869
+ }
870
+ });
871
+ }
825
872
  openDebugApp(type, port, envId, agentId, isOpen = true) {
826
- setTimeout(() => {
873
+ return __awaiter(this, void 0, void 0, function* () {
827
874
  let url = `http://127.0.0.1:${port}/cloudrun-run-ui/index.html?type=${type}&envId=${envId}&port=${port}`;
828
875
  if (type === 'agent') {
829
876
  url += `&agentId=${agentId}`;
@@ -832,8 +879,32 @@ let CloudRunRunCommand = class CloudRunRunCommand extends common_1.Command {
832
879
  else {
833
880
  console.log(chalk_1.default.green(`点击 [${url}] 可以打开函数调试面板`));
834
881
  }
835
- isOpen && (0, open_1.default)(url, { wait: false });
836
- }, 3000);
882
+ if (isOpen) {
883
+ yield this.waitForPort(url);
884
+ (0, open_1.default)(url, { wait: false });
885
+ }
886
+ });
887
+ }
888
+ waitForPort(url, timeout = 10000) {
889
+ return __awaiter(this, void 0, void 0, function* () {
890
+ const startTime = Date.now();
891
+ const { default: fetch } = yield Promise.resolve().then(() => __importStar(require('node-fetch')));
892
+ while (Date.now() - startTime < timeout) {
893
+ try {
894
+ const response = yield fetch(url, {
895
+ timeout: 1000,
896
+ method: 'HEAD'
897
+ });
898
+ if (response.ok) {
899
+ return;
900
+ }
901
+ }
902
+ catch (e) {
903
+ }
904
+ yield new Promise((resolve) => setTimeout(resolve, 500));
905
+ }
906
+ throw new Error(`等待服务${url}就绪超时`);
907
+ });
837
908
  }
838
909
  };
839
910
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.7.6",
3
+ "version": "2.7.7",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -151,5 +151,7 @@ export declare class CloudRunRunCommand extends Command {
151
151
  desc: string;
152
152
  };
153
153
  execute(envId: string, logger: Logger, ctx: any, options: any): Promise<void>;
154
+ private checkAndRunTsc;
154
155
  private openDebugApp;
156
+ private waitForPort;
155
157
  }