@cloudbase/cli 2.1.2-alpha.1 → 2.1.4-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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules\\typescript\\lib"
3
+ }
package/bin/cloudbase.js CHANGED
File without changes
package/bin/tcb.js CHANGED
File without changes
@@ -70,8 +70,8 @@ let HostingDetail = class HostingDetail extends common_1.Command {
70
70
  const res = yield (0, hosting_1.getHostingInfo)({ envId });
71
71
  const website = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a[0];
72
72
  if (!website) {
73
- const link = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/tcb');
74
- throw new error_1.CloudBaseError(`您还没有开启静态网站服务,请先到云开发控制台开启静态网站服务!\n 👉 ${link}`);
73
+ yield (0, hosting_1.initHosting)({ envId });
74
+ return;
75
75
  }
76
76
  const link = (0, utils_1.genClickableLink)(`https://${website.cdnDomain}`);
77
77
  if (website.status !== 'offline') {
@@ -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
  };
@@ -23,7 +46,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
46
  Object.defineProperty(exports, "__esModule", { value: true });
24
47
  exports.LowCodeWatch = void 0;
25
48
  const common_1 = require("../common");
26
- const lowcode_cli_1 = require("@cloudbase/lowcode-cli");
27
49
  const decorators_1 = require("../../decorators");
28
50
  let LowCodeWatch = class LowCodeWatch extends common_1.Command {
29
51
  get options() {
@@ -46,10 +68,12 @@ let LowCodeWatch = class LowCodeWatch extends common_1.Command {
46
68
  }
47
69
  execute(ctx, options) {
48
70
  return __awaiter(this, void 0, void 0, function* () {
49
- yield (0, lowcode_cli_1.watchApp)({
50
- watchPort: 8288,
51
- wxDevtoolPath: options === null || options === void 0 ? void 0 : options.wxDevtoolPath
52
- });
71
+ Promise.resolve().then(() => __importStar(require('@cloudbase/lowcode-cli'))).then((res) => __awaiter(this, void 0, void 0, function* () {
72
+ yield res.watchApp({
73
+ watchPort: 8288,
74
+ wxDevtoolPath: options === null || options === void 0 ? void 0 : options.wxDevtoolPath,
75
+ });
76
+ }));
53
77
  });
54
78
  }
55
79
  };
@@ -49,10 +49,14 @@ const common_1 = require("../common");
49
49
  const decorators_1 = require("../../decorators");
50
50
  const utils_1 = require("../../utils");
51
51
  const error_1 = require("../../error");
52
- const lowcode_cli_1 = require("@cloudbase/lowcode-cli");
53
52
  const enquirer_1 = require("enquirer");
54
53
  const semver = __importStar(require("semver"));
54
+ const utils_2 = require("./utils");
55
55
  const cloudService = utils_1.CloudApiService.getInstance('lowcode');
56
+ let lowcodeCli;
57
+ if (process.argv.includes('lowcode')) {
58
+ (0, utils_2.getLowcodeCli)().then(_ => lowcodeCli = _);
59
+ }
56
60
  let LowCodeCreateComps = class LowCodeCreateComps extends common_1.Command {
57
61
  get options() {
58
62
  return {
@@ -94,7 +98,7 @@ let LowCodeCreateComps = class LowCodeCreateComps extends common_1.Command {
94
98
  throw new error_1.CloudBaseError(`云端不存在组件库 ${compsName},请到低码控制台新建该组件库!`);
95
99
  }
96
100
  }
97
- yield (0, lowcode_cli_1.bootstrap)(compsName, log);
101
+ yield lowcodeCli.bootstrap(compsName, log);
98
102
  });
99
103
  }
100
104
  };
@@ -129,7 +133,7 @@ let LowCodeBuildComps = class LowCodeBuildComps extends common_1.Command {
129
133
  return __awaiter(this, void 0, void 0, function* () {
130
134
  const config = ctx.config.lowcodeCustomComponents;
131
135
  if (config) {
132
- yield (0, lowcode_cli_1.graceBuildComps)(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log }));
136
+ yield lowcodeCli.graceBuildComps(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log }));
133
137
  return;
134
138
  }
135
139
  throw new error_1.CloudBaseError('请参考文档填写 cloudbaserc 配置: https://docs.cloudbase.net/lowcode/custom-components/config/config-comps');
@@ -175,7 +179,7 @@ let LowCodeDebugComps = class LowCodeDebugComps extends common_1.Command {
175
179
  return __awaiter(this, void 0, void 0, function* () {
176
180
  const config = ctx.config.lowcodeCustomComponents;
177
181
  if (config) {
178
- yield (0, lowcode_cli_1.graceDebugComps)(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), debugPort: (options === null || options === void 0 ? void 0 : options.debugPort) || 8388, logger: log, wxDevtoolPath: options === null || options === void 0 ? void 0 : options.wxDevtoolPath }));
182
+ yield lowcodeCli.graceDebugComps(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), debugPort: (options === null || options === void 0 ? void 0 : options.debugPort) || 8388, logger: log, wxDevtoolPath: options === null || options === void 0 ? void 0 : options.wxDevtoolPath }));
179
183
  return;
180
184
  }
181
185
  throw new error_1.CloudBaseError('请参考文档填写 cloudbaserc 配置: https://docs.cloudbase.net/lowcode/custom-components/config/config-comps');
@@ -219,7 +223,7 @@ let LowCodePublishComps = class LowCodePublishComps extends common_1.Command {
219
223
  return __awaiter(this, void 0, void 0, function* () {
220
224
  const config = ctx.config.lowcodeCustomComponents;
221
225
  if (config) {
222
- yield (0, lowcode_cli_1.gracePublishComps)(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log, isAdmin: Boolean(options.admin) }));
226
+ yield lowcodeCli.gracePublishComps(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log, isAdmin: Boolean(options.admin) }));
223
227
  log.success('组件库 - 已同步到云端,请到低码控制台发布该组件库!');
224
228
  return;
225
229
  }
@@ -287,7 +291,7 @@ let LowCodePublishVersionComps = class LowCodePublishVersionComps extends common
287
291
  if (!config) {
288
292
  log.error('组件库 - 请添加组件库配置到cloudbaserc.json 以使用该命令');
289
293
  }
290
- const res = yield (0, lowcode_cli_1.publishVersion)(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log, isAdmin: options.admin }), comment, tag);
294
+ const res = yield lowcodeCli.publishVersion(Object.assign(Object.assign({}, config), { context: config.context || process.cwd(), logger: log, isAdmin: options.admin }), comment, tag);
291
295
  if (res.data.code === 200) {
292
296
  log.success('组件库 - 已发布新版本!');
293
297
  return;
@@ -1,6 +1,38 @@
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
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
2
34
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promisifyProcess = void 0;
35
+ exports.getLowcodeCli = exports.promisifyProcess = void 0;
4
36
  const toolbox_1 = require("@cloudbase/toolbox");
5
37
  function promisifyProcess(p, pipe = false) {
6
38
  return new Promise((resolve, reject) => {
@@ -23,3 +55,17 @@ function promisifyProcess(p, pipe = false) {
23
55
  });
24
56
  }
25
57
  exports.promisifyProcess = promisifyProcess;
58
+ function getLowcodeCli() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const key = '@cloudbase/lowcode-cli';
61
+ const cache = new Map();
62
+ let result;
63
+ if (!cache.get(key)) {
64
+ const module = yield Promise.resolve().then(() => __importStar(require(key)));
65
+ cache.set(key, module);
66
+ }
67
+ result = cache.get(key);
68
+ return result;
69
+ });
70
+ }
71
+ exports.getLowcodeCli = getLowcodeCli;
package/lib/constant.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_CPU_MEM_SET = exports.CPU_MEM_OPTS = exports.ConcurrencyTaskStatus = exports.StatusMap = exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
3
+ exports.EnvType = exports.DEFAULT_CPU_MEM_SET = exports.CPU_MEM_OPTS = exports.ConcurrencyTaskStatus = exports.StatusMap = exports.ALL_COMMANDS = exports.STATUS_TEXT = exports.REQUEST_TIMEOUT = exports.DefaultCloudBaseConfig = exports.DefaultFunctionDeployConfig = exports.ConfigItems = void 0;
4
4
  class ConfigItems {
5
5
  }
6
6
  exports.ConfigItems = ConfigItems;
@@ -132,3 +132,10 @@ exports.DEFAULT_CPU_MEM_SET = [
132
132
  PolicyThreshold: 60
133
133
  },
134
134
  ];
135
+ var EnvType;
136
+ (function (EnvType) {
137
+ EnvType["BAAS"] = "baas";
138
+ EnvType["RUN"] = "run";
139
+ EnvType["HOTING"] = "hoting";
140
+ EnvType["WEDA"] = "weda";
141
+ })(EnvType = exports.EnvType || (exports.EnvType = {}));
package/lib/hosting.js CHANGED
@@ -12,10 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.walkLocalDir = exports.hostingDelete = exports.hostingDeploy = exports.destroyHosting = exports.hostingList = exports.enableHosting = exports.checkHostingStatus = exports.getHostingInfo = void 0;
15
+ exports.walkLocalDir = exports.hostingDelete = exports.hostingDeploy = exports.destroyHosting = exports.hostingList = exports.subscribeHosting = exports.getEnvInfoByEnvId = exports.enableHosting = exports.checkHostingStatus = exports.initHosting = exports.getHostingInfo = void 0;
16
16
  const path_1 = __importDefault(require("path"));
17
17
  const utils_1 = require("./utils");
18
18
  const error_1 = require("./error");
19
+ const inquirer_1 = __importDefault(require("inquirer"));
20
+ const constant_1 = require("./constant");
19
21
  const HostingStatusMap = {
20
22
  init: '初始化中',
21
23
  process: '处理中',
@@ -37,15 +39,45 @@ function getHostingInfo(options) {
37
39
  });
38
40
  }
39
41
  exports.getHostingInfo = getHostingInfo;
40
- function checkHostingStatus(envId) {
42
+ function initHosting(options) {
41
43
  return __awaiter(this, void 0, void 0, function* () {
42
- const hostings = yield getHostingInfo({ envId });
43
- const link = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/tcb');
44
- if (!hostings.data || !hostings.data.length) {
44
+ const { envId } = options;
45
+ const envInfo = yield getEnvInfoByEnvId({ envId });
46
+ if (envInfo.EnvType === constant_1.EnvType.BAAS) {
47
+ const { confirm } = yield inquirer_1.default.prompt({
48
+ type: 'confirm',
49
+ name: 'confirm',
50
+ message: '您还未开通静态托管,是否立即开通?'
51
+ });
52
+ if (confirm) {
53
+ const res = yield subscribeHosting({ envId });
54
+ if (!res.code) {
55
+ utils_1.logger.success('开通静态托管成功!资源正在初始化中,请稍候3~5分钟再试...');
56
+ return;
57
+ }
58
+ else {
59
+ throw new error_1.CloudBaseError(`开通静态托管失败\n request id: ${res.requestId}`);
60
+ }
61
+ }
62
+ else
63
+ return;
64
+ }
65
+ else {
66
+ const link = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/tcb');
45
67
  throw new error_1.CloudBaseError(`您还没有开启静态网站服务,请先到云开发控制台开启静态网站服务!\n👉 ${link}`, {
46
68
  code: 'INVALID_OPERATION'
47
69
  });
48
70
  }
71
+ });
72
+ }
73
+ exports.initHosting = initHosting;
74
+ function checkHostingStatus(envId) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const hostings = yield getHostingInfo({ envId });
77
+ if (!hostings.data || !hostings.data.length) {
78
+ yield initHosting({ envId });
79
+ return;
80
+ }
49
81
  const website = hostings.data[0];
50
82
  if (website.status !== 'online') {
51
83
  throw new error_1.CloudBaseError(`静态网站服务【${HostingStatusMap[website.status]}】,无法进行此操作!`, {
@@ -78,6 +110,31 @@ function enableHosting(options) {
78
110
  });
79
111
  }
80
112
  exports.enableHosting = enableHosting;
113
+ function getEnvInfoByEnvId(options) {
114
+ var _a;
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const { envId } = options;
117
+ const res = yield tcbService.request('DescribeEnvs', {
118
+ EnvId: envId
119
+ });
120
+ return (_a = res === null || res === void 0 ? void 0 : res.EnvList) === null || _a === void 0 ? void 0 : _a.filter(item => item.EnvId === envId)[0];
121
+ });
122
+ }
123
+ exports.getEnvInfoByEnvId = getEnvInfoByEnvId;
124
+ function subscribeHosting(options) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const { envId } = options;
127
+ const res = yield tcbService.request('DescribeStaticStore', {
128
+ EnvId: envId
129
+ });
130
+ const code = res.Result === 'succ' ? 0 : -1;
131
+ return {
132
+ code,
133
+ requestId: res.RequestId
134
+ };
135
+ });
136
+ }
137
+ exports.subscribeHosting = subscribeHosting;
81
138
  function hostingList(options) {
82
139
  return __awaiter(this, void 0, void 0, function* () {
83
140
  const { envId } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.1.2-alpha.1",
3
+ "version": "2.1.4-beta.0",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -31,8 +31,8 @@
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
33
  "@cloudbase/cloud-api": "^0.5.5",
34
- "@cloudbase/framework-core": "^1.6.1",
35
- "@cloudbase/lowcode-cli": "^0.16.0-alpha.0",
34
+ "@cloudbase/framework-core": "^1.9.5",
35
+ "@cloudbase/lowcode-cli": "^0.16.0",
36
36
  "@cloudbase/manager-node": "4.0.1",
37
37
  "@cloudbase/toolbox": "^0.7.3",
38
38
  "@sentry/node": "^5.10.2",
@@ -1,3 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import { ChildProcess } from 'child_process';
3
3
  export declare function promisifyProcess(p: ChildProcess, pipe?: boolean): Promise<unknown>;
4
+ export declare function getLowcodeCli(): Promise<typeof import('@cloudbase/lowcode-cli')>;
@@ -63,3 +63,9 @@ export declare const DEFAULT_CPU_MEM_SET: {
63
63
  PolicyType: 'mem' | 'cpu';
64
64
  PolicyThreshold: number;
65
65
  }[];
66
+ export declare enum EnvType {
67
+ BAAS = "baas",
68
+ RUN = "run",
69
+ HOTING = "hoting",
70
+ WEDA = "weda"
71
+ }
@@ -13,11 +13,17 @@ interface IHostingCloudOptions extends IBaseOptions {
13
13
  isDir: boolean;
14
14
  }
15
15
  export declare function getHostingInfo(options: IBaseOptions): Promise<any>;
16
+ export declare function initHosting(options: IBaseOptions): Promise<void>;
16
17
  export declare function checkHostingStatus(envId: string): Promise<any>;
17
18
  export declare function enableHosting(options: IBaseOptions): Promise<{
18
19
  code: number;
19
20
  requestId: any;
20
21
  }>;
22
+ export declare function getEnvInfoByEnvId(options: IBaseOptions): Promise<any>;
23
+ export declare function subscribeHosting(options: IBaseOptions): Promise<{
24
+ code: number;
25
+ requestId: any;
26
+ }>;
21
27
  export declare function hostingList(options: IBaseOptions): Promise<import("@cloudbase/manager-node/types/interfaces").IListFileInfo[]>;
22
28
  export declare function destroyHosting(options: IBaseOptions): Promise<{
23
29
  code: number;