0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

refactor(cli): support proxy

This commit is contained in:
Gao Sun 2022-10-03 19:00:44 +08:00
parent a59ba6e318
commit 50e5e5fa22
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
3 changed files with 16 additions and 3 deletions

View file

@ -1,11 +1,12 @@
{
"name": "@logto/cli",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.10",
"description": "Logto CLI.",
"author": "Silverhand Inc. <contact@silverhand.io>",
"homepage": "https://github.com/logto-io/logto#readme",
"license": "MPL-2.0",
"main": "lib/index.js",
"bin": "lib/index.js",
"files": [
"lib"
],
@ -13,7 +14,6 @@
"type": "git",
"url": "git+https://github.com/logto-io/logto.git"
},
"bin": "lib/index.js",
"scripts": {
"precommit": "lint-staged",
"build": "rimraf lib && tsc",
@ -32,6 +32,7 @@
"dependencies": {
"chalk": "^4.1.2",
"got": "^11.8.2",
"hpagent": "^1.0.0",
"ora": "^5.0.0",
"prompts": "^2.4.2",
"semver": "^7.3.7",

View file

@ -3,6 +3,7 @@ import { createWriteStream } from 'fs';
import chalk from 'chalk';
import got, { Progress } from 'got';
import { HttpsProxyAgent } from 'hpagent';
import ora from 'ora';
export const safeExecSync = (command: string) => {
@ -32,8 +33,12 @@ export const log: Log = Object.freeze({
});
export const downloadFile = async (url: string, destination: string) => {
const { HTTPS_PROXY, HTTP_PROXY, https_proxy, http_proxy } = process.env;
const file = createWriteStream(destination);
const stream = got.stream(url);
const proxy = HTTPS_PROXY ?? https_proxy ?? HTTP_PROXY ?? http_proxy;
const stream = got.stream(url, {
...(proxy && { agent: { https: new HttpsProxyAgent({ proxy }) } }),
});
const spinner = ora({
text: 'Connecting',
prefixText: chalk.blue('[info]'),

View file

@ -30,6 +30,7 @@ importers:
chalk: ^4.1.2
eslint: ^8.21.0
got: ^11.8.2
hpagent: ^1.0.0
lint-staged: ^13.0.0
ora: ^5.0.0
prettier: ^2.7.1
@ -42,6 +43,7 @@ importers:
dependencies:
chalk: 4.1.2
got: 11.8.3
hpagent: 1.0.0
ora: 5.4.1
prompts: 2.4.2
semver: 7.3.7
@ -8110,6 +8112,11 @@ packages:
lru-cache: 7.10.1
dev: true
/hpagent/1.0.0:
resolution: {integrity: sha512-SCleE2Uc1bM752ymxg8QXYGW0TWtAV4ZW3TqH1aOnyi6T6YW2xadCcclm5qeVjvMvfQ2RKNtZxO7uVb9CTPt1A==}
engines: {node: '>=14'}
dev: false
/html-encoding-sniffer/3.0.0:
resolution: {integrity: sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==}
engines: {node: '>=12'}