@cloudbase/cli 2.12.2 → 2.12.3-beta.1
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 +878 -140
- package/package.json +1 -1
package/dist/standalone/cli.js
CHANGED
|
@@ -326147,7 +326147,7 @@ module.exports = function generate_pattern(it, $keyword, $ruleType) {
|
|
|
326147
326147
|
/***/ ((module) => {
|
|
326148
326148
|
|
|
326149
326149
|
"use strict";
|
|
326150
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.
|
|
326150
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.3-beta.1","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.10.1","@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"}');
|
|
326151
326151
|
|
|
326152
326152
|
/***/ }),
|
|
326153
326153
|
|
|
@@ -383915,6 +383915,7 @@ __exportStar(__webpack_require__(87531), exports);
|
|
|
383915
383915
|
__exportStar(__webpack_require__(5476), exports);
|
|
383916
383916
|
__exportStar(__webpack_require__(74371), exports);
|
|
383917
383917
|
__exportStar(__webpack_require__(37210), exports);
|
|
383918
|
+
__exportStar(__webpack_require__(64180), exports);
|
|
383918
383919
|
__exportStar(__webpack_require__(22700), exports);
|
|
383919
383920
|
__exportStar(__webpack_require__(32428), exports);
|
|
383920
383921
|
__exportStar(__webpack_require__(29561), exports);
|
|
@@ -493661,6 +493662,10 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493661
493662
|
{
|
|
493662
493663
|
flags: '-e, --envId <envId>',
|
|
493663
493664
|
desc: (0, i18n_1.t)('环境 Id')
|
|
493665
|
+
},
|
|
493666
|
+
{
|
|
493667
|
+
flags: '--yes',
|
|
493668
|
+
desc: (0, i18n_1.t)('跳过交互确认,使用默认选项自动执行')
|
|
493664
493669
|
}
|
|
493665
493670
|
],
|
|
493666
493671
|
desc: (0, i18n_1.t)('更新云函数配置'),
|
|
@@ -493670,26 +493675,35 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493670
493675
|
}
|
|
493671
493676
|
execute(ctx, params, log) {
|
|
493672
493677
|
return __awaiter(this, void 0, void 0, function* () {
|
|
493673
|
-
let { envId, config: { functions } } = ctx;
|
|
493678
|
+
let { envId, config: { functions }, options } = ctx;
|
|
493674
493679
|
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
493680
|
+
const { yes } = options;
|
|
493675
493681
|
let isBathUpdate = false;
|
|
493676
493682
|
if (!envId) {
|
|
493677
493683
|
envId = yield (0, utils_1.selectEnv)({ envTypes: [constant_1.EnvType.BAAS, constant_1.EnvType.WEDA] });
|
|
493678
493684
|
}
|
|
493679
493685
|
if (!name) {
|
|
493680
|
-
|
|
493681
|
-
|
|
493682
|
-
|
|
493683
|
-
|
|
493684
|
-
|
|
493685
|
-
|
|
493686
|
-
|
|
493686
|
+
if (yes) {
|
|
493687
|
+
log.info((0, i18n_1.t)('🚀 --yes 模式:自动更新配置文件中的全部云函数配置'));
|
|
493688
|
+
isBathUpdate = true;
|
|
493689
|
+
}
|
|
493690
|
+
else {
|
|
493691
|
+
const { isBatch } = yield inquirer_1.default.prompt({
|
|
493692
|
+
type: 'confirm',
|
|
493693
|
+
name: 'isBatch',
|
|
493694
|
+
message: (0, i18n_1.t)('无云函数名称,是否需要更新配置文件中的【全部云函数】的配置?'),
|
|
493695
|
+
default: false
|
|
493696
|
+
});
|
|
493697
|
+
isBathUpdate = isBatch;
|
|
493698
|
+
}
|
|
493687
493699
|
if (!isBathUpdate) {
|
|
493688
493700
|
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
|
|
493689
493701
|
}
|
|
493690
493702
|
}
|
|
493691
493703
|
if (isBathUpdate) {
|
|
493692
|
-
const envVarUpdateMode = hasEnvVariablesConfig(functions)
|
|
493704
|
+
const envVarUpdateMode = hasEnvVariablesConfig(functions)
|
|
493705
|
+
? (yes ? 'overwrite' : yield askEnvVarUpdateMode())
|
|
493706
|
+
: undefined;
|
|
493693
493707
|
for (const func of functions) {
|
|
493694
493708
|
const isValid = yield validateFunctionTypeChange(envId, func, log);
|
|
493695
493709
|
if (!isValid) {
|
|
@@ -493713,7 +493727,9 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493713
493727
|
if (!isValid) {
|
|
493714
493728
|
return;
|
|
493715
493729
|
}
|
|
493716
|
-
const envVarUpdateMode = hasEnvVariablesConfig([functionItem])
|
|
493730
|
+
const envVarUpdateMode = hasEnvVariablesConfig([functionItem])
|
|
493731
|
+
? (yes ? 'overwrite' : yield askEnvVarUpdateMode())
|
|
493732
|
+
: undefined;
|
|
493717
493733
|
yield (0, function_1.updateFunctionConfig)({
|
|
493718
493734
|
envId,
|
|
493719
493735
|
functionName: name,
|
|
@@ -673704,15 +673720,20 @@ exports.DefaultFunctionDeployConfig = {
|
|
|
673704
673720
|
ignore: ['node_modules', 'node_modules/**/*', '.git']
|
|
673705
673721
|
};
|
|
673706
673722
|
exports.RuntimeOptions = [
|
|
673723
|
+
{ name: 'Node.js 24.11 (公测中)', value: 'Nodejs24.11', handler: 'index.main' },
|
|
673724
|
+
{ name: 'Node.js 22.21 (公测中)', value: 'Nodejs22.21', handler: 'index.main' },
|
|
673707
673725
|
{ name: 'Node.js 20.19', value: 'Nodejs20.19', handler: 'index.main' },
|
|
673708
673726
|
{ name: 'Node.js 18.15', value: 'Nodejs18.15', handler: 'index.main' },
|
|
673709
673727
|
{ name: 'Node.js 16.13', value: 'Nodejs16.13', handler: 'index.main' },
|
|
673728
|
+
{ name: 'Python 3.11', value: 'Python3.11', handler: 'index.main' },
|
|
673729
|
+
{ name: 'Python 3.10', value: 'Python3.10', handler: 'index.main' },
|
|
673710
673730
|
{ name: 'Python 3.9', value: 'Python3.9', handler: 'index.main' },
|
|
673711
673731
|
{ name: 'Python 3.7', value: 'Python3.7', handler: 'index.main' },
|
|
673712
673732
|
{ name: 'PHP 8.0', value: 'Php8.0', handler: 'index.main' },
|
|
673713
673733
|
{ name: 'PHP 7.4', value: 'Php7.4', handler: 'index.main' },
|
|
673714
673734
|
{ name: 'Java 11', value: 'Java11', handler: 'example.Hello::mainHandler' },
|
|
673715
|
-
{ name: 'Java 8', value: 'Java8', handler: 'example.Hello::mainHandler' }
|
|
673735
|
+
{ name: 'Java 8', value: 'Java8', handler: 'example.Hello::mainHandler' },
|
|
673736
|
+
{ name: 'Golang 1', value: 'Go1', handler: 'main' }
|
|
673716
673737
|
];
|
|
673717
673738
|
exports.DefaultCloudBaseConfig = {
|
|
673718
673739
|
functionRoot: './functions',
|
|
@@ -681785,6 +681806,326 @@ exports.version = version
|
|
|
681785
681806
|
exports.defer = defer
|
|
681786
681807
|
|
|
681787
681808
|
|
|
681809
|
+
/***/ }),
|
|
681810
|
+
|
|
681811
|
+
/***/ 64180:
|
|
681812
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
681813
|
+
|
|
681814
|
+
"use strict";
|
|
681815
|
+
|
|
681816
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
681817
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
681818
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
681819
|
+
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;
|
|
681820
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
681821
|
+
};
|
|
681822
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
681823
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
681824
|
+
};
|
|
681825
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
681826
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
681827
|
+
};
|
|
681828
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
681829
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
681830
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
681831
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
681832
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
681833
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
681834
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
681835
|
+
});
|
|
681836
|
+
};
|
|
681837
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
681838
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
681839
|
+
};
|
|
681840
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
681841
|
+
exports.ConfigPull = void 0;
|
|
681842
|
+
const fs_1 = __importDefault(__webpack_require__(79896));
|
|
681843
|
+
const path_1 = __importDefault(__webpack_require__(16928));
|
|
681844
|
+
const inquirer_1 = __importDefault(__webpack_require__(6403));
|
|
681845
|
+
const common_1 = __webpack_require__(48431);
|
|
681846
|
+
const error_1 = __webpack_require__(66759);
|
|
681847
|
+
const function_1 = __webpack_require__(11686);
|
|
681848
|
+
const utils_1 = __webpack_require__(82079);
|
|
681849
|
+
const utils_2 = __webpack_require__(75213);
|
|
681850
|
+
const decorators_1 = __webpack_require__(93480);
|
|
681851
|
+
const i18n_1 = __webpack_require__(69258);
|
|
681852
|
+
const constant_1 = __webpack_require__(62977);
|
|
681853
|
+
function convertToFunctionConfig(detail, funcDir = '.') {
|
|
681854
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
681855
|
+
const config = {
|
|
681856
|
+
name: detail.FunctionName,
|
|
681857
|
+
dir: funcDir
|
|
681858
|
+
};
|
|
681859
|
+
if (detail.Handler) {
|
|
681860
|
+
config.handler = detail.Handler;
|
|
681861
|
+
}
|
|
681862
|
+
if (detail.Timeout) {
|
|
681863
|
+
config.timeout = detail.Timeout;
|
|
681864
|
+
}
|
|
681865
|
+
if (detail.Runtime) {
|
|
681866
|
+
config.runtime = detail.Runtime;
|
|
681867
|
+
}
|
|
681868
|
+
if (detail.MemorySize) {
|
|
681869
|
+
config.memorySize = detail.MemorySize;
|
|
681870
|
+
}
|
|
681871
|
+
if (detail.InstallDependency !== undefined) {
|
|
681872
|
+
config.installDependency = detail.InstallDependency === 'TRUE';
|
|
681873
|
+
}
|
|
681874
|
+
if (((_b = (_a = detail.Environment) === null || _a === void 0 ? void 0 : _a.Variables) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
681875
|
+
const envVariables = {};
|
|
681876
|
+
for (const item of detail.Environment.Variables) {
|
|
681877
|
+
envVariables[item.Key] = item.Value;
|
|
681878
|
+
}
|
|
681879
|
+
config.envVariables = envVariables;
|
|
681880
|
+
}
|
|
681881
|
+
if (((_c = detail.VpcConfig) === null || _c === void 0 ? void 0 : _c.VpcId) && ((_d = detail.VpcConfig) === null || _d === void 0 ? void 0 : _d.SubnetId)) {
|
|
681882
|
+
config.vpc = {
|
|
681883
|
+
vpcId: detail.VpcConfig.VpcId,
|
|
681884
|
+
subnetId: detail.VpcConfig.SubnetId
|
|
681885
|
+
};
|
|
681886
|
+
}
|
|
681887
|
+
if (((_e = detail.Triggers) === null || _e === void 0 ? void 0 : _e.length) > 0) {
|
|
681888
|
+
config.triggers = detail.Triggers.map((trigger) => ({
|
|
681889
|
+
name: trigger.TriggerName,
|
|
681890
|
+
type: trigger.Type.toLowerCase(),
|
|
681891
|
+
config: trigger.TriggerDesc
|
|
681892
|
+
}));
|
|
681893
|
+
}
|
|
681894
|
+
if (detail.ProtocolType === 'WS') {
|
|
681895
|
+
config.protocolType = 'WS';
|
|
681896
|
+
if ((_g = (_f = detail.ProtocolParams) === null || _f === void 0 ? void 0 : _f.WsParams) === null || _g === void 0 ? void 0 : _g.IdleTimeOut) {
|
|
681897
|
+
config.protocolParams = {
|
|
681898
|
+
wsParams: {
|
|
681899
|
+
idleTimeOut: detail.ProtocolParams.WsParams.IdleTimeOut
|
|
681900
|
+
}
|
|
681901
|
+
};
|
|
681902
|
+
}
|
|
681903
|
+
}
|
|
681904
|
+
if (detail.InstanceConcurrencyConfig) {
|
|
681905
|
+
const concurrencyConfig = {};
|
|
681906
|
+
if (detail.InstanceConcurrencyConfig.MaxConcurrency) {
|
|
681907
|
+
concurrencyConfig.maxConcurrency = detail.InstanceConcurrencyConfig.MaxConcurrency;
|
|
681908
|
+
}
|
|
681909
|
+
if (detail.InstanceConcurrencyConfig.DynamicEnabled !== undefined) {
|
|
681910
|
+
concurrencyConfig.dynamicEnabled = detail.InstanceConcurrencyConfig.DynamicEnabled;
|
|
681911
|
+
}
|
|
681912
|
+
if (Object.keys(concurrencyConfig).length > 0) {
|
|
681913
|
+
config.instanceConcurrencyConfig = concurrencyConfig;
|
|
681914
|
+
}
|
|
681915
|
+
}
|
|
681916
|
+
return config;
|
|
681917
|
+
}
|
|
681918
|
+
function generateCloudbaserc(envId, functionConfig) {
|
|
681919
|
+
return {
|
|
681920
|
+
envId,
|
|
681921
|
+
functionRoot: '.',
|
|
681922
|
+
functions: [functionConfig]
|
|
681923
|
+
};
|
|
681924
|
+
}
|
|
681925
|
+
let ConfigPull = class ConfigPull extends common_1.Command {
|
|
681926
|
+
get options() {
|
|
681927
|
+
return {
|
|
681928
|
+
cmd: 'fn',
|
|
681929
|
+
childCmd: {
|
|
681930
|
+
cmd: 'config',
|
|
681931
|
+
desc: (0, i18n_1.t)('函数配置管理')
|
|
681932
|
+
},
|
|
681933
|
+
childSubCmd: 'pull <name>',
|
|
681934
|
+
options: [
|
|
681935
|
+
{
|
|
681936
|
+
flags: '-e, --envId <envId>',
|
|
681937
|
+
desc: (0, i18n_1.t)('环境 Id')
|
|
681938
|
+
},
|
|
681939
|
+
{
|
|
681940
|
+
flags: '-o, --output <output>',
|
|
681941
|
+
desc: (0, i18n_1.t)('输出文件路径(默认为当前目录下的 cloudbaserc.json)')
|
|
681942
|
+
},
|
|
681943
|
+
{
|
|
681944
|
+
flags: '--stdout',
|
|
681945
|
+
desc: (0, i18n_1.t)('输出到控制台而非文件')
|
|
681946
|
+
},
|
|
681947
|
+
{
|
|
681948
|
+
flags: '--code-secret <codeSecret>',
|
|
681949
|
+
desc: (0, i18n_1.t)('代码加密的函数的 CodeSecret')
|
|
681950
|
+
},
|
|
681951
|
+
{
|
|
681952
|
+
flags: '--dir <dir>',
|
|
681953
|
+
desc: (0, i18n_1.t)('指定目录用于推测配置(当云函数不存在时)')
|
|
681954
|
+
},
|
|
681955
|
+
{
|
|
681956
|
+
flags: '--yes',
|
|
681957
|
+
desc: (0, i18n_1.t)('跳过交互确认,自动覆盖已存在的文件')
|
|
681958
|
+
}
|
|
681959
|
+
],
|
|
681960
|
+
desc: (0, i18n_1.t)('拉取云函数配置(如云函数不存在则从本地推测)'),
|
|
681961
|
+
requiredEnvId: false,
|
|
681962
|
+
autoRunLogin: true
|
|
681963
|
+
};
|
|
681964
|
+
}
|
|
681965
|
+
execute(ctx, params, log) {
|
|
681966
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
681967
|
+
let { envId, options } = ctx;
|
|
681968
|
+
const { output, codeSecret, dir, yes, stdout } = options;
|
|
681969
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
681970
|
+
if (!name) {
|
|
681971
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
|
|
681972
|
+
}
|
|
681973
|
+
if (!envId) {
|
|
681974
|
+
envId = yield (0, utils_2.selectEnv)({ envTypes: [constant_1.EnvType.BAAS, constant_1.EnvType.WEDA] });
|
|
681975
|
+
}
|
|
681976
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
681977
|
+
loading.start((0, i18n_1.t)('获取函数配置中...'));
|
|
681978
|
+
const functionService = yield (0, function_1.getFunctionService)(envId);
|
|
681979
|
+
let config;
|
|
681980
|
+
let isInferred = false;
|
|
681981
|
+
let selectedEnvId = envId;
|
|
681982
|
+
const funcDir = dir || '.';
|
|
681983
|
+
try {
|
|
681984
|
+
const detail = yield functionService.getFunctionDetail(name, codeSecret);
|
|
681985
|
+
loading.stop();
|
|
681986
|
+
config = convertToFunctionConfig(detail, funcDir);
|
|
681987
|
+
log.info((0, i18n_1.t)('✓ 已从云端拉取函数 [{{name}}] 的配置', { name }));
|
|
681988
|
+
}
|
|
681989
|
+
catch (e) {
|
|
681990
|
+
loading.stop();
|
|
681991
|
+
if (e.code === 'ResourceNotFound.Function') {
|
|
681992
|
+
log.warn((0, i18n_1.t)('云函数 [{{name}}] 不存在', { name }));
|
|
681993
|
+
let shouldCreate = yes;
|
|
681994
|
+
if (!shouldCreate) {
|
|
681995
|
+
const { confirm } = yield inquirer_1.default.prompt({
|
|
681996
|
+
type: 'confirm',
|
|
681997
|
+
name: 'confirm',
|
|
681998
|
+
message: (0, i18n_1.t)('是否从本地项目推测并创建配置?'),
|
|
681999
|
+
default: true
|
|
682000
|
+
});
|
|
682001
|
+
shouldCreate = confirm;
|
|
682002
|
+
}
|
|
682003
|
+
if (!shouldCreate) {
|
|
682004
|
+
log.info((0, i18n_1.t)('已取消'));
|
|
682005
|
+
return;
|
|
682006
|
+
}
|
|
682007
|
+
const targetDir = dir ? path_1.default.resolve(process.cwd(), dir) : process.cwd();
|
|
682008
|
+
const inferResult = (0, function_1.inferFunctionConfig)({ name, targetDir });
|
|
682009
|
+
if (inferResult) {
|
|
682010
|
+
config = inferResult.config;
|
|
682011
|
+
config.dir = funcDir;
|
|
682012
|
+
isInferred = true;
|
|
682013
|
+
log.info((0, i18n_1.t)('✓ 已从本地推测出配置(来源:{{source}})', { source: inferResult.source }));
|
|
682014
|
+
}
|
|
682015
|
+
else {
|
|
682016
|
+
config = Object.assign({ name, dir: funcDir }, constant_1.DefaultFunctionDeployConfig);
|
|
682017
|
+
isInferred = true;
|
|
682018
|
+
log.info((0, i18n_1.t)('⚠ 无法从本地推测配置,使用默认配置'));
|
|
682019
|
+
}
|
|
682020
|
+
}
|
|
682021
|
+
else {
|
|
682022
|
+
throw e;
|
|
682023
|
+
}
|
|
682024
|
+
}
|
|
682025
|
+
if (stdout) {
|
|
682026
|
+
const cloudbaserc = generateCloudbaserc(selectedEnvId, config);
|
|
682027
|
+
const stdoutOutput = JSON.stringify(cloudbaserc, null, 2);
|
|
682028
|
+
if (isInferred) {
|
|
682029
|
+
log.info((0, i18n_1.t)('推测的函数 [{{name}}] 配置:', { name }));
|
|
682030
|
+
}
|
|
682031
|
+
else {
|
|
682032
|
+
log.info((0, i18n_1.t)('云函数 [{{name}}] 配置:', { name }));
|
|
682033
|
+
}
|
|
682034
|
+
console.log(stdoutOutput);
|
|
682035
|
+
log.info('');
|
|
682036
|
+
log.info((0, i18n_1.t)('提示:可将上述配置添加到 cloudbaserc.json 的 functions 数组中'));
|
|
682037
|
+
return;
|
|
682038
|
+
}
|
|
682039
|
+
const outputPath = output
|
|
682040
|
+
? path_1.default.resolve(process.cwd(), output)
|
|
682041
|
+
: path_1.default.resolve(process.cwd(), 'cloudbaserc.json');
|
|
682042
|
+
let finalOutput;
|
|
682043
|
+
let isUpdate = false;
|
|
682044
|
+
if (fs_1.default.existsSync(outputPath)) {
|
|
682045
|
+
try {
|
|
682046
|
+
const existingContent = fs_1.default.readFileSync(outputPath, 'utf-8');
|
|
682047
|
+
const existingConfig = JSON.parse(existingContent);
|
|
682048
|
+
if (!existingConfig.functions) {
|
|
682049
|
+
existingConfig.functions = [];
|
|
682050
|
+
}
|
|
682051
|
+
const existingIndex = existingConfig.functions.findIndex((fn) => fn.name === config.name);
|
|
682052
|
+
if (existingIndex >= 0) {
|
|
682053
|
+
let shouldUpdate = yes;
|
|
682054
|
+
if (!shouldUpdate) {
|
|
682055
|
+
const { update } = yield inquirer_1.default.prompt({
|
|
682056
|
+
type: 'confirm',
|
|
682057
|
+
name: 'update',
|
|
682058
|
+
message: (0, i18n_1.t)('函数 [{{name}}] 配置已存在,是否更新?', { name: config.name }),
|
|
682059
|
+
default: true
|
|
682060
|
+
});
|
|
682061
|
+
shouldUpdate = update;
|
|
682062
|
+
}
|
|
682063
|
+
if (!shouldUpdate) {
|
|
682064
|
+
log.info((0, i18n_1.t)('已取消'));
|
|
682065
|
+
return;
|
|
682066
|
+
}
|
|
682067
|
+
existingConfig.functions[existingIndex] = config;
|
|
682068
|
+
isUpdate = true;
|
|
682069
|
+
}
|
|
682070
|
+
else {
|
|
682071
|
+
existingConfig.functions.push(config);
|
|
682072
|
+
}
|
|
682073
|
+
if (!existingConfig.envId) {
|
|
682074
|
+
existingConfig.envId = selectedEnvId;
|
|
682075
|
+
}
|
|
682076
|
+
finalOutput = existingConfig;
|
|
682077
|
+
}
|
|
682078
|
+
catch (parseError) {
|
|
682079
|
+
log.warn((0, i18n_1.t)('现有配置文件解析失败'));
|
|
682080
|
+
let shouldOverwrite = yes;
|
|
682081
|
+
if (!shouldOverwrite) {
|
|
682082
|
+
const { overwrite } = yield inquirer_1.default.prompt({
|
|
682083
|
+
type: 'confirm',
|
|
682084
|
+
name: 'overwrite',
|
|
682085
|
+
message: (0, i18n_1.t)('是否覆盖现有文件?'),
|
|
682086
|
+
default: false
|
|
682087
|
+
});
|
|
682088
|
+
shouldOverwrite = overwrite;
|
|
682089
|
+
}
|
|
682090
|
+
if (!shouldOverwrite) {
|
|
682091
|
+
log.info((0, i18n_1.t)('已取消'));
|
|
682092
|
+
return;
|
|
682093
|
+
}
|
|
682094
|
+
finalOutput = generateCloudbaserc(selectedEnvId, config);
|
|
682095
|
+
}
|
|
682096
|
+
}
|
|
682097
|
+
else {
|
|
682098
|
+
finalOutput = generateCloudbaserc(selectedEnvId, config);
|
|
682099
|
+
}
|
|
682100
|
+
const jsonOutput = JSON.stringify(finalOutput, null, 2);
|
|
682101
|
+
fs_1.default.writeFileSync(outputPath, jsonOutput, 'utf-8');
|
|
682102
|
+
if (isUpdate) {
|
|
682103
|
+
log.success((0, i18n_1.t)('云函数 [{{name}}] 配置已更新到 {{path}}', { name, path: outputPath }));
|
|
682104
|
+
}
|
|
682105
|
+
else if (fs_1.default.existsSync(outputPath)) {
|
|
682106
|
+
log.success((0, i18n_1.t)('云函数 [{{name}}] 配置已追加到 {{path}}', { name, path: outputPath }));
|
|
682107
|
+
}
|
|
682108
|
+
else {
|
|
682109
|
+
log.success((0, i18n_1.t)('云函数 [{{name}}] 配置已保存到 {{path}}', { name, path: outputPath }));
|
|
682110
|
+
}
|
|
682111
|
+
});
|
|
682112
|
+
}
|
|
682113
|
+
};
|
|
682114
|
+
__decorate([
|
|
682115
|
+
(0, decorators_1.InjectParams)(),
|
|
682116
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
682117
|
+
__param(1, (0, decorators_1.ArgsParams)()),
|
|
682118
|
+
__param(2, (0, decorators_1.Log)()),
|
|
682119
|
+
__metadata("design:type", Function),
|
|
682120
|
+
__metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
|
|
682121
|
+
__metadata("design:returntype", Promise)
|
|
682122
|
+
], ConfigPull.prototype, "execute", null);
|
|
682123
|
+
ConfigPull = __decorate([
|
|
682124
|
+
(0, common_1.ICommand)()
|
|
682125
|
+
], ConfigPull);
|
|
682126
|
+
exports.ConfigPull = ConfigPull;
|
|
682127
|
+
|
|
682128
|
+
|
|
681788
682129
|
/***/ }),
|
|
681789
682130
|
|
|
681790
682131
|
/***/ 64182:
|
|
@@ -800354,7 +800695,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
800354
800695
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
800355
800696
|
};
|
|
800356
800697
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
800357
|
-
exports.checkAndCreateBootstrap = exports.generateBootstrapContent = void 0;
|
|
800698
|
+
exports.getConfigSourceDescription = exports.inferFunctionConfig = exports.checkAndCreateBootstrap = exports.generateBootstrapContent = void 0;
|
|
800358
800699
|
const fs_1 = __importDefault(__webpack_require__(79896));
|
|
800359
800700
|
const path_1 = __importDefault(__webpack_require__(16928));
|
|
800360
800701
|
const inquirer_1 = __importDefault(__webpack_require__(6403));
|
|
@@ -800446,6 +800787,206 @@ function checkAndCreateBootstrap(functionPath, func, options = {}) {
|
|
|
800446
800787
|
});
|
|
800447
800788
|
}
|
|
800448
800789
|
exports.checkAndCreateBootstrap = checkAndCreateBootstrap;
|
|
800790
|
+
function inferFunctionConfig(options = {}) {
|
|
800791
|
+
const { name, targetDir = process.cwd(), httpFn } = options;
|
|
800792
|
+
const nodeResult = inferNodejsConfig(targetDir, name, httpFn);
|
|
800793
|
+
if (nodeResult)
|
|
800794
|
+
return nodeResult;
|
|
800795
|
+
const pythonResult = inferPythonConfig(targetDir, name, httpFn);
|
|
800796
|
+
if (pythonResult)
|
|
800797
|
+
return pythonResult;
|
|
800798
|
+
const phpResult = inferPhpConfig(targetDir, name, httpFn);
|
|
800799
|
+
if (phpResult)
|
|
800800
|
+
return phpResult;
|
|
800801
|
+
const javaResult = inferJavaConfig(targetDir, name, httpFn);
|
|
800802
|
+
if (javaResult)
|
|
800803
|
+
return javaResult;
|
|
800804
|
+
const goResult = inferGoConfig(targetDir, name, httpFn);
|
|
800805
|
+
if (goResult)
|
|
800806
|
+
return goResult;
|
|
800807
|
+
const fileBasedResult = inferByFileExtension(targetDir, name, httpFn);
|
|
800808
|
+
if (fileBasedResult)
|
|
800809
|
+
return fileBasedResult;
|
|
800810
|
+
return null;
|
|
800811
|
+
}
|
|
800812
|
+
exports.inferFunctionConfig = inferFunctionConfig;
|
|
800813
|
+
function inferNodejsConfig(targetDir, name, httpFn) {
|
|
800814
|
+
var _a;
|
|
800815
|
+
const packageJsonPath = path_1.default.join(targetDir, 'package.json');
|
|
800816
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
800817
|
+
return null;
|
|
800818
|
+
}
|
|
800819
|
+
try {
|
|
800820
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
800821
|
+
const funcName = name || packageJson.name || path_1.default.basename(targetDir);
|
|
800822
|
+
let handler = constant_1.DefaultFunctionDeployConfig.handler;
|
|
800823
|
+
if (packageJson.main) {
|
|
800824
|
+
const mainFile = path_1.default.basename(packageJson.main).replace(/\.[^.]+$/, '');
|
|
800825
|
+
handler = `${mainFile}.main`;
|
|
800826
|
+
}
|
|
800827
|
+
let runtime = constant_1.DefaultFunctionDeployConfig.runtime;
|
|
800828
|
+
if ((_a = packageJson.engines) === null || _a === void 0 ? void 0 : _a.node) {
|
|
800829
|
+
const nodeVersion = packageJson.engines.node;
|
|
800830
|
+
if (nodeVersion.includes('20')) {
|
|
800831
|
+
runtime = 'Nodejs20.19';
|
|
800832
|
+
}
|
|
800833
|
+
else if (nodeVersion.includes('16')) {
|
|
800834
|
+
runtime = 'Nodejs16.13';
|
|
800835
|
+
}
|
|
800836
|
+
}
|
|
800837
|
+
return {
|
|
800838
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime,
|
|
800839
|
+
handler }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800840
|
+
source: (0, i18n_1.t)('Node.js 项目(package.json)')
|
|
800841
|
+
};
|
|
800842
|
+
}
|
|
800843
|
+
catch (e) {
|
|
800844
|
+
return null;
|
|
800845
|
+
}
|
|
800846
|
+
}
|
|
800847
|
+
function inferPythonConfig(targetDir, name, httpFn) {
|
|
800848
|
+
const pythonFiles = ['requirements.txt', 'setup.py', 'pyproject.toml'];
|
|
800849
|
+
const foundFile = pythonFiles.find(file => fs_1.default.existsSync(path_1.default.join(targetDir, file)));
|
|
800850
|
+
if (!foundFile) {
|
|
800851
|
+
return null;
|
|
800852
|
+
}
|
|
800853
|
+
const funcName = name || path_1.default.basename(targetDir);
|
|
800854
|
+
const entryFiles = ['main.py', 'app.py', 'index.py'];
|
|
800855
|
+
let handler = 'index.main';
|
|
800856
|
+
for (const file of entryFiles) {
|
|
800857
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, file))) {
|
|
800858
|
+
const filename = path_1.default.basename(file, '.py');
|
|
800859
|
+
handler = `${filename}.main`;
|
|
800860
|
+
break;
|
|
800861
|
+
}
|
|
800862
|
+
}
|
|
800863
|
+
return {
|
|
800864
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime: 'Python3.9', handler }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800865
|
+
source: (0, i18n_1.t)('Python 项目({{file}})', { file: foundFile })
|
|
800866
|
+
};
|
|
800867
|
+
}
|
|
800868
|
+
function inferPhpConfig(targetDir, name, httpFn) {
|
|
800869
|
+
const composerJsonPath = path_1.default.join(targetDir, 'composer.json');
|
|
800870
|
+
let hasPhpFiles = false;
|
|
800871
|
+
try {
|
|
800872
|
+
hasPhpFiles = fs_1.default.readdirSync(targetDir).some(file => file.endsWith('.php'));
|
|
800873
|
+
}
|
|
800874
|
+
catch (e) {
|
|
800875
|
+
}
|
|
800876
|
+
if (!fs_1.default.existsSync(composerJsonPath) && !hasPhpFiles) {
|
|
800877
|
+
return null;
|
|
800878
|
+
}
|
|
800879
|
+
let funcName = name || path_1.default.basename(targetDir);
|
|
800880
|
+
let source = (0, i18n_1.t)('PHP 项目(PHP 文件)');
|
|
800881
|
+
if (fs_1.default.existsSync(composerJsonPath)) {
|
|
800882
|
+
try {
|
|
800883
|
+
const composerJson = JSON.parse(fs_1.default.readFileSync(composerJsonPath, 'utf-8'));
|
|
800884
|
+
if (!name && composerJson.name) {
|
|
800885
|
+
funcName = composerJson.name.split('/').pop() || funcName;
|
|
800886
|
+
}
|
|
800887
|
+
source = (0, i18n_1.t)('PHP 项目(composer.json)');
|
|
800888
|
+
}
|
|
800889
|
+
catch (e) {
|
|
800890
|
+
}
|
|
800891
|
+
}
|
|
800892
|
+
let handler = 'index.main';
|
|
800893
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'index.php'))) {
|
|
800894
|
+
handler = 'index.main';
|
|
800895
|
+
}
|
|
800896
|
+
return {
|
|
800897
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime: 'Php8.0', handler }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800898
|
+
source
|
|
800899
|
+
};
|
|
800900
|
+
}
|
|
800901
|
+
function inferJavaConfig(targetDir, name, httpFn) {
|
|
800902
|
+
const javaFiles = ['pom.xml', 'build.gradle', 'build.gradle.kts'];
|
|
800903
|
+
const foundFile = javaFiles.find(file => fs_1.default.existsSync(path_1.default.join(targetDir, file)));
|
|
800904
|
+
if (!foundFile) {
|
|
800905
|
+
return null;
|
|
800906
|
+
}
|
|
800907
|
+
let funcName = name || path_1.default.basename(targetDir);
|
|
800908
|
+
if (!name && foundFile === 'pom.xml') {
|
|
800909
|
+
const pomPath = path_1.default.join(targetDir, 'pom.xml');
|
|
800910
|
+
try {
|
|
800911
|
+
const pomContent = fs_1.default.readFileSync(pomPath, 'utf-8');
|
|
800912
|
+
const artifactIdMatch = pomContent.match(/<artifactId>([^<]+)<\/artifactId>/);
|
|
800913
|
+
if (artifactIdMatch) {
|
|
800914
|
+
funcName = artifactIdMatch[1];
|
|
800915
|
+
}
|
|
800916
|
+
}
|
|
800917
|
+
catch (e) {
|
|
800918
|
+
}
|
|
800919
|
+
}
|
|
800920
|
+
return {
|
|
800921
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime: 'Java11', handler: 'example.Hello::mainHandler' }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800922
|
+
source: (0, i18n_1.t)('Java 项目({{file}})', { file: foundFile })
|
|
800923
|
+
};
|
|
800924
|
+
}
|
|
800925
|
+
function inferGoConfig(targetDir, name, httpFn) {
|
|
800926
|
+
const goFiles = ['go.mod', 'go.sum'];
|
|
800927
|
+
const foundFile = goFiles.find(file => fs_1.default.existsSync(path_1.default.join(targetDir, file)));
|
|
800928
|
+
if (!foundFile) {
|
|
800929
|
+
return null;
|
|
800930
|
+
}
|
|
800931
|
+
let funcName = name || path_1.default.basename(targetDir);
|
|
800932
|
+
if (!name && fs_1.default.existsSync(path_1.default.join(targetDir, 'go.mod'))) {
|
|
800933
|
+
try {
|
|
800934
|
+
const goModContent = fs_1.default.readFileSync(path_1.default.join(targetDir, 'go.mod'), 'utf-8');
|
|
800935
|
+
const moduleMatch = goModContent.match(/^module\s+(.+)$/m);
|
|
800936
|
+
if (moduleMatch) {
|
|
800937
|
+
funcName = moduleMatch[1].split('/').pop() || funcName;
|
|
800938
|
+
}
|
|
800939
|
+
}
|
|
800940
|
+
catch (e) {
|
|
800941
|
+
}
|
|
800942
|
+
}
|
|
800943
|
+
return {
|
|
800944
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime: 'Go1', handler: 'main' }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800945
|
+
source: (0, i18n_1.t)('Go 项目({{file}})', { file: foundFile })
|
|
800946
|
+
};
|
|
800947
|
+
}
|
|
800948
|
+
function inferByFileExtension(targetDir, name, httpFn) {
|
|
800949
|
+
try {
|
|
800950
|
+
const files = fs_1.default.readdirSync(targetDir);
|
|
800951
|
+
const fileTypes = {
|
|
800952
|
+
js: files.filter(f => f.endsWith('.js')).length,
|
|
800953
|
+
ts: files.filter(f => f.endsWith('.ts')).length,
|
|
800954
|
+
py: files.filter(f => f.endsWith('.py')).length,
|
|
800955
|
+
php: files.filter(f => f.endsWith('.php')).length,
|
|
800956
|
+
java: files.filter(f => f.endsWith('.java')).length,
|
|
800957
|
+
go: files.filter(f => f.endsWith('.go')).length
|
|
800958
|
+
};
|
|
800959
|
+
const maxType = Object.entries(fileTypes).reduce((a, b) => (fileTypes[a[0]] || 0) > (fileTypes[b[0]] || 0) ? a : b);
|
|
800960
|
+
if (maxType[1] === 0) {
|
|
800961
|
+
return null;
|
|
800962
|
+
}
|
|
800963
|
+
const funcName = name || path_1.default.basename(targetDir);
|
|
800964
|
+
const typeConfigMap = {
|
|
800965
|
+
js: { runtime: 'Nodejs18.15', handler: 'index.main', source: (0, i18n_1.t)('JavaScript 文件推测') },
|
|
800966
|
+
ts: { runtime: 'Nodejs18.15', handler: 'index.main', source: (0, i18n_1.t)('TypeScript 文件推测') },
|
|
800967
|
+
py: { runtime: 'Python3.9', handler: 'index.main', source: (0, i18n_1.t)('Python 文件推测') },
|
|
800968
|
+
php: { runtime: 'Php8.0', handler: 'index.main', source: (0, i18n_1.t)('PHP 文件推测') },
|
|
800969
|
+
java: { runtime: 'Java11', handler: 'example.Hello::mainHandler', source: (0, i18n_1.t)('Java 文件推测') },
|
|
800970
|
+
go: { runtime: 'Go1', handler: 'main', source: (0, i18n_1.t)('Go 文件推测') }
|
|
800971
|
+
};
|
|
800972
|
+
const typeConfig = typeConfigMap[maxType[0]];
|
|
800973
|
+
if (!typeConfig) {
|
|
800974
|
+
return null;
|
|
800975
|
+
}
|
|
800976
|
+
return {
|
|
800977
|
+
config: Object.assign(Object.assign(Object.assign({ name: funcName }, constant_1.DefaultFunctionDeployConfig), { runtime: typeConfig.runtime, handler: typeConfig.handler }), (httpFn ? { type: 'HTTP' } : {})),
|
|
800978
|
+
source: typeConfig.source
|
|
800979
|
+
};
|
|
800980
|
+
}
|
|
800981
|
+
catch (e) {
|
|
800982
|
+
return null;
|
|
800983
|
+
}
|
|
800984
|
+
}
|
|
800985
|
+
function getConfigSourceDescription(targetDir) {
|
|
800986
|
+
const result = inferFunctionConfig({ targetDir, name: 'temp' });
|
|
800987
|
+
return (result === null || result === void 0 ? void 0 : result.source) || (0, i18n_1.t)('默认配置');
|
|
800988
|
+
}
|
|
800989
|
+
exports.getConfigSourceDescription = getConfigSourceDescription;
|
|
800449
800990
|
|
|
800450
800991
|
|
|
800451
800992
|
/***/ }),
|
|
@@ -834447,6 +834988,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834447
834988
|
{
|
|
834448
834989
|
flags: '--deployMode <deployMode>',
|
|
834449
834990
|
desc: (0, i18n_1.t)('代码上传方式:cos(通过 COS 上传)或 zip(直接 ZIP 上传),默认自动选择')
|
|
834991
|
+
},
|
|
834992
|
+
{
|
|
834993
|
+
flags: '--yes',
|
|
834994
|
+
desc: (0, i18n_1.t)('跳过交互确认,使用推测或默认配置自动部署')
|
|
834450
834995
|
}
|
|
834451
834996
|
],
|
|
834452
834997
|
desc: (0, i18n_1.t)('部署云函数'),
|
|
@@ -834458,7 +835003,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834458
835003
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834459
835004
|
let { envId, config, options } = ctx;
|
|
834460
835005
|
const { functions } = config;
|
|
834461
|
-
const { force, codeSecret, path: access, all, dir, httpFn, ws, deployMode } = options;
|
|
835006
|
+
const { force, codeSecret, path: access, all, dir, httpFn, ws, deployMode, yes } = options;
|
|
834462
835007
|
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
834463
835008
|
this.validateOptions({ deployMode, access }, log);
|
|
834464
835009
|
const isUnresolvedEnvId = !envId || envId.startsWith('{{');
|
|
@@ -834478,12 +835023,12 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834478
835023
|
if (hasConfig) {
|
|
834479
835024
|
return this.deployWithConfig({
|
|
834480
835025
|
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
834481
|
-
all, functions, functionRootPath, log
|
|
835026
|
+
all, functions, functionRootPath, yes, log
|
|
834482
835027
|
});
|
|
834483
835028
|
}
|
|
834484
835029
|
else {
|
|
834485
835030
|
return this.deployWithoutConfig({
|
|
834486
|
-
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, log
|
|
835031
|
+
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, yes, log
|
|
834487
835032
|
});
|
|
834488
835033
|
}
|
|
834489
835034
|
});
|
|
@@ -834502,11 +835047,11 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834502
835047
|
}
|
|
834503
835048
|
deployWithConfig(options) {
|
|
834504
835049
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834505
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, all, functions, functionRootPath, log } = options;
|
|
835050
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, all, functions, functionRootPath, yes, log } = options;
|
|
834506
835051
|
if (name) {
|
|
834507
835052
|
return this.deploySingleWithConfig({
|
|
834508
835053
|
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
834509
|
-
functions, functionRootPath, log
|
|
835054
|
+
functions, functionRootPath, yes, log
|
|
834510
835055
|
});
|
|
834511
835056
|
}
|
|
834512
835057
|
if (dir) {
|
|
@@ -834514,13 +835059,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834514
835059
|
}
|
|
834515
835060
|
return this.deployAllFunction({
|
|
834516
835061
|
all, envId, force, access, functions, codeSecret,
|
|
834517
|
-
functionRootPath, httpFn, ws, deployMode, log
|
|
835062
|
+
functionRootPath, httpFn, ws, deployMode, yes, log
|
|
834518
835063
|
});
|
|
834519
835064
|
});
|
|
834520
835065
|
}
|
|
834521
835066
|
deploySingleWithConfig(options) {
|
|
834522
835067
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834523
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, functions, functionRootPath, log } = options;
|
|
835068
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, functions, functionRootPath, yes, log } = options;
|
|
834524
835069
|
let func = functions === null || functions === void 0 ? void 0 : functions.find((item) => item.name === name);
|
|
834525
835070
|
let funcPath;
|
|
834526
835071
|
if (dir) {
|
|
@@ -834543,21 +835088,32 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834543
835088
|
}
|
|
834544
835089
|
if (!func) {
|
|
834545
835090
|
log.warn((0, i18n_1.t)('配置文件中未找到函数 [{{name}}] 的配置', { name }));
|
|
834546
|
-
|
|
834547
|
-
|
|
834548
|
-
|
|
834549
|
-
|
|
834550
|
-
|
|
834551
|
-
|
|
834552
|
-
|
|
834553
|
-
|
|
834554
|
-
|
|
834555
|
-
|
|
834556
|
-
|
|
834557
|
-
|
|
834558
|
-
|
|
835091
|
+
if (yes) {
|
|
835092
|
+
const inferredConfig = this.inferFunctionConfig(httpFn, funcPath);
|
|
835093
|
+
const runtime = (inferredConfig === null || inferredConfig === void 0 ? void 0 : inferredConfig.runtime) || (yield this.getDefaultRuntime(funcPath));
|
|
835094
|
+
const defaultFunc = Object.assign(Object.assign(Object.assign({ name }, constant_1.DefaultFunctionDeployConfig), { runtime }), (inferredConfig ? { handler: inferredConfig.handler } : {}));
|
|
835095
|
+
log.info((0, i18n_1.t)('🚀 --yes 模式:自动使用以下配置部署:'));
|
|
835096
|
+
const sourceDesc = inferredConfig ? this.getConfigSourceDescription(funcPath) : (0, i18n_1.t)('默认配置');
|
|
835097
|
+
this.printFunctionConfig(defaultFunc, log, sourceDesc);
|
|
835098
|
+
func = defaultFunc;
|
|
835099
|
+
}
|
|
835100
|
+
else {
|
|
835101
|
+
const runtime = yield this.selectRuntime();
|
|
835102
|
+
const defaultFunc = Object.assign(Object.assign({ name }, constant_1.DefaultFunctionDeployConfig), { runtime });
|
|
835103
|
+
log.info((0, i18n_1.t)('将使用以下默认配置:'));
|
|
835104
|
+
this.printFunctionConfig(defaultFunc, log, (0, i18n_1.t)('默认配置'));
|
|
835105
|
+
const { confirm } = yield inquirer_1.default.prompt({
|
|
835106
|
+
type: 'confirm',
|
|
835107
|
+
name: 'confirm',
|
|
835108
|
+
message: (0, i18n_1.t)('是否使用默认配置继续部署?'),
|
|
835109
|
+
default: false
|
|
835110
|
+
});
|
|
835111
|
+
if (!confirm) {
|
|
835112
|
+
log.info((0, i18n_1.t)('已取消部署,请在配置文件中添加函数 [{{name}}] 的配置后重试', { name }));
|
|
835113
|
+
return;
|
|
835114
|
+
}
|
|
835115
|
+
func = defaultFunc;
|
|
834559
835116
|
}
|
|
834560
|
-
func = defaultFunc;
|
|
834561
835117
|
}
|
|
834562
835118
|
if (httpFn) {
|
|
834563
835119
|
func = Object.assign(Object.assign({}, func), { type: 'HTTP' });
|
|
@@ -834567,13 +835123,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834567
835123
|
}
|
|
834568
835124
|
return this.doDeploySingleFunction({
|
|
834569
835125
|
func, envId, force, codeSecret, access, deployMode,
|
|
834570
|
-
functionRootPath, functionPath: funcPath, log
|
|
835126
|
+
functionRootPath, functionPath: funcPath, yes, log
|
|
834571
835127
|
});
|
|
834572
835128
|
});
|
|
834573
835129
|
}
|
|
834574
835130
|
deployWithoutConfig(options) {
|
|
834575
835131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834576
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, log } = options;
|
|
835132
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, yes, log } = options;
|
|
834577
835133
|
let deployDir = process.cwd();
|
|
834578
835134
|
if (dir) {
|
|
834579
835135
|
(0, utils_1.checkFullAccess)(dir, true);
|
|
@@ -834597,65 +835153,57 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834597
835153
|
if (ws && isInferred) {
|
|
834598
835154
|
inferredConfig = Object.assign(Object.assign({}, inferredConfig), { type: 'HTTP', protocolType: 'WS' });
|
|
834599
835155
|
}
|
|
835156
|
+
const sourceDesc = isInferred ? this.getConfigSourceDescription(deployDir) : (0, i18n_1.t)('默认配置');
|
|
834600
835157
|
if (isInferred) {
|
|
834601
|
-
log.info((0, i18n_1.t)('
|
|
835158
|
+
log.info((0, i18n_1.t)('✓ 从项目文件推测出以下配置:'));
|
|
834602
835159
|
}
|
|
834603
835160
|
else {
|
|
834604
|
-
log.info((0, i18n_1.t)('未推测出配置,将使用默认配置:'));
|
|
834605
|
-
}
|
|
834606
|
-
this.printFunctionConfig(inferredConfig, log);
|
|
834607
|
-
const { action } = yield inquirer_1.default.prompt({
|
|
834608
|
-
type: 'list',
|
|
834609
|
-
name: 'action',
|
|
834610
|
-
message: (0, i18n_1.t)('请选择操作'),
|
|
834611
|
-
choices: [
|
|
834612
|
-
{ name: (0, i18n_1.t)('使用当前配置部署'), value: 'deploy' },
|
|
834613
|
-
{ name: (0, i18n_1.t)('手动输入配置'), value: 'manual' },
|
|
834614
|
-
{ name: (0, i18n_1.t)('退出'), value: 'exit' }
|
|
834615
|
-
]
|
|
834616
|
-
});
|
|
834617
|
-
if (action === 'exit') {
|
|
834618
|
-
log.info((0, i18n_1.t)('已取消部署'));
|
|
834619
|
-
return;
|
|
835161
|
+
log.info((0, i18n_1.t)('⚠ 未推测出配置,将使用默认配置:'));
|
|
834620
835162
|
}
|
|
835163
|
+
this.printFunctionConfig(inferredConfig, log, sourceDesc);
|
|
834621
835164
|
let func;
|
|
834622
|
-
if (
|
|
834623
|
-
|
|
835165
|
+
if (yes) {
|
|
835166
|
+
log.info((0, i18n_1.t)('🚀 --yes 模式:跳过交互,自动部署'));
|
|
835167
|
+
func = inferredConfig;
|
|
834624
835168
|
}
|
|
834625
835169
|
else {
|
|
834626
|
-
|
|
835170
|
+
const { action } = yield inquirer_1.default.prompt({
|
|
835171
|
+
type: 'list',
|
|
835172
|
+
name: 'action',
|
|
835173
|
+
message: (0, i18n_1.t)('请选择操作'),
|
|
835174
|
+
choices: [
|
|
835175
|
+
{ name: (0, i18n_1.t)('使用当前配置部署'), value: 'deploy' },
|
|
835176
|
+
{ name: (0, i18n_1.t)('手动输入配置'), value: 'manual' },
|
|
835177
|
+
{ name: (0, i18n_1.t)('退出'), value: 'exit' }
|
|
835178
|
+
]
|
|
835179
|
+
});
|
|
835180
|
+
if (action === 'exit') {
|
|
835181
|
+
log.info((0, i18n_1.t)('已取消部署'));
|
|
835182
|
+
return;
|
|
835183
|
+
}
|
|
835184
|
+
if (action === 'manual') {
|
|
835185
|
+
func = yield this.promptFunctionConfig(inferredConfig, httpFn, ws);
|
|
835186
|
+
}
|
|
835187
|
+
else {
|
|
835188
|
+
func = inferredConfig;
|
|
835189
|
+
}
|
|
834627
835190
|
}
|
|
834628
835191
|
return this.doDeploySingleFunction({
|
|
834629
835192
|
func, envId, force, codeSecret, access, deployMode,
|
|
834630
|
-
functionRootPath: deployDir, functionPath: '.', log
|
|
835193
|
+
functionRootPath: deployDir, functionPath: '.', yes, log
|
|
834631
835194
|
});
|
|
834632
835195
|
});
|
|
834633
835196
|
}
|
|
834634
835197
|
inferFunctionConfig(httpFn, deployDir) {
|
|
834635
835198
|
const targetDir = deployDir || process.cwd();
|
|
834636
|
-
const
|
|
834637
|
-
|
|
834638
|
-
return null;
|
|
834639
|
-
}
|
|
834640
|
-
try {
|
|
834641
|
-
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
834642
|
-
if (!packageJson.name) {
|
|
834643
|
-
return null;
|
|
834644
|
-
}
|
|
834645
|
-
let handler = constant_1.DefaultFunctionDeployConfig.handler;
|
|
834646
|
-
if (packageJson.main) {
|
|
834647
|
-
const mainFile = path_1.default.basename(packageJson.main).replace(/\.[^.]+$/, '');
|
|
834648
|
-
handler = `${mainFile}.main`;
|
|
834649
|
-
}
|
|
834650
|
-
return Object.assign(Object.assign(Object.assign({ name: packageJson.name }, constant_1.DefaultFunctionDeployConfig), { handler }), (httpFn ? { type: 'HTTP' } : {}));
|
|
834651
|
-
}
|
|
834652
|
-
catch (e) {
|
|
834653
|
-
return null;
|
|
834654
|
-
}
|
|
835199
|
+
const result = (0, function_1.inferFunctionConfig)({ targetDir, httpFn });
|
|
835200
|
+
return (result === null || result === void 0 ? void 0 : result.config) || null;
|
|
834655
835201
|
}
|
|
834656
|
-
promptFunctionConfig(defaultConfig, httpFn) {
|
|
835202
|
+
promptFunctionConfig(defaultConfig, httpFn, ws) {
|
|
834657
835203
|
var _a, _b, _c;
|
|
834658
835204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835205
|
+
const isHttpFnFromCli = httpFn || ws;
|
|
835206
|
+
const isWsFromCli = ws;
|
|
834659
835207
|
const answers = yield inquirer_1.default.prompt([
|
|
834660
835208
|
{
|
|
834661
835209
|
type: 'input',
|
|
@@ -834684,62 +835232,49 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834684
835232
|
name: 'handler',
|
|
834685
835233
|
message: (0, i18n_1.t)('入口函数(格式:文件名.函数名)'),
|
|
834686
835234
|
default: (answers) => {
|
|
835235
|
+
if (defaultConfig.handler) {
|
|
835236
|
+
return defaultConfig.handler;
|
|
835237
|
+
}
|
|
834687
835238
|
const selectedRuntime = constant_1.RuntimeOptions.find(r => r.value === answers.runtime);
|
|
834688
|
-
return (selectedRuntime === null || selectedRuntime === void 0 ? void 0 : selectedRuntime.handler) ||
|
|
835239
|
+
return (selectedRuntime === null || selectedRuntime === void 0 ? void 0 : selectedRuntime.handler) || constant_1.DefaultFunctionDeployConfig.handler;
|
|
834689
835240
|
}
|
|
834690
835241
|
},
|
|
834691
835242
|
{
|
|
834692
835243
|
type: 'confirm',
|
|
834693
835244
|
name: 'isHttpFn',
|
|
834694
835245
|
message: (0, i18n_1.t)('是否为 HTTP 函数'),
|
|
834695
|
-
default:
|
|
834696
|
-
when: !
|
|
835246
|
+
default: isHttpFnFromCli || defaultConfig.type === 'HTTP',
|
|
835247
|
+
when: !isHttpFnFromCli
|
|
834697
835248
|
},
|
|
834698
835249
|
{
|
|
834699
835250
|
type: 'confirm',
|
|
834700
835251
|
name: 'enableWebSocket',
|
|
834701
835252
|
message: (0, i18n_1.t)('是否支持 WebSocket 协议'),
|
|
834702
|
-
default: defaultConfig.protocolType === 'WS',
|
|
834703
|
-
when: (answers) =>
|
|
835253
|
+
default: isWsFromCli || defaultConfig.protocolType === 'WS',
|
|
835254
|
+
when: (answers) => !isWsFromCli && (isHttpFnFromCli || answers.isHttpFn)
|
|
834704
835255
|
},
|
|
834705
835256
|
{
|
|
834706
835257
|
type: 'number',
|
|
834707
835258
|
name: 'timeout',
|
|
834708
835259
|
message: (answers) => {
|
|
834709
|
-
const isWs = answers.enableWebSocket;
|
|
835260
|
+
const isWs = isWsFromCli || answers.enableWebSocket;
|
|
834710
835261
|
return isWs ? (0, i18n_1.t)('超时时间(秒,1-7200)') : (0, i18n_1.t)('超时时间(秒,1-900)');
|
|
834711
835262
|
},
|
|
834712
835263
|
default: defaultConfig.timeout,
|
|
834713
|
-
validate: (input, answers) => {
|
|
834714
|
-
const num = Number(input);
|
|
834715
|
-
const isWs = answers.enableWebSocket;
|
|
834716
|
-
const maxTimeout = isWs ? 7200 : 900;
|
|
834717
|
-
if (isNaN(num) || num < 1 || num > maxTimeout) {
|
|
834718
|
-
return isWs ? (0, i18n_1.t)('超时时间必须在 1-7200 秒之间') : (0, i18n_1.t)('超时时间必须在 1-900 秒之间');
|
|
834719
|
-
}
|
|
834720
|
-
return true;
|
|
834721
|
-
}
|
|
834722
835264
|
},
|
|
834723
835265
|
{
|
|
834724
835266
|
type: 'number',
|
|
834725
835267
|
name: 'idleTimeOut',
|
|
834726
835268
|
message: (0, i18n_1.t)('空闲超时时间(秒,10-7200,默认15)'),
|
|
834727
835269
|
default: ((_b = (_a = defaultConfig.protocolParams) === null || _a === void 0 ? void 0 : _a.wsParams) === null || _b === void 0 ? void 0 : _b.idleTimeOut) || 15,
|
|
834728
|
-
when: (answers) => answers.enableWebSocket,
|
|
834729
|
-
validate: (input) => {
|
|
834730
|
-
const num = Number(input);
|
|
834731
|
-
if (isNaN(num) || num < 10 || num > 7200) {
|
|
834732
|
-
return (0, i18n_1.t)('空闲超时时间必须在 10-7200 秒之间');
|
|
834733
|
-
}
|
|
834734
|
-
return true;
|
|
834735
|
-
}
|
|
835270
|
+
when: (answers) => isWsFromCli || answers.enableWebSocket,
|
|
834736
835271
|
},
|
|
834737
835272
|
{
|
|
834738
835273
|
type: 'confirm',
|
|
834739
835274
|
name: 'enableInstanceConcurrency',
|
|
834740
835275
|
message: (0, i18n_1.t)('是否启用多并发'),
|
|
834741
835276
|
default: !!defaultConfig.instanceConcurrencyConfig,
|
|
834742
|
-
when: (answers) =>
|
|
835277
|
+
when: (answers) => isHttpFnFromCli || answers.isHttpFn
|
|
834743
835278
|
},
|
|
834744
835279
|
{
|
|
834745
835280
|
type: 'number',
|
|
@@ -834775,15 +835310,16 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834775
835310
|
default: defaultConfig.installDependency
|
|
834776
835311
|
}
|
|
834777
835312
|
]);
|
|
834778
|
-
const
|
|
834779
|
-
const
|
|
835313
|
+
const enableWs = isWsFromCli || answers.enableWebSocket;
|
|
835314
|
+
const protocolType = enableWs ? 'WS' : undefined;
|
|
835315
|
+
const protocolParams = (enableWs && answers.idleTimeOut) ? {
|
|
834780
835316
|
wsParams: { idleTimeOut: answers.idleTimeOut }
|
|
834781
835317
|
} : undefined;
|
|
834782
835318
|
const instanceConcurrencyConfig = answers.enableInstanceConcurrency ? {
|
|
834783
835319
|
dynamicEnabled: 'FALSE',
|
|
834784
835320
|
maxConcurrency: answers.maxConcurrency
|
|
834785
835321
|
} : undefined;
|
|
834786
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({ name: answers.name.trim(), runtime: answers.runtime, handler: answers.handler, timeout: answers.timeout, memorySize: answers.memorySize, installDependency: answers.installDependency, ignore: defaultConfig.ignore || constant_1.DefaultFunctionDeployConfig.ignore }, (
|
|
835322
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ name: answers.name.trim(), runtime: answers.runtime, handler: answers.handler, timeout: answers.timeout, memorySize: answers.memorySize, installDependency: answers.installDependency, ignore: defaultConfig.ignore || constant_1.DefaultFunctionDeployConfig.ignore }, (isHttpFnFromCli || answers.isHttpFn ? { type: 'HTTP' } : {})), (protocolType ? { protocolType } : {})), (protocolParams ? { protocolParams } : {})), (instanceConcurrencyConfig ? { instanceConcurrencyConfig } : {}));
|
|
834787
835323
|
});
|
|
834788
835324
|
}
|
|
834789
835325
|
promptFunctionName() {
|
|
@@ -834802,8 +835338,11 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834802
835338
|
return funcName.trim();
|
|
834803
835339
|
});
|
|
834804
835340
|
}
|
|
834805
|
-
printFunctionConfig(func, log) {
|
|
835341
|
+
printFunctionConfig(func, log, source) {
|
|
834806
835342
|
var _a, _b;
|
|
835343
|
+
if (source) {
|
|
835344
|
+
log.info((0, i18n_1.t)('配置来源:{{source}}', { source }));
|
|
835345
|
+
}
|
|
834807
835346
|
log.info((0, i18n_1.t)(' - 函数名称:{{name}}', { name: func.name }));
|
|
834808
835347
|
log.info((0, i18n_1.t)(' - 运行时:{{runtime}}', { runtime: func.runtime }));
|
|
834809
835348
|
log.info((0, i18n_1.t)(' - 入口函数:{{handler}}', { handler: func.handler }));
|
|
@@ -834826,10 +835365,65 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834826
835365
|
log.info((0, i18n_1.t)(' - 单实例最大并发数:{{num}}', { num: func.instanceConcurrencyConfig.maxConcurrency }));
|
|
834827
835366
|
}
|
|
834828
835367
|
}
|
|
835368
|
+
else {
|
|
835369
|
+
log.info((0, i18n_1.t)(' - 函数类型:Event(事件触发)'));
|
|
835370
|
+
}
|
|
835371
|
+
if (func.envVariables && Object.keys(func.envVariables).length > 0) {
|
|
835372
|
+
log.info((0, i18n_1.t)(' - 环境变量:{{count}} 个', { count: Object.keys(func.envVariables).length }));
|
|
835373
|
+
}
|
|
835374
|
+
if (func.vpc) {
|
|
835375
|
+
log.info((0, i18n_1.t)(' - VPC 配置:已配置'));
|
|
835376
|
+
}
|
|
835377
|
+
}
|
|
835378
|
+
getConfigSourceDescription(targetDir) {
|
|
835379
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'package.json'))) {
|
|
835380
|
+
return (0, i18n_1.t)('Node.js 项目(package.json)');
|
|
835381
|
+
}
|
|
835382
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'requirements.txt'))) {
|
|
835383
|
+
return (0, i18n_1.t)('Python 项目(requirements.txt)');
|
|
835384
|
+
}
|
|
835385
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'setup.py'))) {
|
|
835386
|
+
return (0, i18n_1.t)('Python 项目(setup.py)');
|
|
835387
|
+
}
|
|
835388
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'pyproject.toml'))) {
|
|
835389
|
+
return (0, i18n_1.t)('Python 项目(pyproject.toml)');
|
|
835390
|
+
}
|
|
835391
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'composer.json'))) {
|
|
835392
|
+
return (0, i18n_1.t)('PHP 项目(composer.json)');
|
|
835393
|
+
}
|
|
835394
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'pom.xml'))) {
|
|
835395
|
+
return (0, i18n_1.t)('Java 项目(pom.xml)');
|
|
835396
|
+
}
|
|
835397
|
+
if (fs_1.default.existsSync(path_1.default.join(targetDir, 'build.gradle'))) {
|
|
835398
|
+
return (0, i18n_1.t)('Java 项目(build.gradle)');
|
|
835399
|
+
}
|
|
835400
|
+
try {
|
|
835401
|
+
const files = fs_1.default.readdirSync(targetDir);
|
|
835402
|
+
const fileTypes = {
|
|
835403
|
+
js: files.filter(f => f.endsWith('.js')).length,
|
|
835404
|
+
ts: files.filter(f => f.endsWith('.ts')).length,
|
|
835405
|
+
py: files.filter(f => f.endsWith('.py')).length,
|
|
835406
|
+
php: files.filter(f => f.endsWith('.php')).length,
|
|
835407
|
+
java: files.filter(f => f.endsWith('.java')).length
|
|
835408
|
+
};
|
|
835409
|
+
const maxType = Object.entries(fileTypes).reduce((a, b) => fileTypes[a[0]] > fileTypes[b[0]] ? a : b);
|
|
835410
|
+
if (maxType[1] > 0) {
|
|
835411
|
+
switch (maxType[0]) {
|
|
835412
|
+
case 'js': return (0, i18n_1.t)('JavaScript 文件推测');
|
|
835413
|
+
case 'ts': return (0, i18n_1.t)('TypeScript 文件推测');
|
|
835414
|
+
case 'py': return (0, i18n_1.t)('Python 文件推测');
|
|
835415
|
+
case 'php': return (0, i18n_1.t)('PHP 文件推测');
|
|
835416
|
+
case 'java': return (0, i18n_1.t)('Java 文件推测');
|
|
835417
|
+
}
|
|
835418
|
+
}
|
|
835419
|
+
}
|
|
835420
|
+
catch (e) {
|
|
835421
|
+
}
|
|
835422
|
+
return (0, i18n_1.t)('默认配置');
|
|
834829
835423
|
}
|
|
834830
835424
|
doDeploySingleFunction(options) {
|
|
834831
835425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834832
|
-
const { func, envId, force, codeSecret, access, deployMode, functionRootPath, functionPath, log } = options;
|
|
835426
|
+
const { func, envId, force, codeSecret, access, deployMode, functionRootPath, functionPath, yes, log } = options;
|
|
834833
835427
|
if (func.type === 'HTTP') {
|
|
834834
835428
|
const funcPath = functionPath === '.' ? process.cwd() : (functionPath || path_1.default.join(functionRootPath, func.name));
|
|
834835
835429
|
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(funcPath, func);
|
|
@@ -834863,6 +835457,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834863
835457
|
func,
|
|
834864
835458
|
accessPath: access,
|
|
834865
835459
|
functionPath,
|
|
835460
|
+
yes,
|
|
834866
835461
|
logger: log
|
|
834867
835462
|
});
|
|
834868
835463
|
}
|
|
@@ -834874,7 +835469,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834874
835469
|
}
|
|
834875
835470
|
deployAllFunction(options) {
|
|
834876
835471
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834877
|
-
let { functions = [], envId, force, codeSecret, functionRootPath, all, access, httpFn, ws, deployMode, log } = options;
|
|
835472
|
+
let { functions = [], envId, force, codeSecret, functionRootPath, all, access, httpFn, ws, deployMode, yes, log } = options;
|
|
834878
835473
|
if (!functions || functions.length === 0) {
|
|
834879
835474
|
functions = this.scanFunctionDirectory(functionRootPath, httpFn);
|
|
834880
835475
|
if (functions.length > 0) {
|
|
@@ -834891,7 +835486,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834891
835486
|
throw new error_1.CloudBaseError((0, i18n_1.t)('未找到云函数配置,请在 cloudbaserc.json 中配置 functions 字段,或使用 tcb fn deploy <函数名> 指定要部署的函数'));
|
|
834892
835487
|
}
|
|
834893
835488
|
let selectedFunctions = functions;
|
|
834894
|
-
if (!all) {
|
|
835489
|
+
if (!all && !yes) {
|
|
834895
835490
|
const choices = functions.map((func) => ({
|
|
834896
835491
|
name: `${func.name}${func.type === 'HTTP' ? ' (HTTP)' : ''}${func.protocolType === 'WS' ? ' (WS)' : ''}`,
|
|
834897
835492
|
value: func.name,
|
|
@@ -834924,7 +835519,54 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834924
835519
|
throw new error_1.CloudBaseError((0, i18n_1.t)('没有选择任何云函数'));
|
|
834925
835520
|
}
|
|
834926
835521
|
}
|
|
835522
|
+
else if (yes) {
|
|
835523
|
+
log.info((0, i18n_1.t)('🚀 --yes 模式:自动部署全部 {{count}} 个函数', { count: functions.length }));
|
|
835524
|
+
}
|
|
834927
835525
|
const loading = (0, utils_1.loadingFactory)();
|
|
835526
|
+
let functionsToOverwrite = new Set();
|
|
835527
|
+
if (!force && !yes) {
|
|
835528
|
+
loading.start((0, i18n_1.t)('正在检查云函数状态...'));
|
|
835529
|
+
const functionService = yield (0, function_2.getFunctionService)(envId);
|
|
835530
|
+
const existingFunctions = [];
|
|
835531
|
+
const checkTasks = selectedFunctions.map((func) => __awaiter(this, void 0, void 0, function* () {
|
|
835532
|
+
try {
|
|
835533
|
+
const detail = yield functionService.getFunctionDetail(func.name, codeSecret);
|
|
835534
|
+
if (detail) {
|
|
835535
|
+
return func.name;
|
|
835536
|
+
}
|
|
835537
|
+
}
|
|
835538
|
+
catch (e) {
|
|
835539
|
+
}
|
|
835540
|
+
return null;
|
|
835541
|
+
}));
|
|
835542
|
+
const checkResults = yield Promise.all(checkTasks);
|
|
835543
|
+
checkResults.forEach(name => {
|
|
835544
|
+
if (name)
|
|
835545
|
+
existingFunctions.push(name);
|
|
835546
|
+
});
|
|
835547
|
+
loading.stop();
|
|
835548
|
+
if (existingFunctions.length > 0) {
|
|
835549
|
+
log.info((0, i18n_1.t)('发现 {{count}} 个已存在的云函数:', { count: existingFunctions.length }));
|
|
835550
|
+
existingFunctions.forEach(name => {
|
|
835551
|
+
log.info(` - ${name}`);
|
|
835552
|
+
});
|
|
835553
|
+
const { toOverwrite } = yield inquirer_1.default.prompt({
|
|
835554
|
+
type: 'checkbox',
|
|
835555
|
+
name: 'toOverwrite',
|
|
835556
|
+
message: (0, i18n_1.t)('请选择要覆盖更新的函数(未选中的将跳过部署)'),
|
|
835557
|
+
choices: existingFunctions.map(name => ({
|
|
835558
|
+
name,
|
|
835559
|
+
value: name,
|
|
835560
|
+
checked: true
|
|
835561
|
+
}))
|
|
835562
|
+
});
|
|
835563
|
+
functionsToOverwrite = new Set(toOverwrite);
|
|
835564
|
+
const skippedByUser = existingFunctions.filter(name => !functionsToOverwrite.has(name));
|
|
835565
|
+
if (skippedByUser.length > 0) {
|
|
835566
|
+
log.info((0, i18n_1.t)('以下函数将跳过部署:{{names}}', { names: skippedByUser.join(', ') }));
|
|
835567
|
+
}
|
|
835568
|
+
}
|
|
835569
|
+
}
|
|
834928
835570
|
const tasks = selectedFunctions.map((func) => () => __awaiter(this, void 0, void 0, function* () {
|
|
834929
835571
|
let funcWithType = httpFn ? Object.assign(Object.assign({}, func), { type: 'HTTP' }) : func;
|
|
834930
835572
|
if (ws) {
|
|
@@ -834935,13 +835577,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834935
835577
|
: path_1.default.join(functionRootPath, func.name);
|
|
834936
835578
|
if (!fs_1.default.existsSync(funcPath)) {
|
|
834937
835579
|
log.error((0, i18n_1.t)('未找到函数 [{{name}}] 的目录:{{path}},已跳过', { name: func.name, path: funcPath }));
|
|
834938
|
-
return;
|
|
835580
|
+
return { status: 'skipped', name: func.name };
|
|
834939
835581
|
}
|
|
834940
835582
|
if (funcWithType.type === 'HTTP') {
|
|
834941
835583
|
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(funcPath, funcWithType);
|
|
834942
835584
|
if (!shouldContinue) {
|
|
834943
835585
|
log.warn((0, i18n_1.t)('[{{name}}] 已跳过部署', { name: func.name }));
|
|
834944
|
-
return;
|
|
835586
|
+
return { status: 'skipped', name: func.name };
|
|
834945
835587
|
}
|
|
834946
835588
|
}
|
|
834947
835589
|
loading.start((0, i18n_1.t)('云函数部署中'));
|
|
@@ -834957,19 +835599,28 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834957
835599
|
deployMode
|
|
834958
835600
|
});
|
|
834959
835601
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功', { name: func.name }));
|
|
835602
|
+
return { status: 'success', name: func.name };
|
|
834960
835603
|
}
|
|
834961
835604
|
catch (e) {
|
|
834962
835605
|
loading.stop();
|
|
834963
|
-
|
|
834964
|
-
|
|
834965
|
-
|
|
834966
|
-
|
|
834967
|
-
|
|
834968
|
-
|
|
834969
|
-
|
|
834970
|
-
|
|
834971
|
-
|
|
834972
|
-
|
|
835606
|
+
try {
|
|
835607
|
+
const result = yield this.handleDeployFail(e, {
|
|
835608
|
+
func: funcWithType,
|
|
835609
|
+
envId,
|
|
835610
|
+
force,
|
|
835611
|
+
codeSecret,
|
|
835612
|
+
functionRootPath,
|
|
835613
|
+
functionPath: func.dir ? funcPath : undefined,
|
|
835614
|
+
accessPath: access,
|
|
835615
|
+
yes: yes || functionsToOverwrite.has(func.name),
|
|
835616
|
+
batchMode: true,
|
|
835617
|
+
logger: log
|
|
835618
|
+
});
|
|
835619
|
+
return { status: result || 'error', name: func.name };
|
|
835620
|
+
}
|
|
835621
|
+
catch (handleError) {
|
|
835622
|
+
return { status: 'error', name: func.name, error: handleError };
|
|
835623
|
+
}
|
|
834973
835624
|
}
|
|
834974
835625
|
}));
|
|
834975
835626
|
if (tasks.length > 5) {
|
|
@@ -834977,26 +835628,58 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834977
835628
|
}
|
|
834978
835629
|
const asyncTaskController = new utils_1.AsyncTaskParallelController(5, 50);
|
|
834979
835630
|
asyncTaskController.loadTasks(tasks);
|
|
834980
|
-
const
|
|
834981
|
-
const
|
|
834982
|
-
|
|
834983
|
-
|
|
834984
|
-
|
|
834985
|
-
|
|
834986
|
-
|
|
834987
|
-
|
|
834988
|
-
|
|
835631
|
+
const rawResults = yield asyncTaskController.run();
|
|
835632
|
+
const results = rawResults.map((r, index) => {
|
|
835633
|
+
var _a;
|
|
835634
|
+
if (r instanceof Error) {
|
|
835635
|
+
return { status: 'error', name: ((_a = selectedFunctions[index]) === null || _a === void 0 ? void 0 : _a.name) || 'unknown', error: r };
|
|
835636
|
+
}
|
|
835637
|
+
return r;
|
|
835638
|
+
});
|
|
835639
|
+
const successCount = results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'success').length;
|
|
835640
|
+
const skippedCount = results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'skipped').length;
|
|
835641
|
+
const cancelledCount = results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'cancelled').length;
|
|
835642
|
+
const errorCount = results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'error').length;
|
|
835643
|
+
if (successCount > 0) {
|
|
835644
|
+
log.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: successCount }));
|
|
835645
|
+
}
|
|
835646
|
+
if (skippedCount > 0) {
|
|
835647
|
+
log.warn((0, i18n_1.t)('跳过 {{count}} 个函数', { count: skippedCount }));
|
|
835648
|
+
}
|
|
835649
|
+
if (cancelledCount > 0) {
|
|
835650
|
+
log.info((0, i18n_1.t)('取消部署 {{count}} 个函数', { count: cancelledCount }));
|
|
835651
|
+
}
|
|
835652
|
+
if (errorCount > 0) {
|
|
835653
|
+
log.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: errorCount }));
|
|
835654
|
+
let envNotFoundError = null;
|
|
835655
|
+
results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'error').forEach((r) => {
|
|
835656
|
+
var _a;
|
|
835657
|
+
if ((_a = r === null || r === void 0 ? void 0 : r.error) === null || _a === void 0 ? void 0 : _a.message) {
|
|
835658
|
+
log.error(` - [${r.name}] ${r.error.message}`);
|
|
835659
|
+
if (r.error.message.includes('Environment') && r.error.message.includes('not found') && !envNotFoundError) {
|
|
835660
|
+
envNotFoundError = r.error;
|
|
835661
|
+
}
|
|
834989
835662
|
}
|
|
834990
835663
|
});
|
|
835664
|
+
if (envNotFoundError) {
|
|
835665
|
+
throw envNotFoundError;
|
|
835666
|
+
}
|
|
835667
|
+
}
|
|
835668
|
+
if (successCount === 0 && errorCount === 0 && skippedCount === 0 && cancelledCount === 0) {
|
|
835669
|
+
log.info((0, i18n_1.t)('没有函数被部署'));
|
|
834991
835670
|
}
|
|
834992
835671
|
});
|
|
834993
835672
|
}
|
|
834994
835673
|
handleDeployFail(e, options) {
|
|
834995
835674
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834996
|
-
const { envId, codeSecret, functionRootPath, func: originalFunc, functionPath, accessPath, force: forceOverwrite, logger: log } = options;
|
|
835675
|
+
const { envId, codeSecret, functionRootPath, func: originalFunc, functionPath, accessPath, force: forceOverwrite, yes, batchMode, logger: log } = options;
|
|
834997
835676
|
let func = originalFunc;
|
|
834998
835677
|
const loading = (0, utils_1.loadingFactory)();
|
|
834999
|
-
|
|
835678
|
+
const isResourceInUseError = e.code === 'ResourceInUse.FunctionName'
|
|
835679
|
+
|| e.code === 'ResourceInUse.Function'
|
|
835680
|
+
|| (e.message && e.message.includes('ResourceInUse.FunctionName'))
|
|
835681
|
+
|| (e.message && e.message.includes('ResourceInUse.Function'));
|
|
835682
|
+
if (isResourceInUseError) {
|
|
835000
835683
|
const functionService = yield (0, function_2.getFunctionService)(envId);
|
|
835001
835684
|
const existingFunction = yield functionService.getFunctionDetail(func.name, codeSecret);
|
|
835002
835685
|
const existingType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.Type) || 'Event';
|
|
@@ -835007,7 +835690,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835007
835690
|
existingType,
|
|
835008
835691
|
newType
|
|
835009
835692
|
}));
|
|
835010
|
-
return;
|
|
835693
|
+
return 'error';
|
|
835011
835694
|
}
|
|
835012
835695
|
const existingProtocolType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.ProtocolType) || '';
|
|
835013
835696
|
const newProtocolType = func.protocolType !== undefined ? func.protocolType : existingProtocolType;
|
|
@@ -835017,10 +835700,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835017
835700
|
existingProtocolType: existingProtocolType || '无',
|
|
835018
835701
|
newProtocolType: newProtocolType || '无'
|
|
835019
835702
|
}));
|
|
835020
|
-
return;
|
|
835703
|
+
return 'error';
|
|
835021
835704
|
}
|
|
835022
835705
|
func = Object.assign(Object.assign({}, func), { type: newType, protocolType: newProtocolType || undefined });
|
|
835023
|
-
let shouldForce = forceOverwrite;
|
|
835706
|
+
let shouldForce = forceOverwrite || yes;
|
|
835024
835707
|
if (!shouldForce) {
|
|
835025
835708
|
const answer = yield inquirer_1.default.prompt({
|
|
835026
835709
|
type: 'confirm',
|
|
@@ -835030,9 +835713,8 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835030
835713
|
});
|
|
835031
835714
|
shouldForce = answer.force;
|
|
835032
835715
|
}
|
|
835033
|
-
const { triggers } = func;
|
|
835034
835716
|
if (shouldForce) {
|
|
835035
|
-
loading.start((0, i18n_1.t)('云函数更新部署中...'));
|
|
835717
|
+
loading.start(batchMode ? (0, i18n_1.t)('云函数 [{{name}}] 更新部署中...', { name: func.name }) : (0, i18n_1.t)('云函数更新部署中...'));
|
|
835036
835718
|
try {
|
|
835037
835719
|
yield (0, function_2.updateFunctionCode)({
|
|
835038
835720
|
func,
|
|
@@ -835043,7 +835725,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835043
835725
|
});
|
|
835044
835726
|
const success = yield this.waitForFunctionReady(envId, func.name, loading);
|
|
835045
835727
|
if (!success) {
|
|
835046
|
-
return;
|
|
835728
|
+
return 'error';
|
|
835047
835729
|
}
|
|
835048
835730
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
|
|
835049
835731
|
yield (0, function_2.updateFunctionConfig)({
|
|
@@ -835052,7 +835734,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835052
835734
|
config: func
|
|
835053
835735
|
});
|
|
835054
835736
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
|
|
835055
|
-
|
|
835737
|
+
if (!batchMode) {
|
|
835738
|
+
yield this.printSuccessTips(envId);
|
|
835739
|
+
}
|
|
835740
|
+
return 'success';
|
|
835056
835741
|
}
|
|
835057
835742
|
catch (e) {
|
|
835058
835743
|
loading.stop();
|
|
@@ -835060,9 +835745,9 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835060
835745
|
}
|
|
835061
835746
|
}
|
|
835062
835747
|
else {
|
|
835063
|
-
(log || utils_1.logger).info((0, i18n_1.t)('已取消部署'));
|
|
835748
|
+
(log || utils_1.logger).info(batchMode ? (0, i18n_1.t)('[{{name}}] 已跳过部署', { name: func.name }) : (0, i18n_1.t)('已取消部署'));
|
|
835749
|
+
return 'cancelled';
|
|
835064
835750
|
}
|
|
835065
|
-
return;
|
|
835066
835751
|
}
|
|
835067
835752
|
throw e;
|
|
835068
835753
|
});
|
|
@@ -835180,6 +835865,59 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835180
835865
|
return runtime;
|
|
835181
835866
|
});
|
|
835182
835867
|
}
|
|
835868
|
+
getDefaultRuntime(targetDir) {
|
|
835869
|
+
var _a;
|
|
835870
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
835871
|
+
const dir = targetDir || process.cwd();
|
|
835872
|
+
if (fs_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
|
|
835873
|
+
try {
|
|
835874
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dir, 'package.json'), 'utf-8'));
|
|
835875
|
+
if ((_a = packageJson.engines) === null || _a === void 0 ? void 0 : _a.node) {
|
|
835876
|
+
const nodeVersion = packageJson.engines.node;
|
|
835877
|
+
if (nodeVersion.includes('20'))
|
|
835878
|
+
return 'Nodejs20.19';
|
|
835879
|
+
if (nodeVersion.includes('16'))
|
|
835880
|
+
return 'Nodejs16.13';
|
|
835881
|
+
}
|
|
835882
|
+
}
|
|
835883
|
+
catch (e) {
|
|
835884
|
+
}
|
|
835885
|
+
return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835886
|
+
}
|
|
835887
|
+
const pythonFiles = ['requirements.txt', 'setup.py', 'pyproject.toml'];
|
|
835888
|
+
if (pythonFiles.some(file => fs_1.default.existsSync(path_1.default.join(dir, file)))) {
|
|
835889
|
+
return 'Python3.9';
|
|
835890
|
+
}
|
|
835891
|
+
if (fs_1.default.existsSync(path_1.default.join(dir, 'composer.json')) ||
|
|
835892
|
+
fs_1.default.readdirSync(dir).some(file => file.endsWith('.php'))) {
|
|
835893
|
+
return 'Php8.0';
|
|
835894
|
+
}
|
|
835895
|
+
const javaFiles = ['pom.xml', 'build.gradle', 'build.gradle.kts'];
|
|
835896
|
+
if (javaFiles.some(file => fs_1.default.existsSync(path_1.default.join(dir, file)))) {
|
|
835897
|
+
return 'Java11';
|
|
835898
|
+
}
|
|
835899
|
+
try {
|
|
835900
|
+
const files = fs_1.default.readdirSync(dir);
|
|
835901
|
+
const fileTypes = {
|
|
835902
|
+
js: files.filter(f => f.endsWith('.js')).length,
|
|
835903
|
+
ts: files.filter(f => f.endsWith('.ts')).length,
|
|
835904
|
+
py: files.filter(f => f.endsWith('.py')).length,
|
|
835905
|
+
php: files.filter(f => f.endsWith('.php')).length,
|
|
835906
|
+
java: files.filter(f => f.endsWith('.java')).length
|
|
835907
|
+
};
|
|
835908
|
+
const maxType = Object.entries(fileTypes).reduce((a, b) => fileTypes[a[0]] > fileTypes[b[0]] ? a : b);
|
|
835909
|
+
switch (maxType[0]) {
|
|
835910
|
+
case 'py': return 'Python3.9';
|
|
835911
|
+
case 'php': return 'Php8.0';
|
|
835912
|
+
case 'java': return 'Java11';
|
|
835913
|
+
default: return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835914
|
+
}
|
|
835915
|
+
}
|
|
835916
|
+
catch (e) {
|
|
835917
|
+
return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835918
|
+
}
|
|
835919
|
+
});
|
|
835920
|
+
}
|
|
835183
835921
|
};
|
|
835184
835922
|
__decorate([
|
|
835185
835923
|
(0, decorators_1.InjectParams)(),
|