@cloudbase/cli 2.12.3-beta.0 → 2.12.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/standalone/cli.js +624 -964
- package/package.json +1 -1
package/dist/standalone/cli.js
CHANGED
|
@@ -295574,11 +295574,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
295574
295574
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
295575
295575
|
exports.getPort = void 0;
|
|
295576
295576
|
const portfinder_1 = __importDefault(__webpack_require__(31323));
|
|
295577
|
-
|
|
295577
|
+
// 默认端口
|
|
295578
|
+
const LOCAL_DEFAULT_PORT = 9012;
|
|
295579
|
+
const REMOTE_DEFAULT_PORT = 19012;
|
|
295580
|
+
function isRemoteEnvironment() {
|
|
295581
|
+
return Boolean(process.env.SSH_CONNECTION
|
|
295582
|
+
|| process.env.SSH_CLIENT
|
|
295583
|
+
|| process.env.SSH_TTY
|
|
295584
|
+
|| process.env.VSCODE_IPC_HOOK_CLI
|
|
295585
|
+
|| process.env.VSCODE_AGENT_FOLDER
|
|
295586
|
+
|| process.env.REMOTE_CONTAINERS
|
|
295587
|
+
|| process.env.CODESPACES
|
|
295588
|
+
|| process.env.GITPOD_WORKSPACE_ID);
|
|
295589
|
+
}
|
|
295590
|
+
function getStartPort() {
|
|
295591
|
+
const customStartPort = Number(process.env.TCB_WEB_LOGIN_START_PORT);
|
|
295592
|
+
if (Number.isInteger(customStartPort) && customStartPort > 0 && customStartPort < 65535) {
|
|
295593
|
+
return customStartPort;
|
|
295594
|
+
}
|
|
295595
|
+
return isRemoteEnvironment() ? REMOTE_DEFAULT_PORT : LOCAL_DEFAULT_PORT;
|
|
295596
|
+
}
|
|
295597
|
+
// 获取本地可用端口
|
|
295578
295598
|
function getPort() {
|
|
295579
295599
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295600
|
+
const startPort = getStartPort();
|
|
295580
295601
|
const port = yield portfinder_1.default.getPortPromise({
|
|
295581
|
-
port:
|
|
295602
|
+
port: startPort,
|
|
295603
|
+
stopPort: 65535
|
|
295582
295604
|
});
|
|
295583
295605
|
return port;
|
|
295584
295606
|
});
|
|
@@ -326147,7 +326169,7 @@ module.exports = function generate_pattern(it, $keyword, $ruleType) {
|
|
|
326147
326169
|
/***/ ((module) => {
|
|
326148
326170
|
|
|
326149
326171
|
"use strict";
|
|
326150
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.3-beta.
|
|
326172
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.3-beta.2","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.4","@cloudbase/toolbox":"^0.7.16-beta.0","@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
326173
|
|
|
326152
326174
|
/***/ }),
|
|
326153
326175
|
|
|
@@ -333651,6 +333673,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
333651
333673
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
333652
333674
|
exports.getMacAddress = void 0;
|
|
333653
333675
|
const address_1 = __importDefault(__webpack_require__(56163));
|
|
333676
|
+
// 获取本机 Mac 地址
|
|
333654
333677
|
function getMacAddress() {
|
|
333655
333678
|
return __awaiter(this, void 0, void 0, function* () {
|
|
333656
333679
|
return new Promise((resolve) => {
|
|
@@ -334541,6 +334564,9 @@ const DefaultCloudBaseConfig = {
|
|
|
334541
334564
|
functionRoot: './functions',
|
|
334542
334565
|
functions: []
|
|
334543
334566
|
};
|
|
334567
|
+
/**
|
|
334568
|
+
* 从配置文件中解析 cloudbase 配置
|
|
334569
|
+
*/
|
|
334544
334570
|
function resolveCloudBaseConfig(options) {
|
|
334545
334571
|
var _a, _b;
|
|
334546
334572
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -334549,17 +334575,21 @@ function resolveCloudBaseConfig(options) {
|
|
|
334549
334575
|
searchFrom,
|
|
334550
334576
|
moduleName: 'tcb'
|
|
334551
334577
|
});
|
|
334578
|
+
// 检查旧的配置文件
|
|
334552
334579
|
if (oldTcbConfig) {
|
|
334553
334580
|
throw new error_1.CloudBaseError('tcbrc.json 配置文件已废弃,请使用 cloudbaserc 配置文件!');
|
|
334554
334581
|
}
|
|
334582
|
+
// 可能为 null
|
|
334555
334583
|
const localCloudBaseConfig = yield (0, cosmiconfig_1.loadConfig)({
|
|
334556
334584
|
searchFrom,
|
|
334557
334585
|
configPath
|
|
334558
334586
|
});
|
|
334587
|
+
// localCloudBaseConfig 不为空,且不存在 envId
|
|
334559
334588
|
if (localCloudBaseConfig && !localCloudBaseConfig.envId) {
|
|
334560
334589
|
throw new error_1.CloudBaseError('无效的配置文件,配置文件必须包含环境 Id(envId) 字段');
|
|
334561
334590
|
}
|
|
334562
334591
|
const cloudbaseConfig = Object.assign(Object.assign({}, DefaultCloudBaseConfig), localCloudBaseConfig);
|
|
334592
|
+
// 兼容不同形式的配置
|
|
334563
334593
|
if ((_a = cloudbaseConfig.functions) === null || _a === void 0 ? void 0 : _a.length) {
|
|
334564
334594
|
cloudbaseConfig.functions = (_b = cloudbaseConfig.functions) === null || _b === void 0 ? void 0 : _b.map((func) => {
|
|
334565
334595
|
if (func.config) {
|
|
@@ -334577,19 +334607,25 @@ function resolveCloudBaseConfig(options) {
|
|
|
334577
334607
|
});
|
|
334578
334608
|
}
|
|
334579
334609
|
exports.resolveCloudBaseConfig = resolveCloudBaseConfig;
|
|
334610
|
+
/**
|
|
334611
|
+
* 从命令行和配置文件中获取 envId
|
|
334612
|
+
*/
|
|
334580
334613
|
function getEnvId(commandOptions) {
|
|
334581
334614
|
var _a;
|
|
334582
334615
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334583
334616
|
const envId = commandOptions === null || commandOptions === void 0 ? void 0 : commandOptions.envId;
|
|
334584
334617
|
const configPath = (_a = commandOptions === null || commandOptions === void 0 ? void 0 : commandOptions.parent) === null || _a === void 0 ? void 0 : _a.configFile;
|
|
334585
334618
|
const cloudbaseConfig = yield resolveCloudBaseConfig(configPath);
|
|
334619
|
+
// 命令行 envId 可以覆盖配置文件 envId
|
|
334586
334620
|
const assignEnvId = envId || (cloudbaseConfig === null || cloudbaseConfig === void 0 ? void 0 : cloudbaseConfig.envId);
|
|
334587
334621
|
return assignEnvId;
|
|
334588
334622
|
});
|
|
334589
334623
|
}
|
|
334590
334624
|
exports.getEnvId = getEnvId;
|
|
334591
334625
|
const renderConfig = (template, view) => {
|
|
334626
|
+
// 渲染时不 escape
|
|
334592
334627
|
mustache_1.default.escape = (text) => {
|
|
334628
|
+
// 将对象转成 JSON 字符串
|
|
334593
334629
|
if (typeof text === 'object') {
|
|
334594
334630
|
try {
|
|
334595
334631
|
return JSON.stringify(text).replace(/"/g, '\\"');
|
|
@@ -334603,6 +334639,7 @@ const renderConfig = (template, view) => {
|
|
|
334603
334639
|
return mustache_1.default.render(template, view, ['"{{', '}}"']);
|
|
334604
334640
|
};
|
|
334605
334641
|
exports.renderConfig = renderConfig;
|
|
334642
|
+
// cloudbase v2+ 配置文件解析器
|
|
334606
334643
|
class ConfigParser {
|
|
334607
334644
|
static get(key, defaultValue, options) {
|
|
334608
334645
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -334620,14 +334657,22 @@ class ConfigParser {
|
|
|
334620
334657
|
return this.instance.options(options).update(key, value);
|
|
334621
334658
|
});
|
|
334622
334659
|
}
|
|
334660
|
+
// 解析配置
|
|
334623
334661
|
static parseRawConfig(rawConfig, cwd = process.cwd()) {
|
|
334624
334662
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334625
334663
|
let config = lodash_1.default.cloneDeep(rawConfig);
|
|
334664
|
+
// 命令行中指定的 envId,优先级最高
|
|
334626
334665
|
const envId = yargs_1.default.argv.e || yargs_1.default.argv.envId;
|
|
334666
|
+
// 加载本地 env 文件
|
|
334627
334667
|
const env = (0, env_1.loadEnvVariables)(cwd);
|
|
334668
|
+
// 转换成字符串
|
|
334628
334669
|
let configString = JSON.stringify(config);
|
|
334629
334670
|
const envs = {
|
|
334630
|
-
|
|
334671
|
+
// 环境变量
|
|
334672
|
+
env: Object.assign(Object.assign({
|
|
334673
|
+
// 注入 ENV_ID,同云端部署保持一致
|
|
334674
|
+
ENV_ID: envId || config.envId }, env), process.env),
|
|
334675
|
+
// 云开发相关的变量
|
|
334631
334676
|
tcb: {
|
|
334632
334677
|
envId: envId || config.envId
|
|
334633
334678
|
},
|
|
@@ -334635,14 +334680,17 @@ class ConfigParser {
|
|
|
334635
334680
|
uid: (0, uid_1.uuid)(24)
|
|
334636
334681
|
}
|
|
334637
334682
|
};
|
|
334683
|
+
// --envId 优先级最高
|
|
334638
334684
|
if (envId) {
|
|
334639
334685
|
envs.env.envId = envId;
|
|
334640
334686
|
envs.env.ENV_ID = envId;
|
|
334641
334687
|
}
|
|
334688
|
+
// 使用模板渲染
|
|
334642
334689
|
configString = (0, exports.renderConfig)(configString, envs);
|
|
334643
334690
|
config = JSON.parse(configString, (key, value) => {
|
|
334644
334691
|
if (typeof value === 'string') {
|
|
334645
334692
|
try {
|
|
334693
|
+
// 只解析对象
|
|
334646
334694
|
const parsed = JSON.parse(value);
|
|
334647
334695
|
if (typeof parsed === 'object') {
|
|
334648
334696
|
return parsed;
|
|
@@ -334661,6 +334709,7 @@ class ConfigParser {
|
|
|
334661
334709
|
constructor(options = {}) {
|
|
334662
334710
|
this.options(options);
|
|
334663
334711
|
}
|
|
334712
|
+
// 重写内部配置
|
|
334664
334713
|
options(options = {}) {
|
|
334665
334714
|
const { cwd = process.cwd(), cover = true, configPath } = options;
|
|
334666
334715
|
this.cwd = cwd;
|
|
@@ -334668,21 +334717,28 @@ class ConfigParser {
|
|
|
334668
334717
|
this.configPath = configPath;
|
|
334669
334718
|
return this;
|
|
334670
334719
|
}
|
|
334720
|
+
// get config value by lodash object paths
|
|
334721
|
+
// https://lodash.com/docs/4.17.15#get
|
|
334671
334722
|
get(key, defaultValue) {
|
|
334672
334723
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334673
334724
|
const config = yield this.getConfig();
|
|
334725
|
+
// 不带 key,返回整个配置
|
|
334674
334726
|
if (!key) {
|
|
334675
334727
|
return config;
|
|
334676
334728
|
}
|
|
334729
|
+
// 返回具体字段的值
|
|
334677
334730
|
return lodash_1.default.get(config, key, defaultValue);
|
|
334678
334731
|
});
|
|
334679
334732
|
}
|
|
334733
|
+
// update config value by lodash object paths
|
|
334734
|
+
// https://lodash.com/docs/4.17.15#set
|
|
334680
334735
|
update(key, value, cover) {
|
|
334681
334736
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334682
334737
|
const config = yield resolveCloudBaseConfig({
|
|
334683
334738
|
configPath: this.configPath
|
|
334684
334739
|
});
|
|
334685
334740
|
let unionConfig;
|
|
334741
|
+
// 当 value 为 undefined 且 key 为对象时,直接把 key 作为值更新到 config 中
|
|
334686
334742
|
if (typeof value === 'undefined' && typeof key === 'object') {
|
|
334687
334743
|
unionConfig = Object.assign(Object.assign({}, config), key);
|
|
334688
334744
|
}
|
|
@@ -334692,24 +334748,34 @@ class ConfigParser {
|
|
|
334692
334748
|
yield this.updateConfig(unionConfig, cover);
|
|
334693
334749
|
});
|
|
334694
334750
|
}
|
|
334751
|
+
// 读配置,支持外部直接调用
|
|
334695
334752
|
getConfig() {
|
|
334696
334753
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334754
|
+
// 配置文件路径不存在
|
|
334697
334755
|
if (!this.configPath) {
|
|
334756
|
+
// 搜索配置,获取配置目录
|
|
334698
334757
|
const result = yield (0, cosmiconfig_1.searchConfig)(this.cwd);
|
|
334758
|
+
// 设置 config 路径
|
|
334699
334759
|
this.configPath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
334700
334760
|
}
|
|
334761
|
+
// 读取原配置
|
|
334701
334762
|
const rawConfig = yield resolveCloudBaseConfig({
|
|
334702
334763
|
configPath: this.configPath
|
|
334703
334764
|
});
|
|
334704
334765
|
return ConfigParser.parseRawConfig(rawConfig, this.cwd);
|
|
334705
334766
|
});
|
|
334706
334767
|
}
|
|
334768
|
+
// 写配置
|
|
334707
334769
|
updateConfig(config, cover = this.cover) {
|
|
334708
334770
|
return __awaiter(this, void 0, void 0, function* () {
|
|
334771
|
+
// 配置文件路径不存在
|
|
334709
334772
|
if (!this.configPath) {
|
|
334773
|
+
// 搜索配置,获取配置目录
|
|
334710
334774
|
const result = yield (0, cosmiconfig_1.searchConfig)(this.cwd);
|
|
334775
|
+
// 设置 config 路径,config 可能不存在
|
|
334711
334776
|
this.configPath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
334712
334777
|
}
|
|
334778
|
+
// 原配置
|
|
334713
334779
|
const baseConfig = yield (0, cosmiconfig_1.loadConfig)({
|
|
334714
334780
|
searchFrom: this.cwd,
|
|
334715
334781
|
configPath: this.configPath
|
|
@@ -334717,14 +334783,17 @@ class ConfigParser {
|
|
|
334717
334783
|
const unionConfig = cover
|
|
334718
334784
|
? Object.assign(Object.assign({}, baseConfig), config) : Object.assign(Object.assign({}, config), baseConfig);
|
|
334719
334785
|
let indent = 2;
|
|
334786
|
+
// 文件存在,检测文件缩进
|
|
334720
334787
|
if (this.configPath) {
|
|
334721
334788
|
const fileContent = yield fs_1.default.promises.readFile(this.configPath);
|
|
334722
334789
|
const detectRet = (0, detect_indent_1.detectIndent)(fileContent === null || fileContent === void 0 ? void 0 : fileContent.toString());
|
|
334723
334790
|
indent = (detectRet === null || detectRet === void 0 ? void 0 : detectRet.amount) || indent;
|
|
334724
334791
|
}
|
|
334725
334792
|
else {
|
|
334793
|
+
// 配置文件可能不存在,设置配置文件路径,直接写内容
|
|
334726
334794
|
this.configPath = path_1.default.join(this.cwd, 'cloudbaserc.json');
|
|
334727
334795
|
}
|
|
334796
|
+
// 写入配置到 json 文件中
|
|
334728
334797
|
jsonfile_1.default.writeFileSync(this.configPath, unionConfig, { spaces: indent });
|
|
334729
334798
|
});
|
|
334730
334799
|
}
|
|
@@ -378040,11 +378109,17 @@ function indexOf(xs, x) {
|
|
|
378040
378109
|
|
|
378041
378110
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
378042
378111
|
exports.getPropertyByPath = void 0;
|
|
378112
|
+
// Resolves property names or property paths defined with period-delimited
|
|
378113
|
+
// strings or arrays of strings. Property names that are found on the source
|
|
378114
|
+
// object are used directly (even if they include a period).
|
|
378115
|
+
// Nested property names that include periods, within a path, are only
|
|
378116
|
+
// understood in array paths.
|
|
378043
378117
|
function getPropertyByPath(source, path) {
|
|
378044
378118
|
if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
|
|
378045
378119
|
return source[path];
|
|
378046
378120
|
}
|
|
378047
378121
|
const parsedPath = typeof path === 'string' ? path.split('.') : path;
|
|
378122
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378048
378123
|
return parsedPath.reduce((previous, key) => {
|
|
378049
378124
|
if (previous === undefined) {
|
|
378050
378125
|
return previous;
|
|
@@ -383915,7 +383990,6 @@ __exportStar(__webpack_require__(87531), exports);
|
|
|
383915
383990
|
__exportStar(__webpack_require__(5476), exports);
|
|
383916
383991
|
__exportStar(__webpack_require__(74371), exports);
|
|
383917
383992
|
__exportStar(__webpack_require__(37210), exports);
|
|
383918
|
-
__exportStar(__webpack_require__(64180), exports);
|
|
383919
383993
|
__exportStar(__webpack_require__(22700), exports);
|
|
383920
383994
|
__exportStar(__webpack_require__(32428), exports);
|
|
383921
383995
|
__exportStar(__webpack_require__(29561), exports);
|
|
@@ -398236,7 +398310,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
398236
398310
|
});
|
|
398237
398311
|
};
|
|
398238
398312
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
398239
|
-
exports.AuthSupevisor = void 0;
|
|
398313
|
+
exports.AuthSupevisor = exports.AuthSupervisor = void 0;
|
|
398240
398314
|
const web_auth_1 = __webpack_require__(76097);
|
|
398241
398315
|
const common_1 = __webpack_require__(96711);
|
|
398242
398316
|
const credential_1 = __webpack_require__(99795);
|
|
@@ -398244,13 +398318,17 @@ const error_1 = __webpack_require__(64119);
|
|
|
398244
398318
|
__exportStar(__webpack_require__(96711), exports);
|
|
398245
398319
|
__exportStar(__webpack_require__(99795), exports);
|
|
398246
398320
|
__exportStar(__webpack_require__(76097), exports);
|
|
398247
|
-
class
|
|
398321
|
+
class AuthSupervisor {
|
|
398322
|
+
/**
|
|
398323
|
+
* 单例模式,全局缓存
|
|
398324
|
+
* @param options
|
|
398325
|
+
*/
|
|
398248
398326
|
static getInstance(options = {}) {
|
|
398249
|
-
if (
|
|
398250
|
-
return
|
|
398327
|
+
if (AuthSupervisor.instance) {
|
|
398328
|
+
return AuthSupervisor.instance;
|
|
398251
398329
|
}
|
|
398252
|
-
const instance = new
|
|
398253
|
-
|
|
398330
|
+
const instance = new AuthSupervisor(options);
|
|
398331
|
+
AuthSupervisor.instance = instance;
|
|
398254
398332
|
return instance;
|
|
398255
398333
|
}
|
|
398256
398334
|
constructor(options = {}) {
|
|
@@ -398263,11 +398341,15 @@ class AuthSupevisor {
|
|
|
398263
398341
|
this.cacheExpiredTime = 0;
|
|
398264
398342
|
this.throwError = throwError;
|
|
398265
398343
|
}
|
|
398344
|
+
/**
|
|
398345
|
+
* 获取登录状态信息
|
|
398346
|
+
*/
|
|
398266
398347
|
getLoginState() {
|
|
398267
398348
|
return __awaiter(this, void 0, void 0, function* () {
|
|
398268
398349
|
if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
|
|
398269
398350
|
return this.cacheCredential;
|
|
398270
398351
|
}
|
|
398352
|
+
// 获取本地登录状态
|
|
398271
398353
|
const credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
398272
398354
|
if (this.needCache && credential) {
|
|
398273
398355
|
this.cacheCredential = credential;
|
|
@@ -398279,17 +398361,25 @@ class AuthSupevisor {
|
|
|
398279
398361
|
return credential;
|
|
398280
398362
|
});
|
|
398281
398363
|
}
|
|
398364
|
+
/**
|
|
398365
|
+
* 通过网页授权登录
|
|
398366
|
+
* @returns credential
|
|
398367
|
+
*/
|
|
398282
398368
|
loginByWebAuth(options = {}) {
|
|
398283
398369
|
return __awaiter(this, void 0, void 0, function* () {
|
|
398284
|
-
const { getAuthUrl, throwError } = options;
|
|
398370
|
+
const { getAuthUrl, throwError, noBrowser, callbackTimeout } = options;
|
|
398285
398371
|
if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
|
|
398286
398372
|
return this.cacheCredential;
|
|
398287
398373
|
}
|
|
398374
|
+
// 校验本地秘钥
|
|
398288
398375
|
let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
398289
398376
|
if (credential)
|
|
398290
398377
|
return credential;
|
|
398378
|
+
// 兼容临时秘钥
|
|
398291
398379
|
credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
|
|
398292
|
-
getAuthUrl
|
|
398380
|
+
getAuthUrl,
|
|
398381
|
+
noBrowser,
|
|
398382
|
+
callbackTimeout
|
|
398293
398383
|
});
|
|
398294
398384
|
try {
|
|
398295
398385
|
yield (0, common_1.checkAuth)(credential, this.requestConfig);
|
|
@@ -398300,8 +398390,10 @@ class AuthSupevisor {
|
|
|
398300
398390
|
}
|
|
398301
398391
|
return null;
|
|
398302
398392
|
}
|
|
398393
|
+
// 通过 Web 登录时,本地要存储 tmpSecretId 形式,方式 CLI 登录失效
|
|
398303
398394
|
const webCredential = (0, common_1.resolveWebCredential)(credential);
|
|
398304
398395
|
yield credential_1.authStore.set('credential', webCredential);
|
|
398396
|
+
// 缓存处理转换后的 credential
|
|
398305
398397
|
if (this.needCache && credential) {
|
|
398306
398398
|
this.cacheCredential = credential;
|
|
398307
398399
|
const { accessTokenExpired } = credential;
|
|
@@ -398312,26 +398404,41 @@ class AuthSupevisor {
|
|
|
398312
398404
|
return credential;
|
|
398313
398405
|
});
|
|
398314
398406
|
}
|
|
398315
|
-
|
|
398407
|
+
/**
|
|
398408
|
+
* 通过 API Secret 登录,支持临时秘钥
|
|
398409
|
+
* @param secretId
|
|
398410
|
+
* @param secretKey
|
|
398411
|
+
* @param token
|
|
398412
|
+
* @param opts 选项配置,包括强制更新和额外的 Credential 字段
|
|
398413
|
+
* @returns credential
|
|
398414
|
+
*/
|
|
398415
|
+
// eslint-disable-next-line max-params
|
|
398416
|
+
loginByApiSecret(secretId, secretKey, token, opts) {
|
|
398316
398417
|
return __awaiter(this, void 0, void 0, function* () {
|
|
398317
|
-
|
|
398418
|
+
const { forceUpdate = false, storeAsWebCredential = false, additionalCredentialFields } = opts || {};
|
|
398419
|
+
if (this.cacheCredential && this.needCache && !this.isCacheExpire() && !forceUpdate) {
|
|
398318
398420
|
return this.cacheCredential;
|
|
398319
398421
|
}
|
|
398320
|
-
|
|
398321
|
-
if (
|
|
398322
|
-
|
|
398422
|
+
// 校验本地秘钥(如果不是强制更新)
|
|
398423
|
+
if (!forceUpdate) {
|
|
398424
|
+
let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
398425
|
+
if (credential)
|
|
398426
|
+
return credential;
|
|
398427
|
+
}
|
|
398428
|
+
// 当本地身份信息不存在时,才使用传入参数进行校验
|
|
398323
398429
|
if (!secretId || !secretKey) {
|
|
398324
398430
|
throw new error_1.CloudBaseError('secretId 或 secretKey 不能为空');
|
|
398325
398431
|
}
|
|
398326
|
-
credential = {
|
|
398327
|
-
secretId,
|
|
398432
|
+
const credential = Object.assign(Object.assign({}, additionalCredentialFields), { secretId,
|
|
398328
398433
|
secretKey,
|
|
398329
|
-
token
|
|
398330
|
-
};
|
|
398434
|
+
token });
|
|
398331
398435
|
try {
|
|
398332
398436
|
yield (0, common_1.checkAuth)(credential, this.requestConfig);
|
|
398333
398437
|
}
|
|
398334
398438
|
catch (e) {
|
|
398439
|
+
// CAM 错误视为登录正常
|
|
398440
|
+
// if (isCamRefused(e)) return credential;
|
|
398441
|
+
// 请求超时
|
|
398335
398442
|
if (e.type === 'request-timeout') {
|
|
398336
398443
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
398337
398444
|
}
|
|
@@ -398340,7 +398447,12 @@ class AuthSupevisor {
|
|
|
398340
398447
|
}
|
|
398341
398448
|
return null;
|
|
398342
398449
|
}
|
|
398343
|
-
|
|
398450
|
+
// 根据选项决定存储格式
|
|
398451
|
+
const credentialToStore = storeAsWebCredential
|
|
398452
|
+
? (0, common_1.resolveWebCredential)(credential)
|
|
398453
|
+
: credential;
|
|
398454
|
+
// 存储信息
|
|
398455
|
+
yield credential_1.authStore.set('credential', credentialToStore);
|
|
398344
398456
|
if (this.needCache && credential) {
|
|
398345
398457
|
this.cacheCredential = credential;
|
|
398346
398458
|
this.cacheExpiredTime = Date.now() + 3600 * 1000;
|
|
@@ -398353,10 +398465,11 @@ class AuthSupevisor {
|
|
|
398353
398465
|
if (this.cacheCredential) {
|
|
398354
398466
|
this.cacheCredential = null;
|
|
398355
398467
|
}
|
|
398356
|
-
const
|
|
398468
|
+
const credential = yield (0, credential_1.getCredentialWithoutCheck)();
|
|
398357
398469
|
try {
|
|
398358
|
-
|
|
398359
|
-
|
|
398470
|
+
// 仅使用 Web 控制台授权登录时才删除 token
|
|
398471
|
+
if (credential === null || credential === void 0 ? void 0 : credential.refreshToken) {
|
|
398472
|
+
yield (0, credential_1.refreshTmpToken)(Object.assign(Object.assign({}, credential), { isLogout: true }));
|
|
398360
398473
|
}
|
|
398361
398474
|
yield credential_1.authStore.delete('credential');
|
|
398362
398475
|
}
|
|
@@ -398371,6 +398484,29 @@ class AuthSupevisor {
|
|
|
398371
398484
|
return now >= this.cacheExpiredTime;
|
|
398372
398485
|
}
|
|
398373
398486
|
}
|
|
398487
|
+
exports.AuthSupervisor = AuthSupervisor;
|
|
398488
|
+
/**
|
|
398489
|
+
* @deprecated Use `AuthSupervisor` instead. This class has a spelling error and will be removed in a future version.
|
|
398490
|
+
*/
|
|
398491
|
+
class AuthSupevisor extends AuthSupervisor {
|
|
398492
|
+
/**
|
|
398493
|
+
* @deprecated Use `AuthSupervisor.getInstance` instead
|
|
398494
|
+
*/
|
|
398495
|
+
static getInstance(options = {}) {
|
|
398496
|
+
if (AuthSupevisor.instance) {
|
|
398497
|
+
return AuthSupevisor.instance;
|
|
398498
|
+
}
|
|
398499
|
+
const instance = new AuthSupevisor(options);
|
|
398500
|
+
AuthSupevisor.instance = instance;
|
|
398501
|
+
return instance;
|
|
398502
|
+
}
|
|
398503
|
+
/**
|
|
398504
|
+
* @deprecated Use `AuthSupervisor` constructor instead
|
|
398505
|
+
*/
|
|
398506
|
+
constructor(options = {}) {
|
|
398507
|
+
super(options);
|
|
398508
|
+
}
|
|
398509
|
+
}
|
|
398374
398510
|
exports.AuthSupevisor = AuthSupevisor;
|
|
398375
398511
|
|
|
398376
398512
|
|
|
@@ -410150,11 +410286,14 @@ const http_1 = __importDefault(__webpack_require__(58611));
|
|
|
410150
410286
|
const system_1 = __webpack_require__(62179);
|
|
410151
410287
|
const error_1 = __webpack_require__(64119);
|
|
410152
410288
|
const html_1 = __webpack_require__(74856);
|
|
410289
|
+
const child_process_1 = __webpack_require__(35317);
|
|
410290
|
+
// 创建本地 Web 服务器,接受 Web 控制台传入的信息
|
|
410153
410291
|
function createLocalServer() {
|
|
410154
410292
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410155
410293
|
const server = http_1.default.createServer();
|
|
410156
410294
|
const port = yield (0, system_1.getPort)();
|
|
410157
410295
|
return new Promise((resolve, reject) => {
|
|
410296
|
+
// 服务启动异常
|
|
410158
410297
|
server.on('error', (e) => {
|
|
410159
410298
|
reject(e);
|
|
410160
410299
|
});
|
|
@@ -410167,6 +410306,7 @@ function createLocalServer() {
|
|
|
410167
410306
|
});
|
|
410168
410307
|
});
|
|
410169
410308
|
}
|
|
410309
|
+
// 返回 HTML 响应
|
|
410170
410310
|
function respondWithFile(options) {
|
|
410171
410311
|
const { req, res, statusCode, filename } = options;
|
|
410172
410312
|
return new Promise(function (resolve) {
|
|
@@ -410180,20 +410320,83 @@ function respondWithFile(options) {
|
|
|
410180
410320
|
resolve();
|
|
410181
410321
|
});
|
|
410182
410322
|
}
|
|
410183
|
-
function
|
|
410323
|
+
function isTruthyFlag(value) {
|
|
410324
|
+
if (!value) {
|
|
410325
|
+
return false;
|
|
410326
|
+
}
|
|
410327
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
|
|
410328
|
+
}
|
|
410329
|
+
function isVSCodeEnvironment() {
|
|
410330
|
+
return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.TERM_PROGRAM === 'vscode');
|
|
410331
|
+
}
|
|
410332
|
+
function openUrlByVSCode(url) {
|
|
410333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
410334
|
+
return new Promise((resolve, reject) => {
|
|
410335
|
+
(0, child_process_1.execFile)('code', ['--open-url', url], (error) => {
|
|
410336
|
+
if (error) {
|
|
410337
|
+
reject(error);
|
|
410338
|
+
return;
|
|
410339
|
+
}
|
|
410340
|
+
resolve();
|
|
410341
|
+
});
|
|
410342
|
+
});
|
|
410343
|
+
});
|
|
410344
|
+
}
|
|
410345
|
+
// 从 Web 页面中获取数据
|
|
410346
|
+
function getDataFromWeb(getUrl, type, options = {}) {
|
|
410347
|
+
var _a, _b;
|
|
410184
410348
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410185
410349
|
const { server, port } = yield createLocalServer();
|
|
410186
|
-
const
|
|
410187
|
-
|
|
410188
|
-
|
|
410350
|
+
const noBrowser = (_a = options.noBrowser) !== null && _a !== void 0 ? _a : isTruthyFlag(process.env.TCB_NO_BROWSER);
|
|
410351
|
+
const callbackTimeout = (_b = options.callbackTimeout) !== null && _b !== void 0 ? _b : 180000;
|
|
410352
|
+
if (!Number.isFinite(callbackTimeout) || callbackTimeout <= 0) {
|
|
410353
|
+
throw new error_1.CloudBaseError('callbackTimeout must be a positive number');
|
|
410189
410354
|
}
|
|
410190
|
-
|
|
410191
|
-
|
|
410355
|
+
const url = getUrl(port);
|
|
410356
|
+
console.log('若链接未自动打开,请手动复制此链接至浏览器,或尝试使用其他登录方式:');
|
|
410357
|
+
console.log(`\n${url}`);
|
|
410358
|
+
if (!noBrowser) {
|
|
410359
|
+
// 对 url 转码, 避免 wsl 无法正常打开地址
|
|
410360
|
+
// https://www.npmjs.com/package/open#url
|
|
410361
|
+
// https://github.com/sindresorhus/open/blob/master/index.js#L48
|
|
410362
|
+
try {
|
|
410363
|
+
yield (0, open_1.default)(url, { url: true });
|
|
410364
|
+
}
|
|
410365
|
+
catch (e) {
|
|
410366
|
+
const code = (e === null || e === void 0 ? void 0 : e.code) || 'UNKNOWN';
|
|
410367
|
+
console.warn(`自动打开浏览器失败(${code})。`);
|
|
410368
|
+
if (isVSCodeEnvironment()) {
|
|
410369
|
+
try {
|
|
410370
|
+
yield openUrlByVSCode(url);
|
|
410371
|
+
}
|
|
410372
|
+
catch (vscodeError) {
|
|
410373
|
+
// ignore error
|
|
410374
|
+
}
|
|
410375
|
+
}
|
|
410376
|
+
}
|
|
410192
410377
|
}
|
|
410193
410378
|
return new Promise((resolve, reject) => {
|
|
410379
|
+
let finished = false;
|
|
410380
|
+
const timer = setTimeout(() => {
|
|
410381
|
+
if (finished) {
|
|
410382
|
+
return;
|
|
410383
|
+
}
|
|
410384
|
+
finished = true;
|
|
410385
|
+
server.close();
|
|
410386
|
+
reject(new error_1.CloudBaseError(`等待浏览器授权回调超时(${Math.floor(callbackTimeout / 1000)}s)!`));
|
|
410387
|
+
}, callbackTimeout);
|
|
410388
|
+
const finish = (fn) => {
|
|
410389
|
+
if (finished) {
|
|
410390
|
+
return;
|
|
410391
|
+
}
|
|
410392
|
+
finished = true;
|
|
410393
|
+
clearTimeout(timer);
|
|
410394
|
+
fn();
|
|
410395
|
+
};
|
|
410194
410396
|
server.on('request', (req, res) => {
|
|
410195
|
-
const
|
|
410397
|
+
const url = req.url || '/';
|
|
410196
410398
|
const { query } = query_string_1.default.parseUrl(url);
|
|
410399
|
+
// 响应 HTML 文件
|
|
410197
410400
|
if (query === null || query === void 0 ? void 0 : query.html) {
|
|
410198
410401
|
return respondWithFile({
|
|
410199
410402
|
req,
|
|
@@ -410201,25 +410404,33 @@ function getDataFromWeb(getUrl, type) {
|
|
|
410201
410404
|
statusCode: 200,
|
|
410202
410405
|
filename: `${type}Success`
|
|
410203
410406
|
}).then(() => {
|
|
410204
|
-
|
|
410205
|
-
|
|
410407
|
+
finish(() => {
|
|
410408
|
+
server.close();
|
|
410409
|
+
resolve(query);
|
|
410410
|
+
});
|
|
410206
410411
|
}).catch((e) => {
|
|
410207
|
-
|
|
410208
|
-
|
|
410412
|
+
finish(() => {
|
|
410413
|
+
server.close();
|
|
410414
|
+
reject(e);
|
|
410415
|
+
});
|
|
410209
410416
|
});
|
|
410210
410417
|
}
|
|
410418
|
+
// CORS 响应普通文本
|
|
410211
410419
|
res.writeHead(200, {
|
|
410212
410420
|
'Access-Control-Allow-Origin': '*',
|
|
410213
410421
|
'Access-Control-Allow-Methods': '*',
|
|
410214
410422
|
'Access-Control-Allow-Headers': '*',
|
|
410215
410423
|
'Content-Type': 'text/plain',
|
|
410424
|
+
// 立即关闭 http 连接
|
|
410216
410425
|
Connection: 'close'
|
|
410217
410426
|
});
|
|
410218
410427
|
res.end();
|
|
410219
410428
|
if (req.method !== 'OPTIONS') {
|
|
410220
410429
|
server.close();
|
|
410221
410430
|
}
|
|
410222
|
-
|
|
410431
|
+
finish(() => {
|
|
410432
|
+
resolve(query);
|
|
410433
|
+
});
|
|
410223
410434
|
});
|
|
410224
410435
|
});
|
|
410225
410436
|
});
|
|
@@ -442282,6 +442493,7 @@ __exportStar(__webpack_require__(31153), exports);
|
|
|
442282
442493
|
__exportStar(__webpack_require__(33283), exports);
|
|
442283
442494
|
__exportStar(__webpack_require__(79998), exports);
|
|
442284
442495
|
__exportStar(__webpack_require__(19835), exports);
|
|
442496
|
+
// export types
|
|
442285
442497
|
__exportStar(__webpack_require__(42612), exports);
|
|
442286
442498
|
|
|
442287
442499
|
|
|
@@ -450306,6 +450518,7 @@ const cloud_api_1 = __webpack_require__(2090);
|
|
|
450306
450518
|
const constant_1 = __webpack_require__(53393);
|
|
450307
450519
|
let commonCredential;
|
|
450308
450520
|
class CloudApiService {
|
|
450521
|
+
// 单例模式
|
|
450309
450522
|
static getInstance(service) {
|
|
450310
450523
|
var _a;
|
|
450311
450524
|
if ((_a = CloudApiService.serviceCacheMap) === null || _a === void 0 ? void 0 : _a[service]) {
|
|
@@ -450316,6 +450529,7 @@ class CloudApiService {
|
|
|
450316
450529
|
return apiService;
|
|
450317
450530
|
}
|
|
450318
450531
|
constructor(service, baseParams, version = '') {
|
|
450532
|
+
// 初始化 API 实例
|
|
450319
450533
|
this.apiService = new cloud_api_1.CloudApiService({
|
|
450320
450534
|
service,
|
|
450321
450535
|
version,
|
|
@@ -450344,6 +450558,7 @@ class CloudApiService {
|
|
|
450344
450558
|
}
|
|
450345
450559
|
}
|
|
450346
450560
|
exports.CloudApiService = CloudApiService;
|
|
450561
|
+
// 缓存请求实例
|
|
450347
450562
|
CloudApiService.serviceCacheMap = {};
|
|
450348
450563
|
|
|
450349
450564
|
|
|
@@ -468485,8 +468700,16 @@ const archiver_1 = __importDefault(__webpack_require__(30989));
|
|
|
468485
468700
|
exports.decompress = decompress_1.default;
|
|
468486
468701
|
const unzip = (zipFile, dest) => (0, exports.decompress)(zipFile, dest);
|
|
468487
468702
|
exports.unzip = unzip;
|
|
468703
|
+
/**
|
|
468704
|
+
* 解压流(使用临时 zip 包)
|
|
468705
|
+
* @param source 可读流
|
|
468706
|
+
* @param dest 解压目标文件夹
|
|
468707
|
+
* @param name 可选的临时 zip 包名
|
|
468708
|
+
*/
|
|
468488
468709
|
const unzipStream = (source, dest, name = 'gape3il5rk8.zip') => __awaiter(void 0, void 0, void 0, function* () {
|
|
468710
|
+
// 确保文件夹存在
|
|
468489
468711
|
yield (0, fs_2.mkdirAsync)(dest);
|
|
468712
|
+
// 使用一个临时文件下载 zip 包
|
|
468490
468713
|
const zipPath = path_1.default.join(dest, `${name}.zip`);
|
|
468491
468714
|
const zip = fs_1.default.createWriteStream(zipPath);
|
|
468492
468715
|
source.pipe(zip);
|
|
@@ -468529,13 +468752,16 @@ function zipFiles(allFilesPath, outputPath, ignore) {
|
|
|
468529
468752
|
archive.pipe(output);
|
|
468530
468753
|
allFilesPath.forEach(filePath => {
|
|
468531
468754
|
if (fs_1.default.statSync(filePath).isDirectory()) {
|
|
468755
|
+
// append files from a glob pattern
|
|
468532
468756
|
archive.glob('**/*', {
|
|
468757
|
+
// 目标路径
|
|
468533
468758
|
cwd: filePath,
|
|
468534
468759
|
ignore: ignore,
|
|
468535
468760
|
dot: true
|
|
468536
468761
|
});
|
|
468537
468762
|
}
|
|
468538
468763
|
else {
|
|
468764
|
+
// append file
|
|
468539
468765
|
archive.file(filePath);
|
|
468540
468766
|
}
|
|
468541
468767
|
});
|
|
@@ -482194,7 +482420,11 @@ module.exports = arrayMap;
|
|
|
482194
482420
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
482195
482421
|
exports.AsyncMerge = void 0;
|
|
482196
482422
|
const cache_1 = __webpack_require__(51995);
|
|
482423
|
+
// 使用 Symbol 值,判断缓存结果时,可以准确判断是否为 Error 类型
|
|
482197
482424
|
const ERROR_KEY = Symbol('ERROR_KEY');
|
|
482425
|
+
/**
|
|
482426
|
+
* 异步任务合并
|
|
482427
|
+
*/
|
|
482198
482428
|
class AsyncMerge {
|
|
482199
482429
|
constructor() {
|
|
482200
482430
|
this.tasks = {};
|
|
@@ -482208,7 +482438,10 @@ class AsyncMerge {
|
|
|
482208
482438
|
throw new Error('AsyncMerge taskId could not be empty, it will cause unexpected result!');
|
|
482209
482439
|
}
|
|
482210
482440
|
return new Promise((resolve, reject) => {
|
|
482441
|
+
// 取缓存
|
|
482211
482442
|
const cacheRet = cache_1.nilCache.get(taskId);
|
|
482443
|
+
// 校验缓存,缓存结果可能为 null, undefined 等空值
|
|
482444
|
+
// 使用 Symbol 值做判断
|
|
482212
482445
|
if (maxAge > 0 && cacheRet !== cache_1.Cache.NIL) {
|
|
482213
482446
|
const e = cacheRet[ERROR_KEY];
|
|
482214
482447
|
if (e) {
|
|
@@ -482230,6 +482463,7 @@ class AsyncMerge {
|
|
|
482230
482463
|
}
|
|
482231
482464
|
});
|
|
482232
482465
|
}
|
|
482466
|
+
// eslint-disable-next-line
|
|
482233
482467
|
runTask(fn, taskId, taskOptions, cb) {
|
|
482234
482468
|
const { tasks } = this;
|
|
482235
482469
|
const { maxAge = 0, timeout = 60000 } = taskOptions;
|
|
@@ -482241,15 +482475,18 @@ class AsyncMerge {
|
|
|
482241
482475
|
}
|
|
482242
482476
|
tasks[taskId].callbacks.push(cb);
|
|
482243
482477
|
const task = tasks[taskId];
|
|
482478
|
+
// 当前类型的任务没有运行
|
|
482244
482479
|
if (!task.lock) {
|
|
482245
482480
|
let timerId = null;
|
|
482246
482481
|
if (timeout) {
|
|
482247
482482
|
timerId = setTimeout(() => {
|
|
482483
|
+
// 超时回调
|
|
482248
482484
|
task.callbacks.forEach((cb) => cb(new Error('TASK_TIMEOUT')));
|
|
482249
482485
|
task.lock = false;
|
|
482250
482486
|
delete tasks[taskId];
|
|
482251
482487
|
}, timeout);
|
|
482252
482488
|
}
|
|
482489
|
+
// 上锁,标志任务处理开始
|
|
482253
482490
|
task.lock = true;
|
|
482254
482491
|
fn()
|
|
482255
482492
|
.then((res) => {
|
|
@@ -482263,6 +482500,7 @@ class AsyncMerge {
|
|
|
482263
482500
|
clearTimeout(timerId);
|
|
482264
482501
|
task.lock = false;
|
|
482265
482502
|
delete tasks[taskId];
|
|
482503
|
+
// 任务异常,缓存异常值
|
|
482266
482504
|
maxAge > 0 && cache_1.nilCache.set(taskId, { ERROR_KEY: e }, maxAge);
|
|
482267
482505
|
task.callbacks.forEach((cb) => cb(e));
|
|
482268
482506
|
});
|
|
@@ -493662,10 +493900,6 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493662
493900
|
{
|
|
493663
493901
|
flags: '-e, --envId <envId>',
|
|
493664
493902
|
desc: (0, i18n_1.t)('环境 Id')
|
|
493665
|
-
},
|
|
493666
|
-
{
|
|
493667
|
-
flags: '--yes',
|
|
493668
|
-
desc: (0, i18n_1.t)('跳过交互确认,使用默认选项自动执行')
|
|
493669
493903
|
}
|
|
493670
493904
|
],
|
|
493671
493905
|
desc: (0, i18n_1.t)('更新云函数配置'),
|
|
@@ -493675,35 +493909,26 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493675
493909
|
}
|
|
493676
493910
|
execute(ctx, params, log) {
|
|
493677
493911
|
return __awaiter(this, void 0, void 0, function* () {
|
|
493678
|
-
let { envId, config: { functions }
|
|
493912
|
+
let { envId, config: { functions } } = ctx;
|
|
493679
493913
|
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
493680
|
-
const { yes } = options;
|
|
493681
493914
|
let isBathUpdate = false;
|
|
493682
493915
|
if (!envId) {
|
|
493683
493916
|
envId = yield (0, utils_1.selectEnv)({ envTypes: [constant_1.EnvType.BAAS, constant_1.EnvType.WEDA] });
|
|
493684
493917
|
}
|
|
493685
493918
|
if (!name) {
|
|
493686
|
-
|
|
493687
|
-
|
|
493688
|
-
|
|
493689
|
-
|
|
493690
|
-
|
|
493691
|
-
|
|
493692
|
-
|
|
493693
|
-
name: 'isBatch',
|
|
493694
|
-
message: (0, i18n_1.t)('无云函数名称,是否需要更新配置文件中的【全部云函数】的配置?'),
|
|
493695
|
-
default: false
|
|
493696
|
-
});
|
|
493697
|
-
isBathUpdate = isBatch;
|
|
493698
|
-
}
|
|
493919
|
+
const { isBatch } = yield inquirer_1.default.prompt({
|
|
493920
|
+
type: 'confirm',
|
|
493921
|
+
name: 'isBatch',
|
|
493922
|
+
message: (0, i18n_1.t)('无云函数名称,是否需要更新配置文件中的【全部云函数】的配置?'),
|
|
493923
|
+
default: false
|
|
493924
|
+
});
|
|
493925
|
+
isBathUpdate = isBatch;
|
|
493699
493926
|
if (!isBathUpdate) {
|
|
493700
493927
|
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
|
|
493701
493928
|
}
|
|
493702
493929
|
}
|
|
493703
493930
|
if (isBathUpdate) {
|
|
493704
|
-
const envVarUpdateMode = hasEnvVariablesConfig(functions)
|
|
493705
|
-
? (yes ? 'overwrite' : yield askEnvVarUpdateMode())
|
|
493706
|
-
: undefined;
|
|
493931
|
+
const envVarUpdateMode = hasEnvVariablesConfig(functions) ? yield askEnvVarUpdateMode() : undefined;
|
|
493707
493932
|
for (const func of functions) {
|
|
493708
493933
|
const isValid = yield validateFunctionTypeChange(envId, func, log);
|
|
493709
493934
|
if (!isValid) {
|
|
@@ -493727,9 +493952,7 @@ let ConfigUpdate = class ConfigUpdate extends common_1.Command {
|
|
|
493727
493952
|
if (!isValid) {
|
|
493728
493953
|
return;
|
|
493729
493954
|
}
|
|
493730
|
-
const envVarUpdateMode = hasEnvVariablesConfig([functionItem])
|
|
493731
|
-
? (yes ? 'overwrite' : yield askEnvVarUpdateMode())
|
|
493732
|
-
: undefined;
|
|
493955
|
+
const envVarUpdateMode = hasEnvVariablesConfig([functionItem]) ? yield askEnvVarUpdateMode() : undefined;
|
|
493733
493956
|
yield (0, function_1.updateFunctionConfig)({
|
|
493734
493957
|
envId,
|
|
493735
493958
|
functionName: name,
|
|
@@ -511087,6 +511310,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
511087
511310
|
exports.md5Encoding = void 0;
|
|
511088
511311
|
const crypto_1 = __importDefault(__webpack_require__(76982));
|
|
511089
511312
|
const error_1 = __webpack_require__(64119);
|
|
511313
|
+
// MD5
|
|
511090
511314
|
function md5Encoding(str = '') {
|
|
511091
511315
|
if (typeof str !== 'string')
|
|
511092
511316
|
throw new error_1.CloudBaseError('参数必须为字符串!');
|
|
@@ -512587,9 +512811,13 @@ const FileAsync_1 = __importDefault(__webpack_require__(19778));
|
|
|
512587
512811
|
const FileSync_1 = __importDefault(__webpack_require__(29303));
|
|
512588
512812
|
const fs_1 = __webpack_require__(96185);
|
|
512589
512813
|
const homeDir = os_1.default.homedir();
|
|
512814
|
+
// 系统配置目录
|
|
512590
512815
|
const homeAccessible = (0, fs_1.checkFullAccess)(homeDir);
|
|
512816
|
+
// 仅当 home 目录可访问时,才使用 home 目录,否则使用临时目录
|
|
512591
512817
|
const configDir = homeDir && homeAccessible ? path_1.default.join(homeDir, '.config') : path_1.default.join(os_1.default.tmpdir(), '.config');
|
|
512818
|
+
// cloudbase 配置目录
|
|
512592
512819
|
exports.cloudbaseConfigDir = path_1.default.join(configDir, '.cloudbase');
|
|
512820
|
+
// 确保目录存在
|
|
512593
512821
|
make_dir_1.default.sync(exports.cloudbaseConfigDir);
|
|
512594
512822
|
function getAsyncDB(file) {
|
|
512595
512823
|
const dbPath = path_1.default.join(exports.cloudbaseConfigDir, `${file}.json`);
|
|
@@ -517404,9 +517632,11 @@ function handleTimeout(e) {
|
|
|
517404
517632
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
517405
517633
|
}
|
|
517406
517634
|
else {
|
|
517635
|
+
// 其他错误,抛出
|
|
517407
517636
|
throw e;
|
|
517408
517637
|
}
|
|
517409
517638
|
}
|
|
517639
|
+
// 使用 fetch + 代理
|
|
517410
517640
|
function fetch(url, config = {}) {
|
|
517411
517641
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517412
517642
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -517429,6 +517659,7 @@ function fetch(url, config = {}) {
|
|
|
517429
517659
|
});
|
|
517430
517660
|
}
|
|
517431
517661
|
exports.fetch = fetch;
|
|
517662
|
+
// 使用 fetch + 代理
|
|
517432
517663
|
function postFetch(url, data) {
|
|
517433
517664
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517434
517665
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -517475,6 +517706,7 @@ function fetchStream(url, config = {}) {
|
|
|
517475
517706
|
});
|
|
517476
517707
|
}
|
|
517477
517708
|
exports.fetchStream = fetchStream;
|
|
517709
|
+
// 使用 fetch + 代理
|
|
517478
517710
|
function putFetch(url, config = {}) {
|
|
517479
517711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
517480
517712
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -547181,6 +547413,9 @@ exports.getRegion = exports.getCloudBaseConfig = void 0;
|
|
|
547181
547413
|
const yargs_1 = __importDefault(__webpack_require__(72841));
|
|
547182
547414
|
const path_1 = __importDefault(__webpack_require__(16928));
|
|
547183
547415
|
const cloudbase_1 = __webpack_require__(10304);
|
|
547416
|
+
/**
|
|
547417
|
+
* 获取当前目录下的 cloudbase 配置
|
|
547418
|
+
*/
|
|
547184
547419
|
const getCloudBaseConfig = (configPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
547185
547420
|
let specificConfigPath = configPath || yargs_1.default.argv['config-path'];
|
|
547186
547421
|
specificConfigPath = specificConfigPath ? path_1.default.resolve(specificConfigPath) : undefined;
|
|
@@ -547191,7 +547426,11 @@ const getCloudBaseConfig = (configPath) => __awaiter(void 0, void 0, void 0, fun
|
|
|
547191
547426
|
return config;
|
|
547192
547427
|
});
|
|
547193
547428
|
exports.getCloudBaseConfig = getCloudBaseConfig;
|
|
547429
|
+
/**
|
|
547430
|
+
* 从命令行参数和配置文件中读取 region
|
|
547431
|
+
*/
|
|
547194
547432
|
const getRegion = (noDefault = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
547433
|
+
// region 缩写
|
|
547195
547434
|
const regionMap = {
|
|
547196
547435
|
gz: 'ap-guangzhou',
|
|
547197
547436
|
bj: 'ap-beijing',
|
|
@@ -547200,16 +547439,19 @@ const getRegion = (noDefault = false) => __awaiter(void 0, void 0, void 0, funct
|
|
|
547200
547439
|
cd: 'ap-chengdu',
|
|
547201
547440
|
cq: 'ap-chongqing'
|
|
547202
547441
|
};
|
|
547442
|
+
// 命令行中指定的 region
|
|
547203
547443
|
const argvRegion = (yargs_1.default.argv.r || yargs_1.default.argv.region);
|
|
547204
547444
|
if (argvRegion && regionMap[argvRegion]) {
|
|
547205
547445
|
return regionMap[argvRegion];
|
|
547206
547446
|
}
|
|
547207
547447
|
if (argvRegion)
|
|
547208
547448
|
return argvRegion;
|
|
547449
|
+
// 配置文件中的 region
|
|
547209
547450
|
const config = yield (0, exports.getCloudBaseConfig)();
|
|
547210
547451
|
if ((config === null || config === void 0 ? void 0 : config.region) && regionMap[config === null || config === void 0 ? void 0 : config.region]) {
|
|
547211
547452
|
return regionMap[config.region];
|
|
547212
547453
|
}
|
|
547454
|
+
// 不使用默认值时,不会默认返回 region
|
|
547213
547455
|
return noDefault ? config === null || config === void 0 ? void 0 : config.region : (config === null || config === void 0 ? void 0 : config.region) || 'ap-shanghai';
|
|
547214
547456
|
});
|
|
547215
547457
|
exports.getRegion = getRegion;
|
|
@@ -575740,6 +575982,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
575740
575982
|
exports.getOSInfo = exports.getPlatformRelease = void 0;
|
|
575741
575983
|
const os_1 = __importDefault(__webpack_require__(70857));
|
|
575742
575984
|
const macOSMap = new Map([
|
|
575985
|
+
[24, 'Sequoia'],
|
|
575986
|
+
[23, 'Sonoma'],
|
|
575987
|
+
[22, 'Ventura'],
|
|
575988
|
+
[21, 'Monterey'],
|
|
575743
575989
|
[20, 'BigSur'],
|
|
575744
575990
|
[19, 'Catalina'],
|
|
575745
575991
|
[18, 'Mojave'],
|
|
@@ -575755,9 +576001,19 @@ const macOSMap = new Map([
|
|
|
575755
576001
|
[8, 'Tiger'],
|
|
575756
576002
|
[7, 'Panther'],
|
|
575757
576003
|
[6, 'Jaguar'],
|
|
575758
|
-
[5, 'Puma']
|
|
576004
|
+
[5, 'Puma'] // macOS 10.1 Puma (2001)
|
|
575759
576005
|
]);
|
|
575760
576006
|
const winMap = new Map([
|
|
576007
|
+
['10.0.22000', '11'],
|
|
576008
|
+
['10.0.19041', '10'],
|
|
576009
|
+
['10.0.18363', '10'],
|
|
576010
|
+
['10.0.17763', '10'],
|
|
576011
|
+
['10.0.17134', '10'],
|
|
576012
|
+
['10.0.16299', '10'],
|
|
576013
|
+
['10.0.15063', '10'],
|
|
576014
|
+
['10.0.14393', '10'],
|
|
576015
|
+
['10.0.10586', '10'],
|
|
576016
|
+
['10.0.10240', '10'],
|
|
575761
576017
|
['10.0', '10'],
|
|
575762
576018
|
['6.3', '8.1'],
|
|
575763
576019
|
['6.2', '8'],
|
|
@@ -575768,28 +576024,55 @@ const winMap = new Map([
|
|
|
575768
576024
|
['5.0', '2000'],
|
|
575769
576025
|
['4.9', 'ME'],
|
|
575770
576026
|
['4.1', '98'],
|
|
575771
|
-
['4.0', '95']
|
|
576027
|
+
['4.0', '95'] // Windows 95 (1995)
|
|
575772
576028
|
]);
|
|
575773
576029
|
function getPlatformRelease(platform, release) {
|
|
576030
|
+
// macOS
|
|
575774
576031
|
if (platform === 'darwin') {
|
|
575775
|
-
const
|
|
575776
|
-
const
|
|
576032
|
+
const releaseParts = release.split('.');
|
|
576033
|
+
const majorNum = Number(releaseParts[0]);
|
|
576034
|
+
const minorNum = Number(releaseParts[1]) || 0;
|
|
576035
|
+
const name = macOSMap.get(majorNum) || 'macOS';
|
|
575777
576036
|
let version;
|
|
575778
|
-
|
|
575779
|
-
|
|
576037
|
+
// macOS 11 及以上版本 (majorNum >= 20)
|
|
576038
|
+
if (majorNum >= 20) {
|
|
576039
|
+
// releaseNum 20 -> macOS 11, 21 -> macOS 12, etc.
|
|
576040
|
+
const majorVersion = majorNum - 9;
|
|
576041
|
+
version = `${majorVersion}.${minorNum}`;
|
|
576042
|
+
// macOS 10.x 版本 (majorNum < 20)
|
|
575780
576043
|
}
|
|
575781
576044
|
else {
|
|
575782
|
-
|
|
576045
|
+
// releaseNum 19 -> 10.15, 18 -> 10.14, etc.
|
|
576046
|
+
const minorVersion = majorNum - 4;
|
|
576047
|
+
version = `10.${minorVersion}`;
|
|
575783
576048
|
}
|
|
575784
576049
|
return `${name} ${version}`;
|
|
575785
576050
|
}
|
|
576051
|
+
// windows
|
|
575786
576052
|
if (platform === 'win32') {
|
|
575787
|
-
|
|
575788
|
-
|
|
576053
|
+
// 尝试精确匹配完整版本号
|
|
576054
|
+
let windowsVersion = winMap.get(release);
|
|
576055
|
+
if (!windowsVersion) {
|
|
576056
|
+
// 如果没有精确匹配,尝试匹配主版本号
|
|
576057
|
+
const majorVersion = (/^\d+\.\d+/.exec(release) || [])[0];
|
|
576058
|
+
windowsVersion = winMap.get(majorVersion);
|
|
576059
|
+
}
|
|
576060
|
+
if (!windowsVersion) {
|
|
576061
|
+
// 如果还是没有匹配,尝试只匹配第一部分
|
|
576062
|
+
const firstPart = (/^\d+/.exec(release) || [])[0];
|
|
576063
|
+
if (firstPart === '10') {
|
|
576064
|
+
windowsVersion = '10';
|
|
576065
|
+
}
|
|
576066
|
+
}
|
|
576067
|
+
// 显示完整的版本信息
|
|
576068
|
+
const versionDisplay = windowsVersion || release;
|
|
576069
|
+
return `Windows ${versionDisplay}`;
|
|
575789
576070
|
}
|
|
576071
|
+
// 其他 Linux
|
|
575790
576072
|
return 'Linux';
|
|
575791
576073
|
}
|
|
575792
576074
|
exports.getPlatformRelease = getPlatformRelease;
|
|
576075
|
+
// 获取 hostname 和平台信息
|
|
575793
576076
|
function getOSInfo() {
|
|
575794
576077
|
const hostname = os_1.default.hostname();
|
|
575795
576078
|
const platform = os_1.default.platform();
|
|
@@ -578072,12 +578355,18 @@ function readFile(target) {
|
|
|
578072
578355
|
return '';
|
|
578073
578356
|
}
|
|
578074
578357
|
}
|
|
578358
|
+
// 从 env 文件中加载环境变量
|
|
578359
|
+
// 参考 https://cli.vuejs.org/zh/guide/mode-and-env.html
|
|
578075
578360
|
function loadEnvVariables(from = process.cwd()) {
|
|
578076
578361
|
const mode = yargs_1.default.argv.mode;
|
|
578362
|
+
// .env
|
|
578077
578363
|
const baseEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, '.env')));
|
|
578364
|
+
// .env.local
|
|
578078
578365
|
const localEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, '.env.local')));
|
|
578366
|
+
// .env.mode
|
|
578079
578367
|
const modeEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, `.env.${mode}`)));
|
|
578080
578368
|
const unionConfig = lodash_1.default.merge({}, baseEnv, localEnv, modeEnv);
|
|
578369
|
+
// 扩展 dotenv 解析模式,支持 functions.xxx=xxx 形式设置对象
|
|
578081
578370
|
return Object.keys(unionConfig).reduce((prev, key) => {
|
|
578082
578371
|
return lodash_1.default.set(prev, key, unionConfig[key]);
|
|
578083
578372
|
}, {});
|
|
@@ -581049,28 +581338,46 @@ module.exports = /*#__PURE__*/JSON.parse('{"name":"got","version":"9.6.0","descr
|
|
|
581049
581338
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
581050
581339
|
exports.nilCache = exports.memoryCache = exports.Cache = void 0;
|
|
581051
581340
|
class Entry {
|
|
581341
|
+
// eslint-disable-next-line
|
|
581052
581342
|
constructor(key, value, now, maxAge) {
|
|
581053
581343
|
this.key = key;
|
|
581054
581344
|
this.value = value;
|
|
581055
581345
|
this.now = now;
|
|
581056
581346
|
this.maxAge = maxAge;
|
|
581057
581347
|
}
|
|
581348
|
+
// 当前 entry 是否过期
|
|
581058
581349
|
isExpired() {
|
|
581059
581350
|
const now = Date.now();
|
|
581060
581351
|
return this.now + this.maxAge <= now;
|
|
581061
581352
|
}
|
|
581062
581353
|
}
|
|
581354
|
+
/**
|
|
581355
|
+
* 缓存模块
|
|
581356
|
+
* 1. 内存缓存
|
|
581357
|
+
* 2. TODO: 本地缓存
|
|
581358
|
+
*/
|
|
581063
581359
|
class Cache {
|
|
581064
581360
|
constructor(nil) {
|
|
581361
|
+
// use map to cache
|
|
581065
581362
|
this.store = new Map();
|
|
581066
581363
|
this.nil = false;
|
|
581067
581364
|
this.nil = nil;
|
|
581068
581365
|
}
|
|
581366
|
+
/**
|
|
581367
|
+
* 设置缓存
|
|
581368
|
+
* @param key 缓存 key
|
|
581369
|
+
* @param value 缓存值
|
|
581370
|
+
* @param maxAge 缓存保持时间,单位 ms
|
|
581371
|
+
*/
|
|
581069
581372
|
set(key, value, maxAge = 0) {
|
|
581070
581373
|
const now = maxAge ? Date.now() : 0;
|
|
581071
581374
|
const entry = new Entry(key, value, now, maxAge);
|
|
581072
581375
|
this.store.set(key, entry);
|
|
581073
581376
|
}
|
|
581377
|
+
/**
|
|
581378
|
+
* 获取缓存结果
|
|
581379
|
+
* @param key 缓存 key
|
|
581380
|
+
*/
|
|
581074
581381
|
get(key) {
|
|
581075
581382
|
const { nil } = this;
|
|
581076
581383
|
const entry = this.store.get(key);
|
|
@@ -581084,6 +581391,7 @@ class Cache {
|
|
|
581084
581391
|
}
|
|
581085
581392
|
}
|
|
581086
581393
|
exports.Cache = Cache;
|
|
581394
|
+
// 标志缓存不存在或过期
|
|
581087
581395
|
Cache.NIL = Symbol('NIL');
|
|
581088
581396
|
exports.memoryCache = new Cache();
|
|
581089
581397
|
exports.nilCache = new Cache(true);
|
|
@@ -605506,6 +605814,7 @@ class Explorer extends ExplorerBase_1.ExplorerBase {
|
|
|
605506
605814
|
return placeResult;
|
|
605507
605815
|
}
|
|
605508
605816
|
}
|
|
605817
|
+
// config not found
|
|
605509
605818
|
return null;
|
|
605510
605819
|
});
|
|
605511
605820
|
}
|
|
@@ -667635,12 +667944,15 @@ exports.execWithLoading = exports.loadingFactory = void 0;
|
|
|
667635
667944
|
const ora_1 = __importDefault(__webpack_require__(4539));
|
|
667636
667945
|
class Loading {
|
|
667637
667946
|
constructor() {
|
|
667947
|
+
// @ts-ignore
|
|
667638
667948
|
process.on('tcbExit', this.stop.bind(this));
|
|
667949
|
+
// @ts-ignore
|
|
667639
667950
|
process.on('tcbError', this.stop.bind(this));
|
|
667640
667951
|
this.spinner = (0, ora_1.default)({
|
|
667641
667952
|
discardStdin: false
|
|
667642
667953
|
});
|
|
667643
667954
|
}
|
|
667955
|
+
// eslint-disable-next-line
|
|
667644
667956
|
set text(text) {
|
|
667645
667957
|
this.spinner.text = text;
|
|
667646
667958
|
}
|
|
@@ -667667,9 +667979,15 @@ const loadingFactory = () => {
|
|
|
667667
667979
|
return new Loading();
|
|
667668
667980
|
};
|
|
667669
667981
|
exports.loadingFactory = loadingFactory;
|
|
667982
|
+
/**
|
|
667983
|
+
* 执行异步任务,显示 loading 动画
|
|
667984
|
+
* @param task
|
|
667985
|
+
* @param options
|
|
667986
|
+
*/
|
|
667670
667987
|
const execWithLoading = (task, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
667671
667988
|
const { startTip, successTip, failTip } = options;
|
|
667672
667989
|
const loading = (0, exports.loadingFactory)();
|
|
667990
|
+
// 刷新 loading 提示
|
|
667673
667991
|
const flush = (text) => {
|
|
667674
667992
|
loading.text = text;
|
|
667675
667993
|
};
|
|
@@ -673720,20 +674038,15 @@ exports.DefaultFunctionDeployConfig = {
|
|
|
673720
674038
|
ignore: ['node_modules', 'node_modules/**/*', '.git']
|
|
673721
674039
|
};
|
|
673722
674040
|
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' },
|
|
673725
674041
|
{ name: 'Node.js 20.19', value: 'Nodejs20.19', handler: 'index.main' },
|
|
673726
674042
|
{ name: 'Node.js 18.15', value: 'Nodejs18.15', handler: 'index.main' },
|
|
673727
674043
|
{ 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' },
|
|
673730
674044
|
{ name: 'Python 3.9', value: 'Python3.9', handler: 'index.main' },
|
|
673731
674045
|
{ name: 'Python 3.7', value: 'Python3.7', handler: 'index.main' },
|
|
673732
674046
|
{ name: 'PHP 8.0', value: 'Php8.0', handler: 'index.main' },
|
|
673733
674047
|
{ name: 'PHP 7.4', value: 'Php7.4', handler: 'index.main' },
|
|
673734
674048
|
{ name: 'Java 11', value: 'Java11', handler: 'example.Hello::mainHandler' },
|
|
673735
|
-
{ name: 'Java 8', value: 'Java8', handler: 'example.Hello::mainHandler' }
|
|
673736
|
-
{ name: 'Golang 1', value: 'Go1', handler: 'main' }
|
|
674049
|
+
{ name: 'Java 8', value: 'Java8', handler: 'example.Hello::mainHandler' }
|
|
673737
674050
|
];
|
|
673738
674051
|
exports.DefaultCloudBaseConfig = {
|
|
673739
674052
|
functionRoot: './functions',
|
|
@@ -681806,326 +682119,6 @@ exports.version = version
|
|
|
681806
682119
|
exports.defer = defer
|
|
681807
682120
|
|
|
681808
682121
|
|
|
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
|
-
|
|
682129
682122
|
/***/ }),
|
|
682130
682123
|
|
|
682131
682124
|
/***/ 64182:
|
|
@@ -697294,6 +697287,7 @@ module.exports = ({stream = process.stdout} = {}) => {
|
|
|
697294
697287
|
|
|
697295
697288
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
697296
697289
|
exports.getProxy = void 0;
|
|
697290
|
+
// 解析 Proxy 配置
|
|
697297
697291
|
function getProxy() {
|
|
697298
697292
|
const httpProxy = process.env.http_proxy ||
|
|
697299
697293
|
process.env.HTTP_PROXY ||
|
|
@@ -715268,12 +715262,17 @@ const getSearchPlaces = (moduleName) => [
|
|
|
715268
715262
|
`${moduleName}rc.js`,
|
|
715269
715263
|
`${moduleName}.config.js`
|
|
715270
715264
|
];
|
|
715265
|
+
/**
|
|
715266
|
+
* 搜索指定配置文件,返回包含路径等信息
|
|
715267
|
+
*/
|
|
715271
715268
|
function searchConfig(dest, moduleName = MODULE_NAME) {
|
|
715272
715269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715273
715270
|
const explorer = (0, explorer_1.cosmiconfig)(moduleName, {
|
|
715271
|
+
// 不向上搜索
|
|
715274
715272
|
stopDir: process.cwd(),
|
|
715275
715273
|
searchPlaces: getSearchPlaces(moduleName)
|
|
715276
715274
|
});
|
|
715275
|
+
// 搜索配置文件
|
|
715277
715276
|
try {
|
|
715278
715277
|
return explorer.search(dest || process.cwd());
|
|
715279
715278
|
}
|
|
@@ -715283,14 +715282,21 @@ function searchConfig(dest, moduleName = MODULE_NAME) {
|
|
|
715283
715282
|
});
|
|
715284
715283
|
}
|
|
715285
715284
|
exports.searchConfig = searchConfig;
|
|
715285
|
+
/**
|
|
715286
|
+
* 搜索或指定配置文件路径
|
|
715287
|
+
* 加载配置文件内容
|
|
715288
|
+
*/
|
|
715286
715289
|
function loadConfig(options = {}) {
|
|
715287
715290
|
return __awaiter(this, void 0, void 0, function* () {
|
|
715288
715291
|
const { moduleName = MODULE_NAME, configPath, searchFrom } = options;
|
|
715289
715292
|
const explorer = (0, explorer_1.cosmiconfig)(moduleName, {
|
|
715293
|
+
// 不向上搜索
|
|
715290
715294
|
stopDir: process.cwd(),
|
|
715291
715295
|
searchPlaces: getSearchPlaces(moduleName)
|
|
715292
715296
|
});
|
|
715297
|
+
// 从指定路径加载配置文件
|
|
715293
715298
|
if (configPath) {
|
|
715299
|
+
// 校验路径是否存在
|
|
715294
715300
|
(0, fs_1.checkReadable)(configPath, true);
|
|
715295
715301
|
try {
|
|
715296
715302
|
const result = yield explorer.load(configPath);
|
|
@@ -715305,6 +715311,7 @@ function loadConfig(options = {}) {
|
|
|
715305
715311
|
});
|
|
715306
715312
|
}
|
|
715307
715313
|
}
|
|
715314
|
+
// 搜索配置文件
|
|
715308
715315
|
try {
|
|
715309
715316
|
const result = yield searchConfig(searchFrom || process.cwd(), moduleName);
|
|
715310
715317
|
if (!result)
|
|
@@ -721024,6 +721031,7 @@ function cosmiconfig(moduleName, options = {}) {
|
|
|
721024
721031
|
};
|
|
721025
721032
|
}
|
|
721026
721033
|
exports.cosmiconfig = cosmiconfig;
|
|
721034
|
+
// do not allow mutation of default loaders. Make sure it is set inside options
|
|
721027
721035
|
const defaultLoaders = Object.freeze({
|
|
721028
721036
|
'.js': loaders_1.loaders.loadJs,
|
|
721029
721037
|
'.json': loaders_1.loaders.loadJson,
|
|
@@ -730446,11 +730454,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
730446
730454
|
};
|
|
730447
730455
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
730448
730456
|
exports.yaml = exports.yamlStringify = exports.yamlParse = void 0;
|
|
730457
|
+
// https://github.com/nodeca/js-yaml
|
|
730449
730458
|
const yaml_1 = __importDefault(__webpack_require__(61581));
|
|
730459
|
+
// 解析 YAML 字符串
|
|
730450
730460
|
const yamlParse = (doc) => {
|
|
730451
730461
|
return yaml_1.default.parse(doc);
|
|
730452
730462
|
};
|
|
730453
730463
|
exports.yamlParse = yamlParse;
|
|
730464
|
+
// 导出为 YAML 字符串
|
|
730454
730465
|
const yamlStringify = (object) => {
|
|
730455
730466
|
return yaml_1.default.stringify(object);
|
|
730456
730467
|
};
|
|
@@ -742784,24 +742795,38 @@ const common_1 = __webpack_require__(96711);
|
|
|
742784
742795
|
const coding_1 = __webpack_require__(40540);
|
|
742785
742796
|
const web_1 = __webpack_require__(2240);
|
|
742786
742797
|
const system_1 = __webpack_require__(62179);
|
|
742787
|
-
const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev
|
|
742798
|
+
const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev';
|
|
742799
|
+
// 打开云开发控制台,获取授权
|
|
742788
742800
|
function getAuthTokenFromWeb(options = {}) {
|
|
742789
742801
|
return __awaiter(this, void 0, void 0, function* () {
|
|
742790
|
-
const { getAuthUrl } = options;
|
|
742802
|
+
const { getAuthUrl, noBrowser, callbackTimeout } = options;
|
|
742791
742803
|
const mac = yield (0, system_1.getMacAddress)();
|
|
742792
742804
|
const os = (0, system_1.getOSInfo)();
|
|
742793
742805
|
const macHash = (0, coding_1.md5Encoding)(mac);
|
|
742794
742806
|
const query = yield (0, web_1.getDataFromWeb)((port) => {
|
|
742795
|
-
|
|
742807
|
+
const callbackUrl = `http://127.0.0.1:${port}`;
|
|
742808
|
+
const encodedQuery = `port=${encodeURIComponent(String(port))}`
|
|
742809
|
+
+ `&hash=${encodeURIComponent(macHash)}`
|
|
742810
|
+
+ `&mac=${encodeURIComponent(mac)}`
|
|
742811
|
+
+ `&os=${encodeURIComponent(os)}`
|
|
742812
|
+
+ '&from=cli';
|
|
742813
|
+
const encodedCallbackUrl = encodeURIComponent(callbackUrl);
|
|
742814
|
+
// 授权链接
|
|
742815
|
+
const rawAuthUrl = `${CliAuthBaseUrl}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
|
|
742816
|
+
let cliAuthUrl = rawAuthUrl;
|
|
742796
742817
|
if (getAuthUrl) {
|
|
742797
742818
|
try {
|
|
742798
|
-
cliAuthUrl = getAuthUrl(
|
|
742819
|
+
cliAuthUrl = getAuthUrl(rawAuthUrl);
|
|
742799
742820
|
}
|
|
742800
742821
|
catch (error) {
|
|
742822
|
+
// 忽略错误
|
|
742801
742823
|
}
|
|
742802
742824
|
}
|
|
742803
742825
|
return cliAuthUrl;
|
|
742804
|
-
}, 'login'
|
|
742826
|
+
}, 'login', {
|
|
742827
|
+
noBrowser,
|
|
742828
|
+
callbackTimeout
|
|
742829
|
+
});
|
|
742805
742830
|
const credential = (0, common_1.resolveCredential)(query);
|
|
742806
742831
|
return credential;
|
|
742807
742832
|
});
|
|
@@ -800695,7 +800720,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
800695
800720
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
800696
800721
|
};
|
|
800697
800722
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
800698
|
-
exports.
|
|
800723
|
+
exports.checkAndCreateBootstrap = exports.generateBootstrapContent = void 0;
|
|
800699
800724
|
const fs_1 = __importDefault(__webpack_require__(79896));
|
|
800700
800725
|
const path_1 = __importDefault(__webpack_require__(16928));
|
|
800701
800726
|
const inquirer_1 = __importDefault(__webpack_require__(6403));
|
|
@@ -800787,206 +800812,6 @@ function checkAndCreateBootstrap(functionPath, func, options = {}) {
|
|
|
800787
800812
|
});
|
|
800788
800813
|
}
|
|
800789
800814
|
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;
|
|
800990
800815
|
|
|
800991
800816
|
|
|
800992
800817
|
/***/ }),
|
|
@@ -834988,10 +834813,6 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
834988
834813
|
{
|
|
834989
834814
|
flags: '--deployMode <deployMode>',
|
|
834990
834815
|
desc: (0, i18n_1.t)('代码上传方式:cos(通过 COS 上传)或 zip(直接 ZIP 上传),默认自动选择')
|
|
834991
|
-
},
|
|
834992
|
-
{
|
|
834993
|
-
flags: '--yes',
|
|
834994
|
-
desc: (0, i18n_1.t)('跳过交互确认,使用推测或默认配置自动部署')
|
|
834995
834816
|
}
|
|
834996
834817
|
],
|
|
834997
834818
|
desc: (0, i18n_1.t)('部署云函数'),
|
|
@@ -835003,7 +834824,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835003
834824
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835004
834825
|
let { envId, config, options } = ctx;
|
|
835005
834826
|
const { functions } = config;
|
|
835006
|
-
const { force, codeSecret, path: access, all, dir, httpFn, ws, deployMode
|
|
834827
|
+
const { force, codeSecret, path: access, all, dir, httpFn, ws, deployMode } = options;
|
|
835007
834828
|
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
835008
834829
|
this.validateOptions({ deployMode, access }, log);
|
|
835009
834830
|
const isUnresolvedEnvId = !envId || envId.startsWith('{{');
|
|
@@ -835023,12 +834844,12 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835023
834844
|
if (hasConfig) {
|
|
835024
834845
|
return this.deployWithConfig({
|
|
835025
834846
|
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
835026
|
-
all, functions, functionRootPath,
|
|
834847
|
+
all, functions, functionRootPath, log
|
|
835027
834848
|
});
|
|
835028
834849
|
}
|
|
835029
834850
|
else {
|
|
835030
834851
|
return this.deployWithoutConfig({
|
|
835031
|
-
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
834852
|
+
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, log
|
|
835032
834853
|
});
|
|
835033
834854
|
}
|
|
835034
834855
|
});
|
|
@@ -835047,11 +834868,11 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835047
834868
|
}
|
|
835048
834869
|
deployWithConfig(options) {
|
|
835049
834870
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835050
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, all, functions, functionRootPath,
|
|
834871
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, all, functions, functionRootPath, log } = options;
|
|
835051
834872
|
if (name) {
|
|
835052
834873
|
return this.deploySingleWithConfig({
|
|
835053
834874
|
name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
835054
|
-
functions, functionRootPath,
|
|
834875
|
+
functions, functionRootPath, log
|
|
835055
834876
|
});
|
|
835056
834877
|
}
|
|
835057
834878
|
if (dir) {
|
|
@@ -835059,13 +834880,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835059
834880
|
}
|
|
835060
834881
|
return this.deployAllFunction({
|
|
835061
834882
|
all, envId, force, access, functions, codeSecret,
|
|
835062
|
-
functionRootPath, httpFn, ws, deployMode,
|
|
834883
|
+
functionRootPath, httpFn, ws, deployMode, log
|
|
835063
834884
|
});
|
|
835064
834885
|
});
|
|
835065
834886
|
}
|
|
835066
834887
|
deploySingleWithConfig(options) {
|
|
835067
834888
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835068
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, functions, functionRootPath,
|
|
834889
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, functions, functionRootPath, log } = options;
|
|
835069
834890
|
let func = functions === null || functions === void 0 ? void 0 : functions.find((item) => item.name === name);
|
|
835070
834891
|
let funcPath;
|
|
835071
834892
|
if (dir) {
|
|
@@ -835088,32 +834909,21 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835088
834909
|
}
|
|
835089
834910
|
if (!func) {
|
|
835090
834911
|
log.warn((0, i18n_1.t)('配置文件中未找到函数 [{{name}}] 的配置', { name }));
|
|
835091
|
-
|
|
835092
|
-
|
|
835093
|
-
|
|
835094
|
-
|
|
835095
|
-
|
|
835096
|
-
|
|
835097
|
-
|
|
835098
|
-
|
|
835099
|
-
|
|
835100
|
-
|
|
835101
|
-
|
|
835102
|
-
|
|
835103
|
-
|
|
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;
|
|
834912
|
+
const runtime = yield this.selectRuntime();
|
|
834913
|
+
const defaultFunc = Object.assign(Object.assign({ name }, constant_1.DefaultFunctionDeployConfig), { runtime });
|
|
834914
|
+
log.info((0, i18n_1.t)('将使用以下默认配置:'));
|
|
834915
|
+
this.printFunctionConfig(defaultFunc, log);
|
|
834916
|
+
const { confirm } = yield inquirer_1.default.prompt({
|
|
834917
|
+
type: 'confirm',
|
|
834918
|
+
name: 'confirm',
|
|
834919
|
+
message: (0, i18n_1.t)('是否使用默认配置继续部署?'),
|
|
834920
|
+
default: false
|
|
834921
|
+
});
|
|
834922
|
+
if (!confirm) {
|
|
834923
|
+
log.info((0, i18n_1.t)('已取消部署,请在配置文件中添加函数 [{{name}}] 的配置后重试', { name }));
|
|
834924
|
+
return;
|
|
835116
834925
|
}
|
|
834926
|
+
func = defaultFunc;
|
|
835117
834927
|
}
|
|
835118
834928
|
if (httpFn) {
|
|
835119
834929
|
func = Object.assign(Object.assign({}, func), { type: 'HTTP' });
|
|
@@ -835123,13 +834933,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835123
834933
|
}
|
|
835124
834934
|
return this.doDeploySingleFunction({
|
|
835125
834935
|
func, envId, force, codeSecret, access, deployMode,
|
|
835126
|
-
functionRootPath, functionPath: funcPath,
|
|
834936
|
+
functionRootPath, functionPath: funcPath, log
|
|
835127
834937
|
});
|
|
835128
834938
|
});
|
|
835129
834939
|
}
|
|
835130
834940
|
deployWithoutConfig(options) {
|
|
835131
834941
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835132
|
-
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode,
|
|
834942
|
+
const { name, dir, envId, force, codeSecret, access, httpFn, ws, deployMode, log } = options;
|
|
835133
834943
|
let deployDir = process.cwd();
|
|
835134
834944
|
if (dir) {
|
|
835135
834945
|
(0, utils_1.checkFullAccess)(dir, true);
|
|
@@ -835153,57 +834963,65 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835153
834963
|
if (ws && isInferred) {
|
|
835154
834964
|
inferredConfig = Object.assign(Object.assign({}, inferredConfig), { type: 'HTTP', protocolType: 'WS' });
|
|
835155
834965
|
}
|
|
835156
|
-
const sourceDesc = isInferred ? this.getConfigSourceDescription(deployDir) : (0, i18n_1.t)('默认配置');
|
|
835157
834966
|
if (isInferred) {
|
|
835158
|
-
log.info((0, i18n_1.t)('
|
|
834967
|
+
log.info((0, i18n_1.t)('从 package.json 推测出以下配置:'));
|
|
835159
834968
|
}
|
|
835160
834969
|
else {
|
|
835161
|
-
log.info((0, i18n_1.t)('
|
|
834970
|
+
log.info((0, i18n_1.t)('未推测出配置,将使用默认配置:'));
|
|
834971
|
+
}
|
|
834972
|
+
this.printFunctionConfig(inferredConfig, log);
|
|
834973
|
+
const { action } = yield inquirer_1.default.prompt({
|
|
834974
|
+
type: 'list',
|
|
834975
|
+
name: 'action',
|
|
834976
|
+
message: (0, i18n_1.t)('请选择操作'),
|
|
834977
|
+
choices: [
|
|
834978
|
+
{ name: (0, i18n_1.t)('使用当前配置部署'), value: 'deploy' },
|
|
834979
|
+
{ name: (0, i18n_1.t)('手动输入配置'), value: 'manual' },
|
|
834980
|
+
{ name: (0, i18n_1.t)('退出'), value: 'exit' }
|
|
834981
|
+
]
|
|
834982
|
+
});
|
|
834983
|
+
if (action === 'exit') {
|
|
834984
|
+
log.info((0, i18n_1.t)('已取消部署'));
|
|
834985
|
+
return;
|
|
835162
834986
|
}
|
|
835163
|
-
this.printFunctionConfig(inferredConfig, log, sourceDesc);
|
|
835164
834987
|
let func;
|
|
835165
|
-
if (
|
|
835166
|
-
|
|
835167
|
-
func = inferredConfig;
|
|
834988
|
+
if (action === 'manual') {
|
|
834989
|
+
func = yield this.promptFunctionConfig(inferredConfig, httpFn);
|
|
835168
834990
|
}
|
|
835169
834991
|
else {
|
|
835170
|
-
|
|
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
|
-
}
|
|
834992
|
+
func = inferredConfig;
|
|
835190
834993
|
}
|
|
835191
834994
|
return this.doDeploySingleFunction({
|
|
835192
834995
|
func, envId, force, codeSecret, access, deployMode,
|
|
835193
|
-
functionRootPath: deployDir, functionPath: '.',
|
|
834996
|
+
functionRootPath: deployDir, functionPath: '.', log
|
|
835194
834997
|
});
|
|
835195
834998
|
});
|
|
835196
834999
|
}
|
|
835197
835000
|
inferFunctionConfig(httpFn, deployDir) {
|
|
835198
835001
|
const targetDir = deployDir || process.cwd();
|
|
835199
|
-
const
|
|
835200
|
-
|
|
835002
|
+
const packageJsonPath = path_1.default.join(targetDir, 'package.json');
|
|
835003
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
835004
|
+
return null;
|
|
835005
|
+
}
|
|
835006
|
+
try {
|
|
835007
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf-8'));
|
|
835008
|
+
if (!packageJson.name) {
|
|
835009
|
+
return null;
|
|
835010
|
+
}
|
|
835011
|
+
let handler = constant_1.DefaultFunctionDeployConfig.handler;
|
|
835012
|
+
if (packageJson.main) {
|
|
835013
|
+
const mainFile = path_1.default.basename(packageJson.main).replace(/\.[^.]+$/, '');
|
|
835014
|
+
handler = `${mainFile}.main`;
|
|
835015
|
+
}
|
|
835016
|
+
return Object.assign(Object.assign(Object.assign({ name: packageJson.name }, constant_1.DefaultFunctionDeployConfig), { handler }), (httpFn ? { type: 'HTTP' } : {}));
|
|
835017
|
+
}
|
|
835018
|
+
catch (e) {
|
|
835019
|
+
return null;
|
|
835020
|
+
}
|
|
835201
835021
|
}
|
|
835202
|
-
promptFunctionConfig(defaultConfig, httpFn
|
|
835022
|
+
promptFunctionConfig(defaultConfig, httpFn) {
|
|
835203
835023
|
var _a, _b, _c;
|
|
835204
835024
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835205
|
-
const isHttpFnFromCli = httpFn || ws;
|
|
835206
|
-
const isWsFromCli = ws;
|
|
835207
835025
|
const answers = yield inquirer_1.default.prompt([
|
|
835208
835026
|
{
|
|
835209
835027
|
type: 'input',
|
|
@@ -835232,49 +835050,62 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835232
835050
|
name: 'handler',
|
|
835233
835051
|
message: (0, i18n_1.t)('入口函数(格式:文件名.函数名)'),
|
|
835234
835052
|
default: (answers) => {
|
|
835235
|
-
if (defaultConfig.handler) {
|
|
835236
|
-
return defaultConfig.handler;
|
|
835237
|
-
}
|
|
835238
835053
|
const selectedRuntime = constant_1.RuntimeOptions.find(r => r.value === answers.runtime);
|
|
835239
|
-
return (selectedRuntime === null || selectedRuntime === void 0 ? void 0 : selectedRuntime.handler) ||
|
|
835054
|
+
return (selectedRuntime === null || selectedRuntime === void 0 ? void 0 : selectedRuntime.handler) || defaultConfig.handler;
|
|
835240
835055
|
}
|
|
835241
835056
|
},
|
|
835242
835057
|
{
|
|
835243
835058
|
type: 'confirm',
|
|
835244
835059
|
name: 'isHttpFn',
|
|
835245
835060
|
message: (0, i18n_1.t)('是否为 HTTP 函数'),
|
|
835246
|
-
default:
|
|
835247
|
-
when: !
|
|
835061
|
+
default: httpFn || defaultConfig.type === 'HTTP',
|
|
835062
|
+
when: !httpFn
|
|
835248
835063
|
},
|
|
835249
835064
|
{
|
|
835250
835065
|
type: 'confirm',
|
|
835251
835066
|
name: 'enableWebSocket',
|
|
835252
835067
|
message: (0, i18n_1.t)('是否支持 WebSocket 协议'),
|
|
835253
|
-
default:
|
|
835254
|
-
when: (answers) =>
|
|
835068
|
+
default: defaultConfig.protocolType === 'WS',
|
|
835069
|
+
when: (answers) => httpFn || answers.isHttpFn
|
|
835255
835070
|
},
|
|
835256
835071
|
{
|
|
835257
835072
|
type: 'number',
|
|
835258
835073
|
name: 'timeout',
|
|
835259
835074
|
message: (answers) => {
|
|
835260
|
-
const isWs =
|
|
835075
|
+
const isWs = answers.enableWebSocket;
|
|
835261
835076
|
return isWs ? (0, i18n_1.t)('超时时间(秒,1-7200)') : (0, i18n_1.t)('超时时间(秒,1-900)');
|
|
835262
835077
|
},
|
|
835263
835078
|
default: defaultConfig.timeout,
|
|
835079
|
+
validate: (input, answers) => {
|
|
835080
|
+
const num = Number(input);
|
|
835081
|
+
const isWs = answers.enableWebSocket;
|
|
835082
|
+
const maxTimeout = isWs ? 7200 : 900;
|
|
835083
|
+
if (isNaN(num) || num < 1 || num > maxTimeout) {
|
|
835084
|
+
return isWs ? (0, i18n_1.t)('超时时间必须在 1-7200 秒之间') : (0, i18n_1.t)('超时时间必须在 1-900 秒之间');
|
|
835085
|
+
}
|
|
835086
|
+
return true;
|
|
835087
|
+
}
|
|
835264
835088
|
},
|
|
835265
835089
|
{
|
|
835266
835090
|
type: 'number',
|
|
835267
835091
|
name: 'idleTimeOut',
|
|
835268
835092
|
message: (0, i18n_1.t)('空闲超时时间(秒,10-7200,默认15)'),
|
|
835269
835093
|
default: ((_b = (_a = defaultConfig.protocolParams) === null || _a === void 0 ? void 0 : _a.wsParams) === null || _b === void 0 ? void 0 : _b.idleTimeOut) || 15,
|
|
835270
|
-
when: (answers) =>
|
|
835094
|
+
when: (answers) => answers.enableWebSocket,
|
|
835095
|
+
validate: (input) => {
|
|
835096
|
+
const num = Number(input);
|
|
835097
|
+
if (isNaN(num) || num < 10 || num > 7200) {
|
|
835098
|
+
return (0, i18n_1.t)('空闲超时时间必须在 10-7200 秒之间');
|
|
835099
|
+
}
|
|
835100
|
+
return true;
|
|
835101
|
+
}
|
|
835271
835102
|
},
|
|
835272
835103
|
{
|
|
835273
835104
|
type: 'confirm',
|
|
835274
835105
|
name: 'enableInstanceConcurrency',
|
|
835275
835106
|
message: (0, i18n_1.t)('是否启用多并发'),
|
|
835276
835107
|
default: !!defaultConfig.instanceConcurrencyConfig,
|
|
835277
|
-
when: (answers) =>
|
|
835108
|
+
when: (answers) => httpFn || answers.isHttpFn
|
|
835278
835109
|
},
|
|
835279
835110
|
{
|
|
835280
835111
|
type: 'number',
|
|
@@ -835310,16 +835141,15 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835310
835141
|
default: defaultConfig.installDependency
|
|
835311
835142
|
}
|
|
835312
835143
|
]);
|
|
835313
|
-
const
|
|
835314
|
-
const
|
|
835315
|
-
const protocolParams = (enableWs && answers.idleTimeOut) ? {
|
|
835144
|
+
const protocolType = answers.enableWebSocket ? 'WS' : undefined;
|
|
835145
|
+
const protocolParams = answers.idleTimeOut ? {
|
|
835316
835146
|
wsParams: { idleTimeOut: answers.idleTimeOut }
|
|
835317
835147
|
} : undefined;
|
|
835318
835148
|
const instanceConcurrencyConfig = answers.enableInstanceConcurrency ? {
|
|
835319
835149
|
dynamicEnabled: 'FALSE',
|
|
835320
835150
|
maxConcurrency: answers.maxConcurrency
|
|
835321
835151
|
} : undefined;
|
|
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 }, (
|
|
835152
|
+
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 }, (httpFn || answers.isHttpFn ? { type: 'HTTP' } : {})), (protocolType ? { protocolType } : {})), (protocolParams ? { protocolParams } : {})), (instanceConcurrencyConfig ? { instanceConcurrencyConfig } : {}));
|
|
835323
835153
|
});
|
|
835324
835154
|
}
|
|
835325
835155
|
promptFunctionName() {
|
|
@@ -835338,11 +835168,8 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835338
835168
|
return funcName.trim();
|
|
835339
835169
|
});
|
|
835340
835170
|
}
|
|
835341
|
-
printFunctionConfig(func, log
|
|
835171
|
+
printFunctionConfig(func, log) {
|
|
835342
835172
|
var _a, _b;
|
|
835343
|
-
if (source) {
|
|
835344
|
-
log.info((0, i18n_1.t)('配置来源:{{source}}', { source }));
|
|
835345
|
-
}
|
|
835346
835173
|
log.info((0, i18n_1.t)(' - 函数名称:{{name}}', { name: func.name }));
|
|
835347
835174
|
log.info((0, i18n_1.t)(' - 运行时:{{runtime}}', { runtime: func.runtime }));
|
|
835348
835175
|
log.info((0, i18n_1.t)(' - 入口函数:{{handler}}', { handler: func.handler }));
|
|
@@ -835365,65 +835192,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835365
835192
|
log.info((0, i18n_1.t)(' - 单实例最大并发数:{{num}}', { num: func.instanceConcurrencyConfig.maxConcurrency }));
|
|
835366
835193
|
}
|
|
835367
835194
|
}
|
|
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)('默认配置');
|
|
835423
835195
|
}
|
|
835424
835196
|
doDeploySingleFunction(options) {
|
|
835425
835197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835426
|
-
const { func, envId, force, codeSecret, access, deployMode, functionRootPath, functionPath,
|
|
835198
|
+
const { func, envId, force, codeSecret, access, deployMode, functionRootPath, functionPath, log } = options;
|
|
835427
835199
|
if (func.type === 'HTTP') {
|
|
835428
835200
|
const funcPath = functionPath === '.' ? process.cwd() : (functionPath || path_1.default.join(functionRootPath, func.name));
|
|
835429
835201
|
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(funcPath, func);
|
|
@@ -835457,7 +835229,6 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835457
835229
|
func,
|
|
835458
835230
|
accessPath: access,
|
|
835459
835231
|
functionPath,
|
|
835460
|
-
yes,
|
|
835461
835232
|
logger: log
|
|
835462
835233
|
});
|
|
835463
835234
|
}
|
|
@@ -835469,7 +835240,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835469
835240
|
}
|
|
835470
835241
|
deployAllFunction(options) {
|
|
835471
835242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835472
|
-
let { functions = [], envId, force, codeSecret, functionRootPath, all, access, httpFn, ws, deployMode,
|
|
835243
|
+
let { functions = [], envId, force, codeSecret, functionRootPath, all, access, httpFn, ws, deployMode, log } = options;
|
|
835473
835244
|
if (!functions || functions.length === 0) {
|
|
835474
835245
|
functions = this.scanFunctionDirectory(functionRootPath, httpFn);
|
|
835475
835246
|
if (functions.length > 0) {
|
|
@@ -835486,7 +835257,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835486
835257
|
throw new error_1.CloudBaseError((0, i18n_1.t)('未找到云函数配置,请在 cloudbaserc.json 中配置 functions 字段,或使用 tcb fn deploy <函数名> 指定要部署的函数'));
|
|
835487
835258
|
}
|
|
835488
835259
|
let selectedFunctions = functions;
|
|
835489
|
-
if (!all
|
|
835260
|
+
if (!all) {
|
|
835490
835261
|
const choices = functions.map((func) => ({
|
|
835491
835262
|
name: `${func.name}${func.type === 'HTTP' ? ' (HTTP)' : ''}${func.protocolType === 'WS' ? ' (WS)' : ''}`,
|
|
835492
835263
|
value: func.name,
|
|
@@ -835519,54 +835290,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835519
835290
|
throw new error_1.CloudBaseError((0, i18n_1.t)('没有选择任何云函数'));
|
|
835520
835291
|
}
|
|
835521
835292
|
}
|
|
835522
|
-
else if (yes) {
|
|
835523
|
-
log.info((0, i18n_1.t)('🚀 --yes 模式:自动部署全部 {{count}} 个函数', { count: functions.length }));
|
|
835524
|
-
}
|
|
835525
835293
|
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
|
-
}
|
|
835570
835294
|
const tasks = selectedFunctions.map((func) => () => __awaiter(this, void 0, void 0, function* () {
|
|
835571
835295
|
let funcWithType = httpFn ? Object.assign(Object.assign({}, func), { type: 'HTTP' }) : func;
|
|
835572
835296
|
if (ws) {
|
|
@@ -835577,13 +835301,13 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835577
835301
|
: path_1.default.join(functionRootPath, func.name);
|
|
835578
835302
|
if (!fs_1.default.existsSync(funcPath)) {
|
|
835579
835303
|
log.error((0, i18n_1.t)('未找到函数 [{{name}}] 的目录:{{path}},已跳过', { name: func.name, path: funcPath }));
|
|
835580
|
-
return
|
|
835304
|
+
return;
|
|
835581
835305
|
}
|
|
835582
835306
|
if (funcWithType.type === 'HTTP') {
|
|
835583
835307
|
const shouldContinue = yield (0, function_1.checkAndCreateBootstrap)(funcPath, funcWithType);
|
|
835584
835308
|
if (!shouldContinue) {
|
|
835585
835309
|
log.warn((0, i18n_1.t)('[{{name}}] 已跳过部署', { name: func.name }));
|
|
835586
|
-
return
|
|
835310
|
+
return;
|
|
835587
835311
|
}
|
|
835588
835312
|
}
|
|
835589
835313
|
loading.start((0, i18n_1.t)('云函数部署中'));
|
|
@@ -835599,11 +835323,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835599
835323
|
deployMode
|
|
835600
835324
|
});
|
|
835601
835325
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功', { name: func.name }));
|
|
835602
|
-
return { status: 'success', name: func.name };
|
|
835603
835326
|
}
|
|
835604
835327
|
catch (e) {
|
|
835605
835328
|
loading.stop();
|
|
835606
|
-
|
|
835329
|
+
yield this.handleDeployFail(e, {
|
|
835607
835330
|
func: funcWithType,
|
|
835608
835331
|
envId,
|
|
835609
835332
|
force,
|
|
@@ -835611,10 +835334,8 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835611
835334
|
functionRootPath,
|
|
835612
835335
|
functionPath: func.dir ? funcPath : undefined,
|
|
835613
835336
|
accessPath: access,
|
|
835614
|
-
shouldOverwrite: yes || functionsToOverwrite.has(func.name),
|
|
835615
835337
|
logger: log
|
|
835616
835338
|
});
|
|
835617
|
-
return { status: result || 'error', name: func.name, error: result === 'error' ? e : undefined };
|
|
835618
835339
|
}
|
|
835619
835340
|
}));
|
|
835620
835341
|
if (tasks.length > 5) {
|
|
@@ -835623,113 +835344,25 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835623
835344
|
const asyncTaskController = new utils_1.AsyncTaskParallelController(5, 50);
|
|
835624
835345
|
asyncTaskController.loadTasks(tasks);
|
|
835625
835346
|
const results = yield asyncTaskController.run();
|
|
835626
|
-
const
|
|
835627
|
-
|
|
835628
|
-
const
|
|
835629
|
-
|
|
835630
|
-
|
|
835631
|
-
|
|
835632
|
-
|
|
835633
|
-
|
|
835634
|
-
log.warn((0, i18n_1.t)('跳过 {{count}} 个函数', { count: skippedCount }));
|
|
835635
|
-
}
|
|
835636
|
-
if (cancelledCount > 0) {
|
|
835637
|
-
log.info((0, i18n_1.t)('取消部署 {{count}} 个函数', { count: cancelledCount }));
|
|
835638
|
-
}
|
|
835639
|
-
if (errorCount > 0) {
|
|
835640
|
-
log.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: errorCount }));
|
|
835641
|
-
results.filter(r => (r === null || r === void 0 ? void 0 : r.status) === 'error').forEach((r) => {
|
|
835642
|
-
var _a;
|
|
835643
|
-
if ((_a = r === null || r === void 0 ? void 0 : r.error) === null || _a === void 0 ? void 0 : _a.message) {
|
|
835644
|
-
log.error(` - [${r.name}] ${r.error.message}`);
|
|
835347
|
+
const success = results.filter((_) => !_);
|
|
835348
|
+
log.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: success === null || success === void 0 ? void 0 : success.length }));
|
|
835349
|
+
const errors = results.filter((_) => _);
|
|
835350
|
+
if (errors === null || errors === void 0 ? void 0 : errors.length) {
|
|
835351
|
+
log.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: errors === null || errors === void 0 ? void 0 : errors.length }));
|
|
835352
|
+
errors.forEach((err) => {
|
|
835353
|
+
if (err === null || err === void 0 ? void 0 : err.message) {
|
|
835354
|
+
log.error(` - ${err.message}`);
|
|
835645
835355
|
}
|
|
835646
835356
|
});
|
|
835647
835357
|
}
|
|
835648
|
-
if (successCount === 0 && errorCount === 0 && skippedCount === 0 && cancelledCount === 0) {
|
|
835649
|
-
log.info((0, i18n_1.t)('没有函数被部署'));
|
|
835650
|
-
}
|
|
835651
|
-
});
|
|
835652
|
-
}
|
|
835653
|
-
handleDeployFailBatch(e, options) {
|
|
835654
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
835655
|
-
const { envId, codeSecret, functionRootPath, func: originalFunc, functionPath, accessPath, force: forceOverwrite, shouldOverwrite, logger: log } = options;
|
|
835656
|
-
let func = originalFunc;
|
|
835657
|
-
const loading = (0, utils_1.loadingFactory)();
|
|
835658
|
-
const isResourceInUseError = e.code === 'ResourceInUse.FunctionName'
|
|
835659
|
-
|| e.code === 'ResourceInUse.Function'
|
|
835660
|
-
|| (e.message && e.message.includes('ResourceInUse.FunctionName'))
|
|
835661
|
-
|| (e.message && e.message.includes('ResourceInUse.Function'));
|
|
835662
|
-
if (isResourceInUseError) {
|
|
835663
|
-
const functionService = yield (0, function_2.getFunctionService)(envId);
|
|
835664
|
-
const existingFunction = yield functionService.getFunctionDetail(func.name, codeSecret);
|
|
835665
|
-
const existingType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.Type) || 'Event';
|
|
835666
|
-
const newType = func.type || existingType;
|
|
835667
|
-
if (func.type && existingType !== newType) {
|
|
835668
|
-
(log || utils_1.logger).error((0, i18n_1.t)('不支持变更函数类型:云端函数 [{{name}}] 类型为 {{existingType}},无法变更为 {{newType}}', {
|
|
835669
|
-
name: func.name,
|
|
835670
|
-
existingType,
|
|
835671
|
-
newType
|
|
835672
|
-
}));
|
|
835673
|
-
return 'error';
|
|
835674
|
-
}
|
|
835675
|
-
const existingProtocolType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.ProtocolType) || '';
|
|
835676
|
-
const newProtocolType = func.protocolType !== undefined ? func.protocolType : existingProtocolType;
|
|
835677
|
-
if (func.protocolType !== undefined && existingProtocolType !== newProtocolType) {
|
|
835678
|
-
(log || utils_1.logger).error((0, i18n_1.t)('不支持变更协议类型:云端函数 [{{name}}] 协议类型为 {{existingProtocolType}},本地配置为 {{newProtocolType}},协议类型仅支持在创建函数时设置', {
|
|
835679
|
-
name: func.name,
|
|
835680
|
-
existingProtocolType: existingProtocolType || '无',
|
|
835681
|
-
newProtocolType: newProtocolType || '无'
|
|
835682
|
-
}));
|
|
835683
|
-
return 'error';
|
|
835684
|
-
}
|
|
835685
|
-
func = Object.assign(Object.assign({}, func), { type: newType, protocolType: newProtocolType || undefined });
|
|
835686
|
-
const shouldForce = forceOverwrite || shouldOverwrite;
|
|
835687
|
-
if (shouldForce) {
|
|
835688
|
-
loading.start((0, i18n_1.t)('云函数 [{{name}}] 更新部署中...', { name: func.name }));
|
|
835689
|
-
try {
|
|
835690
|
-
yield (0, function_2.updateFunctionCode)({
|
|
835691
|
-
func,
|
|
835692
|
-
envId,
|
|
835693
|
-
codeSecret,
|
|
835694
|
-
functionRootPath,
|
|
835695
|
-
functionPath
|
|
835696
|
-
});
|
|
835697
|
-
const success = yield this.waitForFunctionReady(envId, func.name, loading);
|
|
835698
|
-
if (!success) {
|
|
835699
|
-
return 'error';
|
|
835700
|
-
}
|
|
835701
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
|
|
835702
|
-
yield (0, function_2.updateFunctionConfig)({
|
|
835703
|
-
envId,
|
|
835704
|
-
functionName: func.name,
|
|
835705
|
-
config: func
|
|
835706
|
-
});
|
|
835707
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
|
|
835708
|
-
return 'success';
|
|
835709
|
-
}
|
|
835710
|
-
catch (e) {
|
|
835711
|
-
loading.stop();
|
|
835712
|
-
throw e;
|
|
835713
|
-
}
|
|
835714
|
-
}
|
|
835715
|
-
else {
|
|
835716
|
-
(log || utils_1.logger).info((0, i18n_1.t)('[{{name}}] 已跳过部署', { name: func.name }));
|
|
835717
|
-
return 'cancelled';
|
|
835718
|
-
}
|
|
835719
|
-
}
|
|
835720
|
-
throw e;
|
|
835721
835358
|
});
|
|
835722
835359
|
}
|
|
835723
835360
|
handleDeployFail(e, options) {
|
|
835724
835361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
835725
|
-
const { envId, codeSecret, functionRootPath, func: originalFunc, functionPath, accessPath, force: forceOverwrite,
|
|
835362
|
+
const { envId, codeSecret, functionRootPath, func: originalFunc, functionPath, accessPath, force: forceOverwrite, logger: log } = options;
|
|
835726
835363
|
let func = originalFunc;
|
|
835727
835364
|
const loading = (0, utils_1.loadingFactory)();
|
|
835728
|
-
|
|
835729
|
-
|| e.code === 'ResourceInUse.Function'
|
|
835730
|
-
|| (e.message && e.message.includes('ResourceInUse.FunctionName'))
|
|
835731
|
-
|| (e.message && e.message.includes('ResourceInUse.Function'));
|
|
835732
|
-
if (isResourceInUseError) {
|
|
835365
|
+
if (e.code === 'ResourceInUse.FunctionName' || e.code === 'ResourceInUse.Function') {
|
|
835733
835366
|
const functionService = yield (0, function_2.getFunctionService)(envId);
|
|
835734
835367
|
const existingFunction = yield functionService.getFunctionDetail(func.name, codeSecret);
|
|
835735
835368
|
const existingType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.Type) || 'Event';
|
|
@@ -835740,7 +835373,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835740
835373
|
existingType,
|
|
835741
835374
|
newType
|
|
835742
835375
|
}));
|
|
835743
|
-
return
|
|
835376
|
+
return;
|
|
835744
835377
|
}
|
|
835745
835378
|
const existingProtocolType = (existingFunction === null || existingFunction === void 0 ? void 0 : existingFunction.ProtocolType) || '';
|
|
835746
835379
|
const newProtocolType = func.protocolType !== undefined ? func.protocolType : existingProtocolType;
|
|
@@ -835750,10 +835383,10 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835750
835383
|
existingProtocolType: existingProtocolType || '无',
|
|
835751
835384
|
newProtocolType: newProtocolType || '无'
|
|
835752
835385
|
}));
|
|
835753
|
-
return
|
|
835386
|
+
return;
|
|
835754
835387
|
}
|
|
835755
835388
|
func = Object.assign(Object.assign({}, func), { type: newType, protocolType: newProtocolType || undefined });
|
|
835756
|
-
let shouldForce = forceOverwrite
|
|
835389
|
+
let shouldForce = forceOverwrite;
|
|
835757
835390
|
if (!shouldForce) {
|
|
835758
835391
|
const answer = yield inquirer_1.default.prompt({
|
|
835759
835392
|
type: 'confirm',
|
|
@@ -835776,7 +835409,7 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835776
835409
|
});
|
|
835777
835410
|
const success = yield this.waitForFunctionReady(envId, func.name, loading);
|
|
835778
835411
|
if (!success) {
|
|
835779
|
-
return
|
|
835412
|
+
return;
|
|
835780
835413
|
}
|
|
835781
835414
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
|
|
835782
835415
|
yield (0, function_2.updateFunctionConfig)({
|
|
@@ -835786,7 +835419,6 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835786
835419
|
});
|
|
835787
835420
|
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
|
|
835788
835421
|
yield this.printSuccessTips(envId);
|
|
835789
|
-
return 'success';
|
|
835790
835422
|
}
|
|
835791
835423
|
catch (e) {
|
|
835792
835424
|
loading.stop();
|
|
@@ -835795,8 +835427,8 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835795
835427
|
}
|
|
835796
835428
|
else {
|
|
835797
835429
|
(log || utils_1.logger).info((0, i18n_1.t)('已取消部署'));
|
|
835798
|
-
return 'cancelled';
|
|
835799
835430
|
}
|
|
835431
|
+
return;
|
|
835800
835432
|
}
|
|
835801
835433
|
throw e;
|
|
835802
835434
|
});
|
|
@@ -835914,59 +835546,6 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
835914
835546
|
return runtime;
|
|
835915
835547
|
});
|
|
835916
835548
|
}
|
|
835917
|
-
getDefaultRuntime(targetDir) {
|
|
835918
|
-
var _a;
|
|
835919
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
835920
|
-
const dir = targetDir || process.cwd();
|
|
835921
|
-
if (fs_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
|
|
835922
|
-
try {
|
|
835923
|
-
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(dir, 'package.json'), 'utf-8'));
|
|
835924
|
-
if ((_a = packageJson.engines) === null || _a === void 0 ? void 0 : _a.node) {
|
|
835925
|
-
const nodeVersion = packageJson.engines.node;
|
|
835926
|
-
if (nodeVersion.includes('20'))
|
|
835927
|
-
return 'Nodejs20.19';
|
|
835928
|
-
if (nodeVersion.includes('16'))
|
|
835929
|
-
return 'Nodejs16.13';
|
|
835930
|
-
}
|
|
835931
|
-
}
|
|
835932
|
-
catch (e) {
|
|
835933
|
-
}
|
|
835934
|
-
return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835935
|
-
}
|
|
835936
|
-
const pythonFiles = ['requirements.txt', 'setup.py', 'pyproject.toml'];
|
|
835937
|
-
if (pythonFiles.some(file => fs_1.default.existsSync(path_1.default.join(dir, file)))) {
|
|
835938
|
-
return 'Python3.9';
|
|
835939
|
-
}
|
|
835940
|
-
if (fs_1.default.existsSync(path_1.default.join(dir, 'composer.json')) ||
|
|
835941
|
-
fs_1.default.readdirSync(dir).some(file => file.endsWith('.php'))) {
|
|
835942
|
-
return 'Php8.0';
|
|
835943
|
-
}
|
|
835944
|
-
const javaFiles = ['pom.xml', 'build.gradle', 'build.gradle.kts'];
|
|
835945
|
-
if (javaFiles.some(file => fs_1.default.existsSync(path_1.default.join(dir, file)))) {
|
|
835946
|
-
return 'Java11';
|
|
835947
|
-
}
|
|
835948
|
-
try {
|
|
835949
|
-
const files = fs_1.default.readdirSync(dir);
|
|
835950
|
-
const fileTypes = {
|
|
835951
|
-
js: files.filter(f => f.endsWith('.js')).length,
|
|
835952
|
-
ts: files.filter(f => f.endsWith('.ts')).length,
|
|
835953
|
-
py: files.filter(f => f.endsWith('.py')).length,
|
|
835954
|
-
php: files.filter(f => f.endsWith('.php')).length,
|
|
835955
|
-
java: files.filter(f => f.endsWith('.java')).length
|
|
835956
|
-
};
|
|
835957
|
-
const maxType = Object.entries(fileTypes).reduce((a, b) => fileTypes[a[0]] > fileTypes[b[0]] ? a : b);
|
|
835958
|
-
switch (maxType[0]) {
|
|
835959
|
-
case 'py': return 'Python3.9';
|
|
835960
|
-
case 'php': return 'Php8.0';
|
|
835961
|
-
case 'java': return 'Java11';
|
|
835962
|
-
default: return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835963
|
-
}
|
|
835964
|
-
}
|
|
835965
|
-
catch (e) {
|
|
835966
|
-
return constant_1.DefaultFunctionDeployConfig.runtime;
|
|
835967
|
-
}
|
|
835968
|
-
});
|
|
835969
|
-
}
|
|
835970
835549
|
};
|
|
835971
835550
|
__decorate([
|
|
835972
835551
|
(0, decorators_1.InjectParams)(),
|
|
@@ -864569,6 +864148,7 @@ module.exports = exports
|
|
|
864569
864148
|
|
|
864570
864149
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
864571
864150
|
exports.detectIndent = void 0;
|
|
864151
|
+
// https://github.com/sindresorhus/detect-indent/blob/master/index.js
|
|
864572
864152
|
const INDENT_REGEX = /^(?:( )+|\t+)/;
|
|
864573
864153
|
const INDENT_TYPE_SPACE = 'space';
|
|
864574
864154
|
const INDENT_TYPE_TAB = 'tab';
|
|
@@ -864579,6 +864159,7 @@ function makeIndentsMap(string) {
|
|
|
864579
864159
|
let key;
|
|
864580
864160
|
for (const line of string.split(/\n/g)) {
|
|
864581
864161
|
if (!line) {
|
|
864162
|
+
// Ignore empty lines
|
|
864582
864163
|
continue;
|
|
864583
864164
|
}
|
|
864584
864165
|
let indent;
|
|
@@ -864605,16 +864186,19 @@ function makeIndentsMap(string) {
|
|
|
864605
864186
|
weight = 0;
|
|
864606
864187
|
const indentDifference = indent - previousSize;
|
|
864607
864188
|
previousSize = indent;
|
|
864189
|
+
// Previous line have same indent?
|
|
864608
864190
|
if (indentDifference === 0) {
|
|
864609
864191
|
weight++;
|
|
864192
|
+
// We use the key from previous loop
|
|
864610
864193
|
}
|
|
864611
864194
|
else {
|
|
864612
864195
|
const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
|
|
864613
864196
|
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
864614
864197
|
}
|
|
864198
|
+
// Update the stats
|
|
864615
864199
|
entry = indents.get(key);
|
|
864616
864200
|
if (entry === undefined) {
|
|
864617
|
-
entry = [1, 0];
|
|
864201
|
+
entry = [1, 0]; // Init
|
|
864618
864202
|
}
|
|
864619
864203
|
else {
|
|
864620
864204
|
entry = [++entry[0], entry[1] + weight];
|
|
@@ -864624,16 +864208,20 @@ function makeIndentsMap(string) {
|
|
|
864624
864208
|
}
|
|
864625
864209
|
return indents;
|
|
864626
864210
|
}
|
|
864211
|
+
// Encode the indent type and amount as a string (e.g. 's4') for use as a compound key in the indents Map.
|
|
864627
864212
|
function encodeIndentsKey(indentType, indentAmount) {
|
|
864628
864213
|
const typeCharacter = indentType === INDENT_TYPE_SPACE ? 's' : 't';
|
|
864629
864214
|
return typeCharacter + String(indentAmount);
|
|
864630
864215
|
}
|
|
864216
|
+
// Extract the indent type and amount from a key of the indents Map.
|
|
864631
864217
|
function decodeIndentsKey(indentsKey) {
|
|
864632
864218
|
const keyHasTypeSpace = indentsKey[0] === 's';
|
|
864633
864219
|
const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
864634
864220
|
const amount = Number(indentsKey.slice(1));
|
|
864635
864221
|
return { type, amount };
|
|
864636
864222
|
}
|
|
864223
|
+
// Return the key (e.g. 's4') from the indents Map that represents the most common indent,
|
|
864224
|
+
// or return undefined if there are no indents.
|
|
864637
864225
|
function getMostUsedKey(indents) {
|
|
864638
864226
|
let result;
|
|
864639
864227
|
let maxUsed = 0;
|
|
@@ -895152,8 +894740,14 @@ const fs_1 = __importDefault(__webpack_require__(79896));
|
|
|
895152
894740
|
const del_1 = __importDefault(__webpack_require__(62958));
|
|
895153
894741
|
const make_dir_1 = __importDefault(__webpack_require__(55589));
|
|
895154
894742
|
const error_1 = __webpack_require__(64119);
|
|
894743
|
+
/**
|
|
894744
|
+
* 检查路径是否可以访问(读、写)
|
|
894745
|
+
* @param dest 目标路径
|
|
894746
|
+
* @param throwError 无权限时是否抛出异常
|
|
894747
|
+
*/
|
|
895155
894748
|
function checkFullAccess(dest, throwError = false) {
|
|
895156
894749
|
try {
|
|
894750
|
+
// 可见、可写
|
|
895157
894751
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
895158
894752
|
fs_1.default.accessSync(dest, fs_1.default.constants.W_OK);
|
|
895159
894753
|
fs_1.default.accessSync(dest, fs_1.default.constants.R_OK);
|
|
@@ -895169,8 +894763,14 @@ function checkFullAccess(dest, throwError = false) {
|
|
|
895169
894763
|
}
|
|
895170
894764
|
}
|
|
895171
894765
|
exports.checkFullAccess = checkFullAccess;
|
|
894766
|
+
/**
|
|
894767
|
+
* 检查路径是否可以读
|
|
894768
|
+
* @param dest 目标路径
|
|
894769
|
+
* @param throwError 无权限时是否抛出异常
|
|
894770
|
+
*/
|
|
895172
894771
|
function checkWritable(dest, throwError = false) {
|
|
895173
894772
|
try {
|
|
894773
|
+
// 可见、可写
|
|
895174
894774
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
895175
894775
|
fs_1.default.accessSync(dest, fs_1.default.constants.W_OK);
|
|
895176
894776
|
return true;
|
|
@@ -895185,8 +894785,14 @@ function checkWritable(dest, throwError = false) {
|
|
|
895185
894785
|
}
|
|
895186
894786
|
}
|
|
895187
894787
|
exports.checkWritable = checkWritable;
|
|
894788
|
+
/**
|
|
894789
|
+
* 检查路径是否可以写
|
|
894790
|
+
* @param dest 目标路径
|
|
894791
|
+
* @param throwError 无权限或路径不存在时是否抛出异常
|
|
894792
|
+
*/
|
|
895188
894793
|
function checkReadable(dest, throwError = false) {
|
|
895189
894794
|
try {
|
|
894795
|
+
// 可见、可读
|
|
895190
894796
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
895191
894797
|
fs_1.default.accessSync(dest, fs_1.default.constants.R_OK);
|
|
895192
894798
|
return true;
|
|
@@ -895201,10 +894807,18 @@ function checkReadable(dest, throwError = false) {
|
|
|
895201
894807
|
}
|
|
895202
894808
|
}
|
|
895203
894809
|
exports.checkReadable = checkReadable;
|
|
894810
|
+
/**
|
|
894811
|
+
* 检查指定路径是否为文件夹
|
|
894812
|
+
* @param dest 目标路径
|
|
894813
|
+
*/
|
|
895204
894814
|
function isDirectorySync(dest) {
|
|
895205
894815
|
return fs_1.default.statSync(dest).isDirectory();
|
|
895206
894816
|
}
|
|
895207
894817
|
exports.isDirectorySync = isDirectorySync;
|
|
894818
|
+
/**
|
|
894819
|
+
* 检查指定路径是否为文件夹,异步
|
|
894820
|
+
* @param dest 目标路径
|
|
894821
|
+
*/
|
|
895208
894822
|
function isDirectoryAsync(dest) {
|
|
895209
894823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
895210
894824
|
const stat = yield fs_1.default.promises.stat(dest);
|
|
@@ -895212,6 +894826,12 @@ function isDirectoryAsync(dest) {
|
|
|
895212
894826
|
});
|
|
895213
894827
|
}
|
|
895214
894828
|
exports.isDirectoryAsync = isDirectoryAsync;
|
|
894829
|
+
/**
|
|
894830
|
+
* 格式化文件大小,保留两位小数
|
|
894831
|
+
* @param size 原数据,单位 Byte
|
|
894832
|
+
* @param unit 目标单位,支持 KB、MB、GB、TB
|
|
894833
|
+
* @param fixed 保留小数位数,默认 2 位
|
|
894834
|
+
*/
|
|
895215
894835
|
function formateFileSize(size, unit, fixed) {
|
|
895216
894836
|
const numSize = Number(size);
|
|
895217
894837
|
const unitMap = {
|
|
@@ -895223,6 +894843,7 @@ function formateFileSize(size, unit, fixed) {
|
|
|
895223
894843
|
return Number(numSize / unitMap[unit]).toFixed(fixed);
|
|
895224
894844
|
}
|
|
895225
894845
|
exports.formateFileSize = formateFileSize;
|
|
894846
|
+
// 创建文件夹
|
|
895226
894847
|
function mkdirSync(dest) {
|
|
895227
894848
|
make_dir_1.default.sync(dest);
|
|
895228
894849
|
}
|
|
@@ -895233,6 +894854,7 @@ function mkdirAsync(dest) {
|
|
|
895233
894854
|
});
|
|
895234
894855
|
}
|
|
895235
894856
|
exports.mkdirAsync = mkdirAsync;
|
|
894857
|
+
// 转换 Windows 下的反斜杠路径
|
|
895236
894858
|
const slash = (input) => {
|
|
895237
894859
|
const isExtendedLengthPath = /^\\\\\?\\/.test(input);
|
|
895238
894860
|
if (isExtendedLengthPath) {
|
|
@@ -895241,8 +894863,10 @@ const slash = (input) => {
|
|
|
895241
894863
|
return input.replace(/\\/g, '/');
|
|
895242
894864
|
};
|
|
895243
894865
|
exports.slash = slash;
|
|
894866
|
+
// 删除文件
|
|
895244
894867
|
function delSync(patterns) {
|
|
895245
894868
|
let paths;
|
|
894869
|
+
// 不能再使用反斜杠,修复 Windows 下的问题 https://github.com/sindresorhus/del/releases/tag/v5.0.0
|
|
895246
894870
|
if (Array.isArray(patterns)) {
|
|
895247
894871
|
paths = patterns.map((item) => (0, exports.slash)(item));
|
|
895248
894872
|
}
|
|
@@ -899125,8 +898749,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
899125
898749
|
exports.resolveWebCredential = exports.resolveCredential = exports.checkAuth = void 0;
|
|
899126
898750
|
const cloud_api_1 = __webpack_require__(2090);
|
|
899127
898751
|
const config_1 = __webpack_require__(88472);
|
|
898752
|
+
// 调用 env:list 接口,检查密钥是否有效
|
|
899128
898753
|
function checkAuth(credential, options = {}) {
|
|
899129
898754
|
return __awaiter(this, void 0, void 0, function* () {
|
|
898755
|
+
// 兼容原临时秘钥
|
|
899130
898756
|
const { secretId, secretKey, token } = resolveCredential(credential);
|
|
899131
898757
|
const { proxy, timeout } = options;
|
|
899132
898758
|
const region = yield (0, config_1.getRegion)();
|
|
@@ -899147,8 +898773,10 @@ function checkAuth(credential, options = {}) {
|
|
|
899147
898773
|
});
|
|
899148
898774
|
}
|
|
899149
898775
|
exports.checkAuth = checkAuth;
|
|
898776
|
+
// 兼容解析旧的登录态
|
|
899150
898777
|
function resolveCredential(data) {
|
|
899151
898778
|
let { secretId, secretKey, token, accessTokenExpired, tmpSecretId, tmpSecretKey, tmpToken, tmpExpired, expired, authTime, refreshToken, uin, hash, envId } = data;
|
|
898779
|
+
// 兼容旧的登录态信息
|
|
899152
898780
|
token = token || tmpToken;
|
|
899153
898781
|
secretId = secretId || tmpSecretId;
|
|
899154
898782
|
secretKey = secretKey || tmpSecretKey;
|
|
@@ -911215,6 +910843,7 @@ function resolveCredentialFormEnv() {
|
|
|
911215
910843
|
token
|
|
911216
910844
|
};
|
|
911217
910845
|
}
|
|
910846
|
+
// 获取 credential 数据
|
|
911218
910847
|
function getCredentialData() {
|
|
911219
910848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
911220
910849
|
const localData = (yield exports.authStore.get('credential'));
|
|
@@ -911223,6 +910852,7 @@ function getCredentialData() {
|
|
|
911223
910852
|
const keys = Object.keys(credential)
|
|
911224
910853
|
.filter((key) => credential[key])
|
|
911225
910854
|
.filter((key) => key !== '-');
|
|
910855
|
+
// 检查是否为空对象
|
|
911226
910856
|
if (!credential || keys.length === 0) {
|
|
911227
910857
|
return null;
|
|
911228
910858
|
}
|
|
@@ -911230,6 +910860,7 @@ function getCredentialData() {
|
|
|
911230
910860
|
});
|
|
911231
910861
|
}
|
|
911232
910862
|
exports.getCredentialData = getCredentialData;
|
|
910863
|
+
// 临时密钥过期后,进行续期
|
|
911233
910864
|
function refreshTmpToken(metaData) {
|
|
911234
910865
|
return __awaiter(this, void 0, void 0, function* () {
|
|
911235
910866
|
const mac = yield (0, system_1.getMacAddress)();
|
|
@@ -911238,6 +910869,7 @@ function refreshTmpToken(metaData) {
|
|
|
911238
910869
|
const credential = (0, common_1.resolveWebCredential)(metaData);
|
|
911239
910870
|
const res = yield async_1.AsyncMerge.merge(() => (0, cloud_api_1.fetch)(refreshTokenUrl, {
|
|
911240
910871
|
method: 'POST',
|
|
910872
|
+
// 超时时间:15S
|
|
911241
910873
|
timeout: 15000,
|
|
911242
910874
|
body: JSON.stringify(credential),
|
|
911243
910875
|
headers: { 'Content-Type': 'application/json' }
|
|
@@ -911261,6 +910893,7 @@ function refreshTmpToken(metaData) {
|
|
|
911261
910893
|
});
|
|
911262
910894
|
}
|
|
911263
910895
|
exports.refreshTmpToken = refreshTmpToken;
|
|
910896
|
+
// 是否为 CAM 权限错误
|
|
911264
910897
|
const isCamRefused = (e) => {
|
|
911265
910898
|
return (Number(e.code) === 4102 ||
|
|
911266
910899
|
Number(e.code) === 42 ||
|
|
@@ -911268,16 +910901,22 @@ const isCamRefused = (e) => {
|
|
|
911268
910901
|
e.code === 'AuthFailure.UnauthorizedOperation');
|
|
911269
910902
|
};
|
|
911270
910903
|
exports.isCamRefused = isCamRefused;
|
|
910904
|
+
// 报错返回 null 值
|
|
911271
910905
|
function wrapCheckAuth(credential, options) {
|
|
911272
910906
|
return __awaiter(this, void 0, void 0, function* () {
|
|
911273
910907
|
const { timeout = 15000 } = options;
|
|
911274
910908
|
try {
|
|
910909
|
+
// 合并请求,避免超过接口限频
|
|
911275
910910
|
yield async_1.AsyncMerge.merge(() => (0, common_1.checkAuth)(credential, options), 'checkAuth', {
|
|
910911
|
+
// 超时时间不能小于发送请求的超时时间
|
|
911276
910912
|
timeout: Number(timeout) ? (timeout < 15000 ? 15000 : timeout + 1000) : 15000
|
|
911277
910913
|
});
|
|
911278
910914
|
return credential;
|
|
911279
910915
|
}
|
|
911280
910916
|
catch (e) {
|
|
910917
|
+
// CAM 错误视为登录正常
|
|
910918
|
+
// if (isCamRefused(e)) return credential;
|
|
910919
|
+
// 请求超时
|
|
911281
910920
|
if (e.type === 'request-timeout') {
|
|
911282
910921
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
911283
910922
|
}
|
|
@@ -911285,38 +910924,50 @@ function wrapCheckAuth(credential, options) {
|
|
|
911285
910924
|
}
|
|
911286
910925
|
});
|
|
911287
910926
|
}
|
|
910927
|
+
// token 将在 n 分钟内过期
|
|
911288
910928
|
const isTokenExpired = (credential, gap = 120) => credential.accessTokenExpired &&
|
|
911289
910929
|
Number(credential.accessTokenExpired) < Date.now() + gap * 1000;
|
|
910930
|
+
// 获取身份认证信息并校验、自动刷新
|
|
911290
910931
|
function checkAndGetCredential(options = {}) {
|
|
911291
910932
|
return __awaiter(this, void 0, void 0, function* () {
|
|
910933
|
+
// 从本地存储中读取 credential
|
|
911292
910934
|
const credential = yield getCredentialData();
|
|
911293
910935
|
if (!credential) {
|
|
911294
910936
|
return null;
|
|
911295
910937
|
}
|
|
910938
|
+
// 存在临时密钥信息
|
|
911296
910939
|
if (credential.refreshToken) {
|
|
910940
|
+
// 临时密钥在 2 小时有效期内,可以直接使用
|
|
911297
910941
|
if (!isTokenExpired(credential)) {
|
|
910942
|
+
// 检查 credential
|
|
911298
910943
|
return wrapCheckAuth(credential, options);
|
|
911299
910944
|
}
|
|
911300
910945
|
else if (Date.now() < Number(credential.expired)) {
|
|
910946
|
+
// 临时密钥超过两小时有效期,但在 1 个月 refresh 有效期内,刷新临时密钥
|
|
911301
910947
|
let refreshCredential;
|
|
911302
910948
|
try {
|
|
911303
910949
|
refreshCredential = yield refreshTmpToken(credential);
|
|
911304
910950
|
}
|
|
911305
910951
|
catch (e) {
|
|
910952
|
+
// 登录态失效
|
|
911306
910953
|
if (e.code === 'AUTH_FAIL') {
|
|
911307
910954
|
return null;
|
|
911308
910955
|
}
|
|
911309
910956
|
else if (e.code === 'InternalError.GetRoleError') {
|
|
910957
|
+
// 用户未开通服务,视为登录态失效
|
|
911310
910958
|
return null;
|
|
911311
910959
|
}
|
|
911312
910960
|
else {
|
|
910961
|
+
// 异常错误
|
|
911313
910962
|
throw e;
|
|
911314
910963
|
}
|
|
911315
910964
|
}
|
|
910965
|
+
// 存储新的秘钥
|
|
911316
910966
|
yield exports.authStore.set('credential', refreshCredential || {});
|
|
911317
910967
|
return wrapCheckAuth((0, common_1.resolveCredential)(refreshCredential), options);
|
|
911318
910968
|
}
|
|
911319
910969
|
}
|
|
910970
|
+
// 存在永久密钥
|
|
911320
910971
|
if (credential.secretId && credential.secretKey) {
|
|
911321
910972
|
return wrapCheckAuth(credential, options);
|
|
911322
910973
|
}
|
|
@@ -911324,36 +910975,45 @@ function checkAndGetCredential(options = {}) {
|
|
|
911324
910975
|
});
|
|
911325
910976
|
}
|
|
911326
910977
|
exports.checkAndGetCredential = checkAndGetCredential;
|
|
910978
|
+
// 获取身份认证信息,不校验
|
|
911327
910979
|
function getCredentialWithoutCheck() {
|
|
911328
910980
|
return __awaiter(this, void 0, void 0, function* () {
|
|
911329
910981
|
const credential = yield getCredentialData();
|
|
911330
910982
|
if (!credential) {
|
|
911331
910983
|
return null;
|
|
911332
910984
|
}
|
|
910985
|
+
// 存在临时密钥信息
|
|
911333
910986
|
if (credential.refreshToken) {
|
|
910987
|
+
// 临时密钥在 2 小时有效期内,可以直接使用
|
|
911334
910988
|
if (!isTokenExpired(credential)) {
|
|
911335
910989
|
return credential;
|
|
911336
910990
|
}
|
|
911337
910991
|
else if (Date.now() < Number(credential.expired)) {
|
|
910992
|
+
// 临时密钥超过两小时有效期,但在 1 个月 refresh 有效期内,刷新临时密钥
|
|
911338
910993
|
let refreshCredential;
|
|
911339
910994
|
try {
|
|
911340
910995
|
refreshCredential = yield refreshTmpToken(credential);
|
|
911341
910996
|
}
|
|
911342
910997
|
catch (e) {
|
|
910998
|
+
// 登录态失效
|
|
911343
910999
|
if (e.code === 'AUTH_FAIL') {
|
|
911344
911000
|
return null;
|
|
911345
911001
|
}
|
|
911346
911002
|
else if (e.code === 'InternalError.GetRoleError') {
|
|
911003
|
+
// 用户未开通服务,视为登录态失效
|
|
911347
911004
|
return null;
|
|
911348
911005
|
}
|
|
911349
911006
|
else {
|
|
911007
|
+
// 异常错误
|
|
911350
911008
|
throw e;
|
|
911351
911009
|
}
|
|
911352
911010
|
}
|
|
911011
|
+
// 存储新的秘钥
|
|
911353
911012
|
yield exports.authStore.set('credential', refreshCredential || {});
|
|
911354
911013
|
return (0, common_1.resolveCredential)(refreshCredential);
|
|
911355
911014
|
}
|
|
911356
911015
|
}
|
|
911016
|
+
// 存在永久密钥
|
|
911357
911017
|
if (credential.secretId && credential.secretKey) {
|
|
911358
911018
|
return credential;
|
|
911359
911019
|
}
|