Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit 5639e51

Browse files
committed
optimize proxy config && fix command get envId error
1 parent 6fe3afa commit 5639e51

13 files changed

Lines changed: 419 additions & 104 deletions

File tree

.vscode/launch.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
{
2-
// 使用 IntelliSense 了解相关属性。
2+
// 使用 IntelliSense 了解相关属性。
33
// 悬停以查看现有属性的描述。
44
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program",
11+
"program": "${workspaceFolder}/src/utils/runtime/nodejs/bootstrap.js"
12+
},
713
{
814
"type": "node",
915
"request": "launch",
1016
"name": "Debug: cloudbase logout",
1117
"program": "${workspaceFolder}/bin/cloudbase.js",
12-
"args": [
13-
"logout"
14-
],
15-
"outFiles": [
16-
"${workspaceFolder}/lib/**/*.js"
17-
]
18+
"args": ["logout"],
19+
"outFiles": ["${workspaceFolder}/lib/**/*.js"]
1820
}
1921
]
20-
}
22+
}

bin/cloudbase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ const pkg = require('../package.json')
1010

1111
const isBeta = pkg.version.indexOf('-') > -1
1212

13+
const userNodeVersion = Number(
14+
process.versions.node
15+
.split('.')
16+
.slice(0, 2)
17+
.join('.')
18+
)
19+
20+
// Node 版本检验提示
21+
if (userNodeVersion < 8.6) {
22+
console.log(
23+
chalk.bold.red(
24+
'您的 Node 版本较低,CloudBase CLI 可能无法正常运行,请升级 Node 到 v8.6.0 以上!\n'
25+
)
26+
)
27+
}
28+
1329
// Sentry 错误上报
1430
Sentry.init({
1531
release: pkg.version,
@@ -54,10 +70,12 @@ Sentry.configureScope(scope => {
5470
}
5571
})
5672

73+
// 设置 options 选项
5774
program.option(
5875
'--config-file <path>',
5976
'设置配置文件,默认为 ./cloudbaserc.js 或 .cloudbaserc.json'
6077
)
78+
program.option('--debug', 'open debug mode')
6179

6280
program.version(pkg.version, '-V, --version', '输出当前 CloudBase CLI 版本')
6381

@@ -93,6 +111,8 @@ if (process.argv.length < 3) {
93111

94112
program.parse(process.argv)
95113

114+
process.IS_DEBUG = program.debug
115+
96116
function errorHandler(err) {
97117
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']
98118
// 忽略自定义错误的错误栈

deps/tencentcloud-sdk-nodejs/tencentcloud/common/http/fetch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ module.exports = (url, options) => {
66
...options
77
};
88

9-
if (!options.agent && process.env.http_proxy) {
10-
instanceOptions.agent = new HttpsProxyAgent(process.env.http_proxy);
9+
const proxy = process.env.http_proxy || process.env.HTTP_PROXY
10+
11+
if (!options.agent && proxy) {
12+
instanceOptions.agent = new HttpsProxyAgent(proxy);
1113
}
1214

1315
return fetch(url, instanceOptions);

lib/commands/init.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1313
};
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const fs_1 = __importDefault(require("fs"));
16-
const tar_fs_1 = __importDefault(require("tar-fs"));
16+
const chalk_1 = __importDefault(require("chalk"));
1717
const path_1 = __importDefault(require("path"));
18+
const tar_fs_1 = __importDefault(require("tar-fs"));
1819
const fs_extra_1 = __importDefault(require("fs-extra"));
1920
const inquirer_1 = __importDefault(require("inquirer"));
2021
const commander_1 = __importDefault(require("commander"));
@@ -46,6 +47,12 @@ function copyServerTemplate(projectPath) {
4647
fs_extra_1.default.copySync(templatePath, projectPath);
4748
});
4849
}
50+
function initSuccessOutput(projectName) {
51+
logger_1.successLog(`创建项目 ${projectName} 成功!\n`);
52+
const command = chalk_1.default.bold.cyan(`cd ${projectName}`);
53+
console.log(`👉 运行 ${command} 开始您的项目!\n`);
54+
console.log('🎉 欢迎贡献你的模板 👉 https://github.com/TencentCloudBase/cloudbase-examples');
55+
}
4956
commander_1.default
5057
.command('init')
5158
.option('--server', '创建 node 项目')
@@ -129,12 +136,11 @@ commander_1.default
129136
const configFileJSPath = path_1.default.join(projectPath, 'cloudbaserc.js');
130137
const configFilePath = [configFileJSPath, configFileJSONPath].find(item => fs_1.default.existsSync(item));
131138
if (!configFilePath) {
132-
logger_1.successLog(`创建项目 ${projectName} 成功`);
139+
initSuccessOutput(projectName);
133140
return;
134141
}
135142
const configContent = fs_1.default.readFileSync(configFilePath).toString();
136143
fs_1.default.writeFileSync(configFilePath, configContent.replace('{{envId}}', env));
137-
logger_1.successLog(`创建项目 ${projectName} 成功!\n`);
138-
console.log('🎉 欢迎贡献你的模板 👉 https://github.com/TencentCloudBase/cloudbase-examples');
144+
initSuccessOutput(projectName);
139145
});
140146
});

lib/utils/cloudbase-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function resolveCloudBaseConfig(configPath = '') {
5555
if (!cloudbasePath ||
5656
!fs_1.default.existsSync(cloudbasePath) ||
5757
!cloudbasePath.match(/.js$|.json$/g)) {
58-
throw new error_1.CloudBaseError('配置文件不存在');
58+
return {};
5959
}
6060
const localCloudBaseConfig = yield Promise.resolve().then(() => __importStar(require(cloudbasePath)));
6161
if (!localCloudBaseConfig.envId) {

lib/utils/http-request.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ const node_fetch_1 = __importDefault(require("node-fetch"));
1616
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
1717
function fetch(url, config = {}) {
1818
return __awaiter(this, void 0, void 0, function* () {
19-
if (process.env.http_proxy) {
20-
config.agent = new https_proxy_agent_1.default(process.env.http_proxy);
19+
const proxy = process.env.http_proxy || process.env.HTTP_PROXY;
20+
if (proxy) {
21+
config.agent = new https_proxy_agent_1.default(proxy);
2122
}
2223
const res = yield node_fetch_1.default(url, config);
2324
return res.json();
@@ -26,8 +27,9 @@ function fetch(url, config = {}) {
2627
exports.fetch = fetch;
2728
function fetchStream(url, config = {}) {
2829
return __awaiter(this, void 0, void 0, function* () {
29-
if (process.env.http_proxy) {
30-
config.agent = new https_proxy_agent_1.default(process.env.http_proxy);
30+
const proxy = process.env.http_proxy || process.env.HTTP_PROXY;
31+
if (proxy) {
32+
config.agent = new https_proxy_agent_1.default(proxy);
3133
}
3234
return node_fetch_1.default(url, config);
3335
});

0 commit comments

Comments
 (0)