@cloudbase/cli 2.12.0-beta.1 → 2.12.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.
- package/dist/standalone/cli.js +183 -161
- package/package.json +1 -1
package/dist/standalone/cli.js
CHANGED
|
@@ -307139,7 +307139,8 @@ const error_1 = __webpack_require__(40430);
|
|
|
307139
307139
|
const os = __importStar(__webpack_require__(70857));
|
|
307140
307140
|
// 10 MB
|
|
307141
307141
|
exports.BIG_FILE_SIZE = 10485760;
|
|
307142
|
-
|
|
307142
|
+
// ZipFile 上传最大 1.5MB
|
|
307143
|
+
exports.API_MAX_SIZE = 1.5 * 1024 * 1024;
|
|
307143
307144
|
var CodeType;
|
|
307144
307145
|
(function (CodeType) {
|
|
307145
307146
|
CodeType[CodeType["File"] = 0] = "File";
|
|
@@ -307228,7 +307229,7 @@ class FunctionPacker {
|
|
|
307228
307229
|
const fileStats = await promiseStat(this.zipFilePath);
|
|
307229
307230
|
return fileStats.size > exports.BIG_FILE_SIZE;
|
|
307230
307231
|
}
|
|
307231
|
-
//
|
|
307232
|
+
// ZipFile 上传最大 1.5MB
|
|
307232
307233
|
async isReachMaxSize() {
|
|
307233
307234
|
if (!this.zipFilePath) {
|
|
307234
307235
|
await this.build();
|
|
@@ -326020,7 +326021,7 @@ module.exports = function generate_pattern(it, $keyword, $ruleType) {
|
|
|
326020
326021
|
/***/ ((module) => {
|
|
326021
326022
|
|
|
326022
326023
|
"use strict";
|
|
326023
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.0
|
|
326024
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.0","description":"cli tool for cloudbase","main":"lib/index.js","scripts":{"build":"rimraf lib types && tsc --resolveJsonModule && cpx \\"src/**/*.html\\" lib","watch":"rimraf lib types && tsc -w","dev":"rimraf lib types && cpx \\"src/**/*.html\\" lib && tsc -w","eslint":"eslint \\"./**/*.ts\\"","test":"node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --forceExit --detectOpenHandles --coverage --verbose --testTimeout=10000","tsc":"tsc","pkg":"pkg ./bin/cloudbase.js --out-path ./pkg","postinstall":"node ./post-install.js || exit 0 && patch-package","prepublishOnly":"node ./scripts/check-publish-source.js","debug":"bin/tcb.js lowcode watch","build:bundle":"webpack --config build/webpack/cli.cjs && webpack --config build/webpack/ccr.cjs && node build/scripts/copy-figlet-fonts.js","package:darwin-arm64":"OS=darwin ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:darwin-x64":"OS=darwin ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-arm64":"OS=linux ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-x64":"OS=linux ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:all":"bash build/scripts/build-all.sh","node:fetch:one":"node -e \\"require(\'child_process\').execSync(\'bash build/scripts/fetch-node.sh\',{stdio:\'inherit\'})\\"","node:fetch:all":"NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh --all","node:fetch:win-x64":"OS=windows ARCH=x64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","node:fetch:win-arm64":"OS=windows ARCH=arm64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","package:windows-x64":"OS=windows ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-arm64":"OS=windows ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-all":"npm run -s node:fetch:win-x64 && npm run -s node:fetch:win-arm64 && npm run -s package:windows-x64 && npm run -s package:windows-arm64","package:npm":"npm run build && npm run build:bundle && bash build/scripts/prepare-publish.sh","out:prune":"bash build/scripts/prune-out.sh","i18n:scan":"i18next-scanner --config locales/i18next-scanner.config.js && node locales/scripts/generate.js","i18n:sync":"node locales/scripts/sync.js sync","publish":"node ./scripts/publish.js"},"repository":{"type":"git","url":"https://github.com/TencentCloudBase/cloud-base-cli.git"},"bin":{"cloudbase":"bin/cloudbase.js","cloudbase-mcp":"bin/cloudbase-mcp.cjs","tcb":"bin/tcb.js"},"husky":{"hooks":{"pre-commit":"npm run build"}},"author":"cwuyiqing@gmail.com","license":"ISC","dependencies":{"@cloudbase/cloud-api":"^0.5.5","@cloudbase/cloudbase-mcp":"^2.7.3","@cloudbase/framework-core":"^1.9.7","@cloudbase/functions-framework":"1.16.0","@cloudbase/iac-core":"0.0.3-alpha.14","@cloudbase/lowcode-cli":"^0.23.0","@cloudbase/manager-node":"4.7.2","@cloudbase/toolbox":"^0.7.9","@dotenvx/dotenvx":"^1.48.3","@musistudio/claude-code-router":"1.0.36","address":"^1.1.2","camelcase-keys":"^7.0.2","chalk":"^2.4.2","cli-table3":"^0.5.1","commander":"7","del":"^5.1.0","didyoumean":"^1.2.2","enquirer":"^2.3.6","execa":"^4.0.3","figlet":"^1.7.0","fs-extra":"^8.1.0","gradient-string":"^2.0.2","https-proxy-agent":"^5.0.1","i":"^0.3.7","inquirer":"^6.5.0","json-schema-to-typescript":"^14.0.5","lodash":"^4.17.21","log-symbols":"^3.0.0","lowdb":"^1.0.0","make-dir":"^3.0.0","node-fetch":"^2.6.0","nodemon":"^3.1.4","npm":"^11.5.2","open":"^7.0.0","ora":"^4.0.2","os-locale":"5.0.0","patch-package":"^8.0.0","portfinder":"^1.0.28","progress":"^2.0.3","query-string":"^6.8.1","reflect-metadata":"^0.1.13","semver":"^7.3.7","simple-git":"^3.28.0","tar-fs":"^2.0.1","terminal-link":"^2.1.1","toml":"^3.0.0","unzipper":"^0.10.10","update-notifier":"^4.0.0","xdg-basedir":"^4.0.0","yargs":"^16.2.0","yargs-parser":"^21.0.1","zod":"^4.0.13"},"devDependencies":{"@babel/parser":"^7.28.4","@babel/traverse":"^7.28.4","@babel/types":"^7.28.4","@types/fs-extra":"^11.0.4","@types/jest":"^27","@types/koa__router":"^8.0.11","@types/lodash":"^4.14.182","@types/node":"^12.12.38","@types/node-fetch":"^2.5.4","@types/react":"^17.0.37","@types/semver":"^7.3.9","@types/unzipper":"^0.10.11","@types/webpack-dev-server":"^3.11.1","@typescript-eslint/eslint-plugin":"^4.8.1","@typescript-eslint/parser":"^4.8.1","cpx":"^1.5.0","eslint":"^7.14.0","eslint-config-alloy":"^3.8.2","husky":"^3.0.9","i18next-scanner":"^4.6.0","jest":"^27","rimraf":"^3.0.2","ts-jest":"^27","typescript":"^4.7.2","webpack":"^5.92.0","webpack-cli":"^5.1.4"},"packageManager":"yarn@3.6.2+sha512.2c2f8b9615e6659773f65cdec7cf92ef773a98a99e611579601f61c7a91ec94c89c929aac86f1cee819421a9b0db7acfd53ec3ebb95af44f77f77634b08b9557"}');
|
|
326024
326025
|
|
|
326025
326026
|
/***/ }),
|
|
326026
326027
|
|
|
@@ -387807,12 +387808,20 @@ async function main() {
|
|
|
387807
387808
|
process.exit(1)
|
|
387808
387809
|
}
|
|
387809
387810
|
|
|
387810
|
-
|
|
387811
|
+
const yargsParsedResult = yargsParser(process.argv.slice(2))
|
|
387812
|
+
|
|
387813
|
+
// -v 时只输出版本信息后退出
|
|
387814
|
+
const isVersionCmd = process.argv.includes('-v') || process.argv.includes('--version')
|
|
387815
|
+
const isCommandEmpty = yargsParsedResult._.length === 0
|
|
387816
|
+
|
|
387811
387817
|
// 输出版本信息
|
|
387812
387818
|
console.log(chalk.gray(`CloudBase CLI ${pkg.version}`))
|
|
387813
387819
|
console.log(chalk.gray(t('试试 tcb ai 命令,开启 AI 原生开发')))
|
|
387820
|
+
|
|
387821
|
+
if (isVersionCmd && isCommandEmpty) {
|
|
387822
|
+
process.exit(0)
|
|
387823
|
+
}
|
|
387814
387824
|
|
|
387815
|
-
const yargsParsedResult = yargsParser(process.argv.slice(2))
|
|
387816
387825
|
const config = await getCloudBaseConfig(yargsParsedResult.configFile)
|
|
387817
387826
|
const privateSettings = getPrivateSettings(config)
|
|
387818
387827
|
if (privateSettings) {
|
|
@@ -387836,16 +387845,6 @@ async function main() {
|
|
|
387836
387845
|
// HACK: 隐藏自动生成的 help 信息
|
|
387837
387846
|
program.helpOption(false)
|
|
387838
387847
|
}
|
|
387839
|
-
const isCommandEmpty = yargsParsedResult._.length === 0
|
|
387840
|
-
|
|
387841
|
-
// -v 时输出的版本信息,设置时避免影响其他命令使用 -v
|
|
387842
|
-
if (isCommandEmpty) {
|
|
387843
|
-
program.version(
|
|
387844
|
-
`\nCLI: ${pkg.version}`,
|
|
387845
|
-
'-v, --version',
|
|
387846
|
-
t('输出当前 CloudBase CLI 版本')
|
|
387847
|
-
)
|
|
387848
|
-
}
|
|
387849
387848
|
|
|
387850
387849
|
// 处理无效命令
|
|
387851
387850
|
program.action(() => {
|
|
@@ -511745,7 +511744,7 @@ module.exports = setup;
|
|
|
511745
511744
|
// static credentail = 'credential'
|
|
511746
511745
|
// }
|
|
511747
511746
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
511748
|
-
exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
511747
|
+
exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.INTERNAL_ENDPOINT_REGION = exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
|
|
511749
511748
|
exports.ENV_NAME = {
|
|
511750
511749
|
ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
|
|
511751
511750
|
ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
|
|
@@ -511797,6 +511796,7 @@ exports.SCF_STATUS = {
|
|
|
511797
511796
|
};
|
|
511798
511797
|
// 是否使用内网域名
|
|
511799
511798
|
exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
|
|
511799
|
+
exports.INTERNAL_ENDPOINT_REGION = process.env.INTERNAL_ENDPOINT_REGION;
|
|
511800
511800
|
exports.COS_SDK_PROTOCOL = process.env.COS_SDK_PROTOCOL;
|
|
511801
511801
|
exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
|
|
511802
511802
|
|
|
@@ -673257,8 +673257,8 @@ exports.RuntimeOptions = [
|
|
|
673257
673257
|
{ name: 'Python 3.7', value: 'Python3.7', handler: 'index.main' },
|
|
673258
673258
|
{ name: 'PHP 8.0', value: 'Php8.0', handler: 'index.main' },
|
|
673259
673259
|
{ name: 'PHP 7.4', value: 'Php7.4', handler: 'index.main' },
|
|
673260
|
-
{ name: 'Java 11', value: 'Java11', handler: '
|
|
673261
|
-
{ name: 'Java 8', value: 'Java8', handler: '
|
|
673260
|
+
{ name: 'Java 11', value: 'Java11', handler: 'example.Hello::mainHandler' },
|
|
673261
|
+
{ name: 'Java 8', value: 'Java8', handler: 'example.Hello::mainHandler' }
|
|
673262
673262
|
];
|
|
673263
673263
|
exports.DefaultCloudBaseConfig = {
|
|
673264
673264
|
functionRoot: './functions',
|
|
@@ -691196,7 +691196,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
691196
691196
|
exports.CloudBaseContext = void 0;
|
|
691197
691197
|
const constant_1 = __webpack_require__(40762);
|
|
691198
691198
|
class CloudBaseContext {
|
|
691199
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
|
|
691199
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined, internalEndpointRegion = undefined }) {
|
|
691200
691200
|
this.secretId = secretId;
|
|
691201
691201
|
this.secretKey = secretKey;
|
|
691202
691202
|
this.token = token;
|
|
@@ -691204,10 +691204,14 @@ class CloudBaseContext {
|
|
|
691204
691204
|
this.region = region;
|
|
691205
691205
|
this.envType = envType;
|
|
691206
691206
|
this.useInternalEndpoint = useInternalEndpoint;
|
|
691207
|
+
this.internalEndpointRegion = internalEndpointRegion;
|
|
691207
691208
|
}
|
|
691208
691209
|
isInternalEndpoint() {
|
|
691209
691210
|
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
691210
691211
|
}
|
|
691212
|
+
getInternalEndpointRegion() {
|
|
691213
|
+
return this.internalEndpointRegion || constant_1.INTERNAL_ENDPOINT_REGION;
|
|
691214
|
+
}
|
|
691211
691215
|
}
|
|
691212
691216
|
exports.CloudBaseContext = CloudBaseContext;
|
|
691213
691217
|
|
|
@@ -776593,6 +776597,7 @@ class CloudService {
|
|
|
776593
776597
|
}
|
|
776594
776598
|
get baseUrl() {
|
|
776595
776599
|
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
776600
|
+
const internalEndpointRegion = this.cloudBaseContext.getInternalEndpointRegion();
|
|
776596
776601
|
const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
|
|
776597
776602
|
const urlMap = {
|
|
776598
776603
|
tcb,
|
|
@@ -776607,6 +776612,9 @@ class CloudService {
|
|
|
776607
776612
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
776608
776613
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
776609
776614
|
if (internalEndpoint) {
|
|
776615
|
+
if (internalEndpointRegion) {
|
|
776616
|
+
return `https://${this.service}.${internalEndpointRegion}.tencentcloudapi.woa.com`;
|
|
776617
|
+
}
|
|
776610
776618
|
return intranetUrlMap[this.service] || `https://${this.service}.internal.tencentcloudapi.com`;
|
|
776611
776619
|
}
|
|
776612
776620
|
if (urlMap[this.service]) {
|
|
@@ -799742,7 +799750,7 @@ export PORT=9000
|
|
|
799742
799750
|
else if (runtime.startsWith('Go')) {
|
|
799743
799751
|
return `#!/bin/bash
|
|
799744
799752
|
export PORT=9000
|
|
799745
|
-
|
|
799753
|
+
./${entryFileBase}
|
|
799746
799754
|
`;
|
|
799747
799755
|
}
|
|
799748
799756
|
const defaultVersion = constant_1.DefaultFunctionDeployConfig.runtime.replace('Nodejs', '');
|
|
@@ -799771,15 +799779,15 @@ function checkAndCreateBootstrap(functionPath, func, options = {}) {
|
|
|
799771
799779
|
});
|
|
799772
799780
|
if (!createBootstrap) {
|
|
799773
799781
|
utils_1.logger.info(cancelMessage);
|
|
799774
|
-
utils_1.logger.info((0, i18n_1.t)('参考文档:https://docs.cloudbase.net/cli-v1/functions/
|
|
799782
|
+
utils_1.logger.info((0, i18n_1.t)('参考文档:https://docs.cloudbase.net/cli-v1/functions/deploy#%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC'));
|
|
799775
799783
|
return false;
|
|
799776
799784
|
}
|
|
799777
799785
|
const bootstrapContent = generateBootstrapContent(func);
|
|
799778
799786
|
fs_1.default.writeFileSync(bootstrapPath, bootstrapContent, { mode: 0o755 });
|
|
799779
799787
|
utils_1.logger.success((0, i18n_1.t)('已创建 scf_bootstrap 文件:{{path}}', { path: bootstrapPath }));
|
|
799780
799788
|
utils_1.logger.info('');
|
|
799781
|
-
utils_1.logger.warn((0, i18n_1.t)('
|
|
799782
|
-
utils_1.logger.info((0, i18n_1.t)('
|
|
799789
|
+
utils_1.logger.warn((0, i18n_1.t)('可以根据您的实际项目修改启动命令'));
|
|
799790
|
+
utils_1.logger.info((0, i18n_1.t)('参考文档:https://docs.cloudbase.net/cli-v1/functions/deploy#%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC'));
|
|
799783
799791
|
utils_1.logger.info('');
|
|
799784
799792
|
const { continueDeploy } = yield inquirer_1.default.prompt({
|
|
799785
799793
|
type: 'confirm',
|
|
@@ -833739,7 +833747,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
833739
833747
|
exports.FunctionDeploy = void 0;
|
|
833740
833748
|
const path_1 = __importDefault(__webpack_require__(16928));
|
|
833741
833749
|
const inquirer_1 = __importDefault(__webpack_require__(6403));
|
|
833742
|
-
const toolbox_1 = __webpack_require__(25901);
|
|
833743
833750
|
const common_1 = __webpack_require__(48431);
|
|
833744
833751
|
const error_1 = __webpack_require__(66759);
|
|
833745
833752
|
const function_1 = __webpack_require__(11686);
|
|
@@ -833751,11 +833758,6 @@ const decorators_1 = __webpack_require__(93480);
|
|
|
833751
833758
|
const function_2 = __webpack_require__(11686);
|
|
833752
833759
|
const i18n_1 = __webpack_require__(69258);
|
|
833753
833760
|
const utils_2 = __webpack_require__(75213);
|
|
833754
|
-
const regionIdMap = {
|
|
833755
|
-
'ap-guangzhou': 1,
|
|
833756
|
-
'ap-shanghai': 4,
|
|
833757
|
-
'ap-beijing': 8
|
|
833758
|
-
};
|
|
833759
833761
|
let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
833760
833762
|
get options() {
|
|
833761
833763
|
return {
|
|
@@ -833806,133 +833808,147 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
833806
833808
|
let { envId, config, options } = ctx;
|
|
833807
833809
|
const { functions } = config;
|
|
833808
833810
|
const { force, codeSecret, path: access, all, dir, httpFn, deployMode } = options;
|
|
833809
|
-
|
|
833811
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
833812
|
+
this.validateOptions({ deployMode, access }, log);
|
|
833813
|
+
const isUnresolvedEnvId = !envId || envId.startsWith('{{');
|
|
833814
|
+
if (isUnresolvedEnvId) {
|
|
833815
|
+
if (envId === null || envId === void 0 ? void 0 : envId.startsWith('{{')) {
|
|
833816
|
+
log.warn((0, i18n_1.t)('配置文件中的环境变量 {{envId}} 未找到对应的值,请选择环境', { envId }));
|
|
833817
|
+
}
|
|
833810
833818
|
envId = yield (0, utils_2.selectEnv)();
|
|
833811
833819
|
log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
|
|
833812
833820
|
}
|
|
833813
|
-
const
|
|
833814
|
-
const
|
|
833815
|
-
|
|
833816
|
-
|
|
833817
|
-
|
|
833818
|
-
|
|
833819
|
-
|
|
833820
|
-
|
|
833821
|
-
|
|
833822
|
-
|
|
833823
|
-
|
|
833824
|
-
}
|
|
833825
|
-
if (access && (0, utils_1.checkFullAccess)(access)) {
|
|
833826
|
-
log.warn((0, i18n_1.t)('--path 参数已更换为HTTP 访问服务路径,请使用 --dir 指定部署函数的文件夹路径'));
|
|
833827
|
-
}
|
|
833828
|
-
if (access && access[0] !== '/') {
|
|
833829
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('HTTP 访问服务路径必须以 / 开头'));
|
|
833821
|
+
const configFiles = ['cloudbaserc.json', 'cloudbaserc.js', 'cloudbaserc.yaml', 'cloudbaserc.yml', 'cloudbaserc', 'cloudbase.config.js'];
|
|
833822
|
+
const hasConfigFile = configFiles.some(file => fs_1.default.existsSync(path_1.default.join(process.cwd(), file)));
|
|
833823
|
+
const hasConfig = hasConfigFile || (functions && functions.length > 0);
|
|
833824
|
+
const functionRootPath = hasConfig
|
|
833825
|
+
? path_1.default.join(process.cwd(), config.functionRoot || 'functions')
|
|
833826
|
+
: process.cwd();
|
|
833827
|
+
if (dir) {
|
|
833828
|
+
return this.deployFromDir({
|
|
833829
|
+
name, dir, envId, force, codeSecret, access, httpFn, deployMode,
|
|
833830
|
+
functionRootPath, hasConfig, log
|
|
833831
|
+
});
|
|
833830
833832
|
}
|
|
833831
|
-
if (
|
|
833832
|
-
if (
|
|
833833
|
-
|
|
833834
|
-
|
|
833835
|
-
|
|
833836
|
-
|
|
833837
|
-
name: 'funcName',
|
|
833838
|
-
message: (0, i18n_1.t)('请输入函数名称'),
|
|
833839
|
-
validate: (input) => {
|
|
833840
|
-
if (!input || !input.trim()) {
|
|
833841
|
-
return (0, i18n_1.t)('函数名称不能为空');
|
|
833842
|
-
}
|
|
833843
|
-
return true;
|
|
833844
|
-
}
|
|
833845
|
-
});
|
|
833846
|
-
const runtime = yield this.selectRuntime();
|
|
833847
|
-
currentDirFunc = Object.assign(Object.assign(Object.assign({ name: funcName.trim() }, constant_1.DefaultFunctionDeployConfig), { runtime }), (httpFn ? { type: 'HTTP' } : {}));
|
|
833848
|
-
}
|
|
833849
|
-
if (currentDirFunc) {
|
|
833850
|
-
log.info((0, i18n_1.t)('未找到配置文件,将从当前目录部署云函数'));
|
|
833851
|
-
log.info((0, i18n_1.t)('函数名称:{{name}}', { name: currentDirFunc.name }));
|
|
833852
|
-
log.info((0, i18n_1.t)('默认配置:'));
|
|
833853
|
-
log.info((0, i18n_1.t)(' - 运行时:{{runtime}}', { runtime: currentDirFunc.runtime }));
|
|
833854
|
-
log.info((0, i18n_1.t)(' - 超时时间:{{timeout}} 秒', { timeout: currentDirFunc.timeout }));
|
|
833855
|
-
log.info((0, i18n_1.t)(' - 入口函数:{{handler}}', { handler: currentDirFunc.handler }));
|
|
833856
|
-
log.info((0, i18n_1.t)(' - 在线安装依赖:{{installDependency}}', { installDependency: currentDirFunc.installDependency ? (0, i18n_1.t)('是') : (0, i18n_1.t)('否') }));
|
|
833857
|
-
if (currentDirFunc.type === 'HTTP') {
|
|
833858
|
-
log.info((0, i18n_1.t)(' - 函数类型:HTTP'));
|
|
833859
|
-
}
|
|
833860
|
-
if (currentDirFunc.type === 'HTTP') {
|
|
833861
|
-
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(process.cwd(), currentDirFunc);
|
|
833862
|
-
if (!shouldContinue) {
|
|
833863
|
-
return;
|
|
833864
|
-
}
|
|
833865
|
-
}
|
|
833866
|
-
const loading = (0, utils_1.loadingFactory)();
|
|
833867
|
-
loading.start((0, i18n_1.t)('云函数部署中...'));
|
|
833868
|
-
try {
|
|
833869
|
-
yield (0, function_1.createFunction)({
|
|
833870
|
-
force,
|
|
833871
|
-
envId,
|
|
833872
|
-
codeSecret,
|
|
833873
|
-
functionRootPath: process.cwd(),
|
|
833874
|
-
func: currentDirFunc,
|
|
833875
|
-
accessPath: access,
|
|
833876
|
-
functionPath: '.',
|
|
833877
|
-
deployMode
|
|
833878
|
-
});
|
|
833879
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name: currentDirFunc.name }));
|
|
833880
|
-
this.printSuccessTips(envId);
|
|
833881
|
-
}
|
|
833882
|
-
catch (e) {
|
|
833883
|
-
loading.stop();
|
|
833884
|
-
yield this.handleDeployFail(e, {
|
|
833885
|
-
envId,
|
|
833886
|
-
force,
|
|
833887
|
-
codeSecret,
|
|
833888
|
-
functionRootPath: process.cwd(),
|
|
833889
|
-
func: currentDirFunc,
|
|
833890
|
-
accessPath: access,
|
|
833891
|
-
functionPath: '.'
|
|
833892
|
-
});
|
|
833893
|
-
}
|
|
833894
|
-
if (access || currentDirFunc.path) {
|
|
833895
|
-
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || currentDirFunc.path}`);
|
|
833896
|
-
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
|
|
833897
|
-
}
|
|
833898
|
-
return;
|
|
833899
|
-
}
|
|
833833
|
+
if (hasConfig) {
|
|
833834
|
+
if (name) {
|
|
833835
|
+
return this.deployByName({
|
|
833836
|
+
name, envId, force, codeSecret, access, httpFn, deployMode,
|
|
833837
|
+
functions, functionRootPath, log
|
|
833838
|
+
});
|
|
833900
833839
|
}
|
|
833901
833840
|
return this.deployAllFunction({
|
|
833902
|
-
all,
|
|
833903
|
-
|
|
833904
|
-
force,
|
|
833905
|
-
access,
|
|
833906
|
-
functions,
|
|
833907
|
-
codeSecret,
|
|
833908
|
-
functionRootPath,
|
|
833909
|
-
httpFn,
|
|
833910
|
-
deployMode
|
|
833841
|
+
all, envId, force, access, functions, codeSecret,
|
|
833842
|
+
functionRootPath, httpFn, deployMode
|
|
833911
833843
|
});
|
|
833912
833844
|
}
|
|
833913
|
-
|
|
833914
|
-
|
|
833915
|
-
|
|
833916
|
-
|
|
833917
|
-
|
|
833845
|
+
return this.deployFromCurrentDir({
|
|
833846
|
+
name, envId, force, codeSecret, access, httpFn, deployMode, log
|
|
833847
|
+
});
|
|
833848
|
+
});
|
|
833849
|
+
}
|
|
833850
|
+
validateOptions(options, log) {
|
|
833851
|
+
const { deployMode, access } = options;
|
|
833852
|
+
if (deployMode && !['cos', 'zip'].includes(deployMode)) {
|
|
833853
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('--deployMode 参数只能是 cos 或 zip'));
|
|
833854
|
+
}
|
|
833855
|
+
if (access && (0, utils_1.checkFullAccess)(access)) {
|
|
833856
|
+
log.warn((0, i18n_1.t)('--path 参数已更换为HTTP 访问服务路径,请使用 --dir 指定部署函数的文件夹路径'));
|
|
833857
|
+
}
|
|
833858
|
+
if (access && access[0] !== '/') {
|
|
833859
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('HTTP 访问服务路径必须以 / 开头'));
|
|
833860
|
+
}
|
|
833861
|
+
}
|
|
833862
|
+
deployFromDir(options) {
|
|
833863
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833864
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, deployMode, functionRootPath, log } = options;
|
|
833865
|
+
(0, utils_1.checkFullAccess)(dir, true);
|
|
833866
|
+
if (!(0, utils_1.isDirectory)(dir)) {
|
|
833867
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('--dir 参数必须指定为云函数的文件夹路径'));
|
|
833918
833868
|
}
|
|
833919
|
-
|
|
833920
|
-
|
|
833921
|
-
newFunction = functions.find((item) => item.name === name);
|
|
833869
|
+
if (!name) {
|
|
833870
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('使用 --dir 参数时必须指定函数名称'));
|
|
833922
833871
|
}
|
|
833923
|
-
const
|
|
833924
|
-
|
|
833872
|
+
const runtime = yield this.selectRuntime();
|
|
833873
|
+
const func = Object.assign(Object.assign(Object.assign({ name }, constant_1.DefaultFunctionDeployConfig), { runtime }), (httpFn ? { type: 'HTTP' } : {}));
|
|
833874
|
+
log.info((0, i18n_1.t)('从目录 {{dir}} 部署云函数', { dir }));
|
|
833875
|
+
return this.doDeploySingleFunction({
|
|
833876
|
+
func, envId, force, codeSecret, access, deployMode,
|
|
833877
|
+
functionRootPath, functionPath: dir, log
|
|
833878
|
+
});
|
|
833879
|
+
});
|
|
833880
|
+
}
|
|
833881
|
+
deployByName(options) {
|
|
833882
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833883
|
+
const { name, envId, force, codeSecret, access, httpFn, deployMode, functions, functionRootPath, log } = options;
|
|
833884
|
+
let func = functions === null || functions === void 0 ? void 0 : functions.find((item) => item.name === name);
|
|
833885
|
+
if (!func) {
|
|
833925
833886
|
const runtime = yield this.selectRuntime();
|
|
833926
|
-
log.info((0, i18n_1.t)('
|
|
833927
|
-
|
|
833887
|
+
log.info((0, i18n_1.t)('未找到函数 [{{name}}] 的配置,使用默认配置 => 运行时:{{runtime}}', { name, runtime }));
|
|
833888
|
+
func = Object.assign(Object.assign({ name }, constant_1.DefaultFunctionDeployConfig), { runtime });
|
|
833928
833889
|
}
|
|
833929
833890
|
if (httpFn) {
|
|
833930
|
-
|
|
833891
|
+
func = Object.assign(Object.assign({}, func), { type: 'HTTP' });
|
|
833931
833892
|
}
|
|
833932
|
-
|
|
833933
|
-
|
|
833934
|
-
|
|
833935
|
-
|
|
833893
|
+
return this.doDeploySingleFunction({
|
|
833894
|
+
func, envId, force, codeSecret, access, deployMode,
|
|
833895
|
+
functionRootPath, functionPath: undefined, log
|
|
833896
|
+
});
|
|
833897
|
+
});
|
|
833898
|
+
}
|
|
833899
|
+
deployFromCurrentDir(options) {
|
|
833900
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833901
|
+
const { name, envId, force, codeSecret, access, httpFn, deployMode, log } = options;
|
|
833902
|
+
let func = this.getFunctionFromCurrentDir(httpFn);
|
|
833903
|
+
if (!func) {
|
|
833904
|
+
const funcName = name || (yield this.promptFunctionName());
|
|
833905
|
+
const runtime = yield this.selectRuntime();
|
|
833906
|
+
func = Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime }), (httpFn ? { type: 'HTTP' } : {}));
|
|
833907
|
+
}
|
|
833908
|
+
else if (name) {
|
|
833909
|
+
func.name = name;
|
|
833910
|
+
}
|
|
833911
|
+
log.info((0, i18n_1.t)('未找到配置文件,将从当前目录部署云函数'));
|
|
833912
|
+
this.printFunctionConfig(func, log);
|
|
833913
|
+
return this.doDeploySingleFunction({
|
|
833914
|
+
func, envId, force, codeSecret, access, deployMode,
|
|
833915
|
+
functionRootPath: process.cwd(), functionPath: '.', log
|
|
833916
|
+
});
|
|
833917
|
+
});
|
|
833918
|
+
}
|
|
833919
|
+
promptFunctionName() {
|
|
833920
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833921
|
+
const { funcName } = yield inquirer_1.default.prompt({
|
|
833922
|
+
type: 'input',
|
|
833923
|
+
name: 'funcName',
|
|
833924
|
+
message: (0, i18n_1.t)('请输入函数名称'),
|
|
833925
|
+
validate: (input) => {
|
|
833926
|
+
if (!input || !input.trim()) {
|
|
833927
|
+
return (0, i18n_1.t)('函数名称不能为空');
|
|
833928
|
+
}
|
|
833929
|
+
return true;
|
|
833930
|
+
}
|
|
833931
|
+
});
|
|
833932
|
+
return funcName.trim();
|
|
833933
|
+
});
|
|
833934
|
+
}
|
|
833935
|
+
printFunctionConfig(func, log) {
|
|
833936
|
+
log.info((0, i18n_1.t)('函数名称:{{name}}', { name: func.name }));
|
|
833937
|
+
log.info((0, i18n_1.t)('默认配置:'));
|
|
833938
|
+
log.info((0, i18n_1.t)(' - 运行时:{{runtime}}', { runtime: func.runtime }));
|
|
833939
|
+
log.info((0, i18n_1.t)(' - 超时时间:{{timeout}} 秒', { timeout: func.timeout }));
|
|
833940
|
+
log.info((0, i18n_1.t)(' - 入口函数:{{handler}}', { handler: func.handler }));
|
|
833941
|
+
log.info((0, i18n_1.t)(' - 在线安装依赖:{{installDependency}}', { installDependency: func.installDependency ? (0, i18n_1.t)('是') : (0, i18n_1.t)('否') }));
|
|
833942
|
+
if (func.type === 'HTTP') {
|
|
833943
|
+
log.info((0, i18n_1.t)(' - 函数类型:HTTP'));
|
|
833944
|
+
}
|
|
833945
|
+
}
|
|
833946
|
+
doDeploySingleFunction(options) {
|
|
833947
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
833948
|
+
const { func, envId, force, codeSecret, access, deployMode, functionRootPath, functionPath, log } = options;
|
|
833949
|
+
if (func.type === 'HTTP') {
|
|
833950
|
+
const funcPath = functionPath === '.' ? process.cwd() : (functionPath || path_1.default.join(functionRootPath, func.name));
|
|
833951
|
+
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(funcPath, func);
|
|
833936
833952
|
if (!shouldContinue) {
|
|
833937
833953
|
return;
|
|
833938
833954
|
}
|
|
@@ -833945,12 +833961,12 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
833945
833961
|
envId,
|
|
833946
833962
|
codeSecret,
|
|
833947
833963
|
functionRootPath,
|
|
833948
|
-
func
|
|
833964
|
+
func,
|
|
833949
833965
|
accessPath: access,
|
|
833950
833966
|
functionPath,
|
|
833951
833967
|
deployMode
|
|
833952
833968
|
});
|
|
833953
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name:
|
|
833969
|
+
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name: func.name }));
|
|
833954
833970
|
this.printSuccessTips(envId);
|
|
833955
833971
|
}
|
|
833956
833972
|
catch (e) {
|
|
@@ -833960,13 +833976,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
833960
833976
|
force,
|
|
833961
833977
|
codeSecret,
|
|
833962
833978
|
functionRootPath,
|
|
833963
|
-
func
|
|
833979
|
+
func,
|
|
833964
833980
|
accessPath: access,
|
|
833965
833981
|
functionPath
|
|
833966
833982
|
});
|
|
833967
833983
|
}
|
|
833968
|
-
if (access ||
|
|
833969
|
-
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access ||
|
|
833984
|
+
if (access || func.path) {
|
|
833985
|
+
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || func.path}`);
|
|
833970
833986
|
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
|
|
833971
833987
|
}
|
|
833972
833988
|
});
|
|
@@ -834129,8 +834145,11 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834129
834145
|
loading.stop();
|
|
834130
834146
|
throw e;
|
|
834131
834147
|
}
|
|
834132
|
-
return;
|
|
834133
834148
|
}
|
|
834149
|
+
else {
|
|
834150
|
+
utils_1.logger.info((0, i18n_1.t)('已取消部署'));
|
|
834151
|
+
}
|
|
834152
|
+
return;
|
|
834134
834153
|
}
|
|
834135
834154
|
throw e;
|
|
834136
834155
|
});
|
|
@@ -834167,9 +834186,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834167
834186
|
}
|
|
834168
834187
|
printSuccessTips(envId, log) {
|
|
834169
834188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834170
|
-
|
|
834171
|
-
const region = yield (0, toolbox_1.getRegion)();
|
|
834172
|
-
url += `&rid=${regionIdMap[region]}`;
|
|
834189
|
+
const url = `${utils_1.EUrl.DevPlatform}?envId=${envId}#/scf`;
|
|
834173
834190
|
const link = (0, utils_1.genClickableLink)(url);
|
|
834174
834191
|
log.breakLine();
|
|
834175
834192
|
log.info((0, i18n_1.t)('控制台查看函数详情或创建HTTP 访问服务链接 🔗:{{link}}', { link }));
|
|
@@ -891850,7 +891867,7 @@ class CloudBase {
|
|
|
891850
891867
|
}
|
|
891851
891868
|
constructor(config = {}) {
|
|
891852
891869
|
this.cloudBaseConfig = {};
|
|
891853
|
-
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
|
|
891870
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint, internalEndpointRegion } = config;
|
|
891854
891871
|
// config 中传入的 secretId secretkey 必须同时存在
|
|
891855
891872
|
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
891856
891873
|
throw new Error('secretId and secretKey must be a pair');
|
|
@@ -891863,7 +891880,8 @@ class CloudBase {
|
|
|
891863
891880
|
envType,
|
|
891864
891881
|
proxy,
|
|
891865
891882
|
region,
|
|
891866
|
-
useInternalEndpoint
|
|
891883
|
+
useInternalEndpoint,
|
|
891884
|
+
internalEndpointRegion,
|
|
891867
891885
|
};
|
|
891868
891886
|
// 初始化 context
|
|
891869
891887
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
|
@@ -900143,12 +900161,12 @@ class FunctionService {
|
|
|
900143
900161
|
}
|
|
900144
900162
|
async getCodeParams(options, installDependency) {
|
|
900145
900163
|
const { func, functionPath, functionRootPath, base64Code, deployMode } = options;
|
|
900146
|
-
//
|
|
900147
|
-
//
|
|
900148
|
-
const MAX_ZIP_SIZE =
|
|
900149
|
-
const MAX_BASE64_LENGTH = Math.floor(MAX_ZIP_SIZE * 4 / 3); // ≈
|
|
900164
|
+
// 直接传入 base64Code 的情况,校验大小
|
|
900165
|
+
// ZipFile 上传大小上限 1.5MB,base64 编码后长度约为原始大小的 4/3
|
|
900166
|
+
const MAX_ZIP_SIZE = 1.5 * 1024 * 1024; // 1.5MB
|
|
900167
|
+
const MAX_BASE64_LENGTH = Math.floor(MAX_ZIP_SIZE * 4 / 3); // ≈ 2097152
|
|
900150
900168
|
if ((base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) > MAX_BASE64_LENGTH) {
|
|
900151
|
-
throw new error_1.CloudBaseError('
|
|
900169
|
+
throw new error_1.CloudBaseError('ZipFile 上传不能大于 1.5MB,请使用 COS 上传方式');
|
|
900152
900170
|
}
|
|
900153
900171
|
if (base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) {
|
|
900154
900172
|
return {
|
|
@@ -900168,10 +900186,14 @@ class FunctionService {
|
|
|
900168
900186
|
root: functionRootPath
|
|
900169
900187
|
});
|
|
900170
900188
|
await packer.build();
|
|
900171
|
-
//
|
|
900172
|
-
// 判断是否需要走 COS 上传
|
|
900189
|
+
// 判断是否超过 ZipFile 上传大小限制(1.5MB)
|
|
900173
900190
|
const reachMax = await packer.isReachMaxSize();
|
|
900174
|
-
|
|
900191
|
+
// 如果指定了 zip 上传方式但超过大小限制,直接报错
|
|
900192
|
+
if (deployMode === 'zip' && reachMax) {
|
|
900193
|
+
throw new error_1.CloudBaseError('ZipFile 上传不能大于 1.5MB,请使用 COS 上传方式(deployMode: "cos")');
|
|
900194
|
+
}
|
|
900195
|
+
// 走 COS 上传:指定 cos 模式,或未指定模式但超过大小限制
|
|
900196
|
+
const useCos = deployMode === 'cos' || reachMax;
|
|
900175
900197
|
if (useCos) {
|
|
900176
900198
|
// 先调用scf的 COS 上传方式
|
|
900177
900199
|
const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
|