@cloudbase/cli 2.0.12-alpha.3 → 2.0.14
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/.vscode/launch.json +0 -10
- package/.vscode/settings.json +3 -0
- package/bin/cloudbase.js +0 -0
- package/bin/tcb.js +0 -0
- package/lib/commands/lowcode/app.js +2 -30
- package/lib/commands/run/service/create.js +4 -0
- package/lib/commands/run/service/deploy.js +4 -0
- package/lib/commands/run/service/update.js +4 -0
- package/lib/run/service/common.js +9 -3
- package/lib/run/service/deployPackage.js +2 -9
- package/lib/utils/checkTcbrEnv.js +5 -4
- package/lib/utils/debug-logger.js +30 -0
- package/lib/utils/net/cloud-api-request.js +7 -1
- package/lib/utils/net/http-request.js +16 -5
- package/package.json +5 -4
- package/types/commands/lowcode/app.d.ts +0 -10
- package/types/run/service/common.d.ts +4 -1
- package/types/types.d.ts +4 -0
- package/types/utils/debug-logger.d.ts +1 -0
- package/types/utils/net/http-request.d.ts +6 -2
- package/.history/.gitignore_20220624162613 +0 -84
- package/.history/.gitignore_20220627114054 +0 -86
- package/.history/package_20220711204706.json +0 -88
- package/.history/package_20220711204818.json +0 -88
- package/.history/package_20220712151717.json +0 -88
- package/.history/package_20220712212537.json +0 -88
- package/.history/package_20220722205058.json +0 -88
- package/.history/src/commands/lowcode/app_20220624162613.ts +0 -34
- package/.history/src/commands/lowcode/app_20220627114205.ts +0 -52
- package/.history/src/index_20220624162613.ts +0 -13
- package/.history/src/index_20220627113609.ts +0 -15
- package/.history/src/index_20220627114102.ts +0 -13
- package/src/auth/index.ts +0 -2
- package/src/auth/login.ts +0 -91
- package/src/auth/logout.ts +0 -7
- package/src/commands/account/index.ts +0 -2
- package/src/commands/account/login.ts +0 -192
- package/src/commands/account/logout.ts +0 -24
- package/src/commands/common.ts +0 -246
- package/src/commands/env/base.ts +0 -90
- package/src/commands/env/create.ts +0 -92
- package/src/commands/env/domain.ts +0 -186
- package/src/commands/env/index.ts +0 -4
- package/src/commands/env/login.ts +0 -235
- package/src/commands/framework/index.ts +0 -124
- package/src/commands/functions/alias/getRoute.ts +0 -76
- package/src/commands/functions/alias/index.ts +0 -2
- package/src/commands/functions/alias/setRoute.ts +0 -82
- package/src/commands/functions/code-download.ts +0 -100
- package/src/commands/functions/code-update.ts +0 -62
- package/src/commands/functions/concurrency/delete.ts +0 -45
- package/src/commands/functions/concurrency/index.ts +0 -3
- package/src/commands/functions/concurrency/list.ts +0 -58
- package/src/commands/functions/concurrency/set.ts +0 -47
- package/src/commands/functions/config-update.ts +0 -76
- package/src/commands/functions/copy.ts +0 -62
- package/src/commands/functions/delete.ts +0 -79
- package/src/commands/functions/deploy.ts +0 -293
- package/src/commands/functions/detail.ts +0 -138
- package/src/commands/functions/index.ts +0 -16
- package/src/commands/functions/invoke.ts +0 -121
- package/src/commands/functions/layer/bind.ts +0 -182
- package/src/commands/functions/layer/common.ts +0 -8
- package/src/commands/functions/layer/create.ts +0 -49
- package/src/commands/functions/layer/delete.ts +0 -73
- package/src/commands/functions/layer/download.ts +0 -92
- package/src/commands/functions/layer/index.ts +0 -7
- package/src/commands/functions/layer/list.ts +0 -94
- package/src/commands/functions/layer/sort.ts +0 -76
- package/src/commands/functions/list.ts +0 -68
- package/src/commands/functions/log.ts +0 -148
- package/src/commands/functions/run.ts +0 -249
- package/src/commands/functions/trigger-create.ts +0 -79
- package/src/commands/functions/trigger-delete.ts +0 -105
- package/src/commands/functions/version/index.ts +0 -2
- package/src/commands/functions/version/list.ts +0 -73
- package/src/commands/functions/version/publish.ts +0 -43
- package/src/commands/gateway/create.ts +0 -109
- package/src/commands/gateway/delete.ts +0 -81
- package/src/commands/gateway/domain.ts +0 -159
- package/src/commands/gateway/index.ts +0 -5
- package/src/commands/gateway/list.ts +0 -76
- package/src/commands/gateway/switch.ts +0 -107
- package/src/commands/helpers/index.ts +0 -3
- package/src/commands/helpers/init.ts +0 -431
- package/src/commands/helpers/new.ts +0 -117
- package/src/commands/helpers/open.ts +0 -67
- package/src/commands/hosting/hosting.ts +0 -360
- package/src/commands/hosting/index.ts +0 -1
- package/src/commands/index.ts +0 -13
- package/src/commands/lowcode/app.ts +0 -52
- package/src/commands/lowcode/comps.ts +0 -325
- package/src/commands/lowcode/index.ts +0 -2
- package/src/commands/lowcode/utils.ts +0 -25
- package/src/commands/run/create.ts +0 -153
- package/src/commands/run/delete.ts +0 -77
- package/src/commands/run/image/common.ts +0 -8
- package/src/commands/run/image/delete.ts +0 -68
- package/src/commands/run/image/download.ts +0 -68
- package/src/commands/run/image/index.ts +0 -5
- package/src/commands/run/image/list.ts +0 -84
- package/src/commands/run/image/upload.ts +0 -76
- package/src/commands/run/index.ts +0 -7
- package/src/commands/run/list.ts +0 -83
- package/src/commands/run/service/config.ts +0 -81
- package/src/commands/run/service/create.ts +0 -122
- package/src/commands/run/service/deploy.ts +0 -125
- package/src/commands/run/service/index.ts +0 -5
- package/src/commands/run/service/list.ts +0 -94
- package/src/commands/run/service/update.ts +0 -108
- package/src/commands/run/standalonegateway/common.ts +0 -8
- package/src/commands/run/standalonegateway/create.ts +0 -85
- package/src/commands/run/standalonegateway/destroy.ts +0 -59
- package/src/commands/run/standalonegateway/index.ts +0 -5
- package/src/commands/run/standalonegateway/list.ts +0 -53
- package/src/commands/run/standalonegateway/package.ts +0 -62
- package/src/commands/run/standalonegateway/turn.ts +0 -63
- package/src/commands/run/version/common.ts +0 -8
- package/src/commands/run/version/create.ts +0 -369
- package/src/commands/run/version/delete.ts +0 -64
- package/src/commands/run/version/index.ts +0 -5
- package/src/commands/run/version/list.ts +0 -91
- package/src/commands/run/version/modify.ts +0 -137
- package/src/commands/run/version/update.ts +0 -398
- package/src/commands/smart.ts +0 -132
- package/src/commands/storage/index.ts +0 -1
- package/src/commands/storage/storage.ts +0 -464
- package/src/commands/third/index.ts +0 -1
- package/src/commands/third/thirdAttach.ts +0 -49
- package/src/completion/index.ts +0 -13
- package/src/constant.ts +0 -154
- package/src/decorators/captureError.ts +0 -25
- package/src/decorators/constants.ts +0 -12
- package/src/decorators/deprecate.ts +0 -25
- package/src/decorators/guard.ts +0 -42
- package/src/decorators/index.ts +0 -7
- package/src/decorators/injectParams.ts +0 -54
- package/src/decorators/params/common.ts +0 -28
- package/src/decorators/params/index.ts +0 -35
- package/src/env/domain.ts +0 -33
- package/src/env/index.ts +0 -63
- package/src/env/login.ts +0 -80
- package/src/error.ts +0 -36
- package/src/function/alias.ts +0 -43
- package/src/function/base.ts +0 -253
- package/src/function/code.ts +0 -55
- package/src/function/concurrency.ts +0 -57
- package/src/function/create.ts +0 -78
- package/src/function/delete.ts +0 -42
- package/src/function/index.ts +0 -11
- package/src/function/layer/attach.ts +0 -68
- package/src/function/layer/create.ts +0 -63
- package/src/function/layer/delete.ts +0 -21
- package/src/function/layer/download.ts +0 -54
- package/src/function/layer/index.ts +0 -7
- package/src/function/layer/list.ts +0 -32
- package/src/function/layer/sort.ts +0 -24
- package/src/function/trigger.ts +0 -97
- package/src/function/update.ts +0 -35
- package/src/function/version.ts +0 -39
- package/src/function/vpc.ts +0 -22
- package/src/gateway/index.ts +0 -137
- package/src/help.ts +0 -50
- package/src/hosting.ts +0 -212
- package/src/index.ts +0 -13
- package/src/logger.ts +0 -17
- package/src/run/create.ts +0 -23
- package/src/run/delete.ts +0 -15
- package/src/run/image/build.ts +0 -36
- package/src/run/image/delete.ts +0 -14
- package/src/run/image/index.ts +0 -4
- package/src/run/image/info.ts +0 -27
- package/src/run/image/list.ts +0 -23
- package/src/run/index.ts +0 -8
- package/src/run/list.ts +0 -30
- package/src/run/repo.ts +0 -25
- package/src/run/service/common.ts +0 -311
- package/src/run/service/config.ts +0 -77
- package/src/run/service/create.ts +0 -52
- package/src/run/service/deployPackage.ts +0 -65
- package/src/run/service/index.ts +0 -7
- package/src/run/service/list.ts +0 -29
- package/src/run/service/showLogs.ts +0 -98
- package/src/run/service/update.ts +0 -82
- package/src/run/standalonegateway/create.ts +0 -24
- package/src/run/standalonegateway/destroy.ts +0 -19
- package/src/run/standalonegateway/index.ts +0 -5
- package/src/run/standalonegateway/list.ts +0 -74
- package/src/run/standalonegateway/package/index.ts +0 -1
- package/src/run/standalonegateway/package/list.ts +0 -24
- package/src/run/standalonegateway/turn/index.ts +0 -2
- package/src/run/standalonegateway/turn/off.ts +0 -19
- package/src/run/standalonegateway/turn/on.ts +0 -19
- package/src/run/version/create.ts +0 -68
- package/src/run/version/delete.ts +0 -16
- package/src/run/version/index.ts +0 -6
- package/src/run/version/list.ts +0 -17
- package/src/run/version/modify.ts +0 -17
- package/src/run/version/repo.ts +0 -28
- package/src/run/version/update.ts +0 -59
- package/src/storage.ts +0 -114
- package/src/third/index.ts +0 -13
- package/src/types.ts +0 -672
- package/src/utils/auth.ts +0 -15
- package/src/utils/checkTcbrEnv.ts +0 -67
- package/src/utils/cli-table.ts +0 -23
- package/src/utils/commonParamsCheck.ts +0 -65
- package/src/utils/config.ts +0 -39
- package/src/utils/env.ts +0 -244
- package/src/utils/fs/del.ts +0 -5
- package/src/utils/fs/index.ts +0 -71
- package/src/utils/function-packer.ts +0 -97
- package/src/utils/index.ts +0 -25
- package/src/utils/log.ts +0 -82
- package/src/utils/net/cloud-api-request.ts +0 -62
- package/src/utils/net/credential.ts +0 -53
- package/src/utils/net/http-request.ts +0 -84
- package/src/utils/net/index.ts +0 -5
- package/src/utils/net/manager-service.ts +0 -36
- package/src/utils/net/proxy.ts +0 -6
- package/src/utils/notice.ts +0 -28
- package/src/utils/output/highlight.ts +0 -5
- package/src/utils/output/index.ts +0 -3
- package/src/utils/output/link.ts +0 -10
- package/src/utils/output/loading.ts +0 -82
- package/src/utils/parallel.ts +0 -82
- package/src/utils/platform/index.ts +0 -3
- package/src/utils/platform/mac.ts +0 -21
- package/src/utils/platform/os.ts +0 -64
- package/src/utils/platform/port.ts +0 -10
- package/src/utils/progress-bar.ts +0 -38
- package/src/utils/prompt/index.ts +0 -1
- package/src/utils/prompt/select.ts +0 -60
- package/src/utils/reporter/agree.ts +0 -20
- package/src/utils/reporter/download.ts +0 -26
- package/src/utils/reporter/index.ts +0 -3
- package/src/utils/reporter/usage.ts +0 -20
- package/src/utils/store/auth.ts +0 -49
- package/src/utils/store/common.ts +0 -8
- package/src/utils/store/db.ts +0 -68
- package/src/utils/store/index.ts +0 -5
- package/src/utils/store/usage.ts +0 -12
- package/src/utils/tcbrApi/callTcbrApi.ts +0 -28
- package/src/utils/tcbrApi/index.ts +0 -1
- package/src/utils/template.ts +0 -170
- package/src/utils/tools/encoding.ts +0 -8
- package/src/utils/tools/index.ts +0 -4
- package/src/utils/tools/object.ts +0 -33
- package/src/utils/tools/time.ts +0 -38
- package/src/utils/tools/uid.ts +0 -19
- package/src/utils/validator.ts +0 -65
- package/yarn-error.log +0 -12841
package/src/utils/log.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import logSymbols from 'log-symbols'
|
|
3
|
-
import { format } from 'util'
|
|
4
|
-
import { Console } from 'console'
|
|
5
|
-
import terminalLink from 'terminal-link'
|
|
6
|
-
|
|
7
|
-
export class Logger {
|
|
8
|
-
c = {
|
|
9
|
-
_times: new Map(),
|
|
10
|
-
log(a: string, ...args: string[]) {
|
|
11
|
-
this.debug(format(a, ...args))
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
verboseEnabled: boolean
|
|
16
|
-
|
|
17
|
-
constructor(options: { verbose?: boolean } = {}) {
|
|
18
|
-
const { verbose } = options
|
|
19
|
-
this.verboseEnabled = verbose
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
breakLine() {
|
|
23
|
-
console.log()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
log(...args) {
|
|
27
|
-
console.log(...args)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
info(msg: string) {
|
|
31
|
-
console.log(`${logSymbols.info} ${msg}`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
success(msg: string) {
|
|
35
|
-
console.log(`${logSymbols.success} ${msg}`)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
warn(msg: string) {
|
|
39
|
-
console.log(`${logSymbols.warning} ${msg}`)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
error(msg: string) {
|
|
43
|
-
console.log(`${logSymbols.error} ${msg}`)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
verbose(...args: any) {
|
|
47
|
-
if (this.verboseEnabled) {
|
|
48
|
-
const msg = args.join(' ▶️ ')
|
|
49
|
-
console.log(
|
|
50
|
-
`${chalk.bold('[debug]')} ${chalk.gray(`[${new Date().toISOString()}]`)} ${msg}`
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
genClickableLink(link: string) {
|
|
56
|
-
if (terminalLink.isSupported) {
|
|
57
|
-
const clickablelink = terminalLink(link, link)
|
|
58
|
-
return chalk.bold.cyan(clickablelink)
|
|
59
|
-
}
|
|
60
|
-
return chalk.bold.underline.cyan(link)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
printClickableLink(link: string) {
|
|
64
|
-
const clickLink = this.genClickableLink(link)
|
|
65
|
-
this.info(clickLink)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async time(label: string, fn: Promise<any> | (() => Promise<any>)) {
|
|
69
|
-
const promise = typeof fn === 'function' ? fn() : fn
|
|
70
|
-
if (this.verboseEnabled) {
|
|
71
|
-
this.c.log(label)
|
|
72
|
-
Console.prototype.time.call(this.c, label)
|
|
73
|
-
const r = await promise
|
|
74
|
-
Console.prototype.timeEnd.call(this.c, label)
|
|
75
|
-
return r
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return promise
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const logger = new Logger()
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getCredentialWithoutCheck, getRegion, Credential, getProxy } from '@cloudbase/toolbox'
|
|
2
|
-
import { CloudApiService as _CloudApiService } from '@cloudbase/cloud-api'
|
|
3
|
-
import { CloudBaseError } from '../../error'
|
|
4
|
-
import { REQUEST_TIMEOUT } from '../../constant'
|
|
5
|
-
|
|
6
|
-
let commonCredential: Credential
|
|
7
|
-
|
|
8
|
-
// token 将在 n 分钟内过期
|
|
9
|
-
const isTokenExpired = (credential: Credential, gap = 120) =>
|
|
10
|
-
credential.accessTokenExpired && Number(credential.accessTokenExpired) < Date.now() + gap * 1000
|
|
11
|
-
|
|
12
|
-
export class CloudApiService {
|
|
13
|
-
// 缓存请求实例
|
|
14
|
-
static serviceCacheMap: Record<string, CloudApiService> = {}
|
|
15
|
-
|
|
16
|
-
// 单例模式
|
|
17
|
-
static getInstance(service: string) {
|
|
18
|
-
if (CloudApiService.serviceCacheMap?.[service]) {
|
|
19
|
-
return CloudApiService.serviceCacheMap[service]
|
|
20
|
-
}
|
|
21
|
-
const apiService = new CloudApiService(service)
|
|
22
|
-
CloudApiService.serviceCacheMap[service] = apiService
|
|
23
|
-
return apiService
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
region: string
|
|
27
|
-
apiService: _CloudApiService
|
|
28
|
-
|
|
29
|
-
constructor(service: string, baseParams?: Record<string, any>, version = '') {
|
|
30
|
-
// 初始化 API 实例
|
|
31
|
-
this.apiService = new _CloudApiService({
|
|
32
|
-
service,
|
|
33
|
-
version: service === 'tcr' ? version : '2019-09-24',
|
|
34
|
-
baseParams,
|
|
35
|
-
proxy: getProxy(),
|
|
36
|
-
timeout: REQUEST_TIMEOUT,
|
|
37
|
-
getCredential: async () => {
|
|
38
|
-
// 存在未过期的 token
|
|
39
|
-
if (commonCredential?.secretId && !isTokenExpired(commonCredential)) {
|
|
40
|
-
return commonCredential
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const credential = await getCredentialWithoutCheck()
|
|
44
|
-
if (!credential) {
|
|
45
|
-
throw new CloudBaseError('无有效身份信息,请使用 cloudbase login 登录')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
commonCredential = credential
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
...credential,
|
|
52
|
-
tokenExpired: Number(credential.accessTokenExpired)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async request(action: string, data: Record<string, any> = {}, method: 'POST' | 'GET' = 'POST') {
|
|
59
|
-
const region = this.region || (await getRegion())
|
|
60
|
-
return this.apiService.request({ action, data, method, region })
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import { checkAndGetCredential as _getCredentail } from '@cloudbase/toolbox'
|
|
3
|
-
import { CloudBaseError } from '../../error'
|
|
4
|
-
import { REQUEST_TIMEOUT } from '../../constant'
|
|
5
|
-
import { Credential, AuthSecret } from '../../types'
|
|
6
|
-
|
|
7
|
-
import { md5 } from '../tools'
|
|
8
|
-
import { getMacAddress } from '../platform'
|
|
9
|
-
import { getProxy } from './proxy'
|
|
10
|
-
import { fetch } from './http-request'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const refreshTokenUrl = 'https://iaas.cloud.tencent.com/tcb_refresh'
|
|
14
|
-
|
|
15
|
-
// 临时密钥过期后,进行续期
|
|
16
|
-
export async function refreshTmpToken(
|
|
17
|
-
metaData: Credential & { isLogout?: boolean }
|
|
18
|
-
): Promise<Credential> {
|
|
19
|
-
const mac = await getMacAddress()
|
|
20
|
-
const hash = md5(mac)
|
|
21
|
-
metaData.hash = hash
|
|
22
|
-
|
|
23
|
-
const res = await fetch(refreshTokenUrl, {
|
|
24
|
-
method: 'POST',
|
|
25
|
-
body: JSON.stringify(metaData),
|
|
26
|
-
headers: { 'Content-Type': 'application/json' }
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
if (res.code !== 0) {
|
|
30
|
-
throw new CloudBaseError(res.message, {
|
|
31
|
-
code: res.code
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { data: credential } = res
|
|
36
|
-
return credential
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function checkAndGetCredential(throwError = false): Promise<AuthSecret> {
|
|
40
|
-
const credential = await _getCredentail({
|
|
41
|
-
proxy: getProxy(),
|
|
42
|
-
timeout: REQUEST_TIMEOUT
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
if (!credential || _.isEmpty(credential)) {
|
|
46
|
-
if (throwError) {
|
|
47
|
-
throw new CloudBaseError('无有效身份信息,请使用 cloudbase login 登录')
|
|
48
|
-
}
|
|
49
|
-
return null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return credential
|
|
53
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import _fetch, { RequestInit } from 'node-fetch'
|
|
2
|
-
import {HttpsProxyAgent} from 'https-proxy-agent'
|
|
3
|
-
import { REQUEST_TIMEOUT } from '../../constant'
|
|
4
|
-
import { CloudBaseError } from '../../error'
|
|
5
|
-
import { getProxy } from './proxy'
|
|
6
|
-
|
|
7
|
-
function handleTimeout(e) {
|
|
8
|
-
if (e.type === 'request-timeout') {
|
|
9
|
-
throw new CloudBaseError(
|
|
10
|
-
'请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!'
|
|
11
|
-
)
|
|
12
|
-
} else {
|
|
13
|
-
// 其他错误,抛出
|
|
14
|
-
throw e
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 使用 fetch + 代理
|
|
19
|
-
export async function fetch(url: string, config: RequestInit = {}) {
|
|
20
|
-
const proxy = getProxy()
|
|
21
|
-
if (proxy) {
|
|
22
|
-
config.agent = new HttpsProxyAgent(proxy)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
config.timeout = REQUEST_TIMEOUT
|
|
26
|
-
|
|
27
|
-
let json
|
|
28
|
-
let text
|
|
29
|
-
try {
|
|
30
|
-
const res = await _fetch(url, config)
|
|
31
|
-
text = await res.text()
|
|
32
|
-
json = JSON.parse(text)
|
|
33
|
-
} catch (e) {
|
|
34
|
-
handleTimeout(e)
|
|
35
|
-
json = text
|
|
36
|
-
}
|
|
37
|
-
return json
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 使用 fetch + 代理
|
|
41
|
-
export async function postFetch(url: string, data?: Record<string, any>) {
|
|
42
|
-
const proxy = getProxy()
|
|
43
|
-
const config: RequestInit = {
|
|
44
|
-
method: 'POST',
|
|
45
|
-
headers: {
|
|
46
|
-
'Content-Type': 'application/json'
|
|
47
|
-
},
|
|
48
|
-
body: JSON.stringify(data)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (proxy) {
|
|
52
|
-
config.agent = new HttpsProxyAgent(proxy)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
config.timeout = REQUEST_TIMEOUT
|
|
56
|
-
|
|
57
|
-
let json
|
|
58
|
-
let text
|
|
59
|
-
try {
|
|
60
|
-
const res = await _fetch(url, config)
|
|
61
|
-
text = await res.text()
|
|
62
|
-
json = JSON.parse(text)
|
|
63
|
-
} catch (e) {
|
|
64
|
-
handleTimeout(e)
|
|
65
|
-
json = text
|
|
66
|
-
}
|
|
67
|
-
return json
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export async function fetchStream(url, config: Record<string, any> = {}) {
|
|
71
|
-
const proxy = getProxy()
|
|
72
|
-
if (proxy) {
|
|
73
|
-
config.agent = new HttpsProxyAgent(proxy)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
config.timeout = REQUEST_TIMEOUT
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const res = await _fetch(url, config)
|
|
80
|
-
return res
|
|
81
|
-
} catch (e) {
|
|
82
|
-
handleTimeout(e)
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/utils/net/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import CloudBase from '@cloudbase/manager-node'
|
|
2
|
-
import { StorageService } from '@cloudbase/manager-node/types/storage'
|
|
3
|
-
import { getRegion } from '@cloudbase/toolbox'
|
|
4
|
-
import { checkAndGetCredential } from './credential'
|
|
5
|
-
import { getProxy } from './proxy'
|
|
6
|
-
|
|
7
|
-
export async function getMangerService(envId = ''): Promise<CloudBase> {
|
|
8
|
-
const { secretId, secretKey, token } = await checkAndGetCredential(true)
|
|
9
|
-
const region = await getRegion()
|
|
10
|
-
|
|
11
|
-
const app = new CloudBase({
|
|
12
|
-
token,
|
|
13
|
-
envId,
|
|
14
|
-
region,
|
|
15
|
-
secretId,
|
|
16
|
-
secretKey,
|
|
17
|
-
proxy: getProxy()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return app
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function getStorageService(envId: string): Promise<StorageService> {
|
|
24
|
-
const { secretId, secretKey, token } = await checkAndGetCredential(true)
|
|
25
|
-
const region = await getRegion()
|
|
26
|
-
|
|
27
|
-
const app = new CloudBase({
|
|
28
|
-
token,
|
|
29
|
-
envId,
|
|
30
|
-
secretId,
|
|
31
|
-
region,
|
|
32
|
-
secretKey,
|
|
33
|
-
proxy: getProxy()
|
|
34
|
-
})
|
|
35
|
-
return app.storage
|
|
36
|
-
}
|
package/src/utils/net/proxy.ts
DELETED
package/src/utils/notice.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { postFetch } from './net'
|
|
2
|
-
import { commonStore } from './store'
|
|
3
|
-
|
|
4
|
-
const url = 'https://tcli.service.tcloudbase.com/notify'
|
|
5
|
-
|
|
6
|
-
// 获取通知,最多每天获取一次
|
|
7
|
-
const ONE_DAY = 86400000
|
|
8
|
-
|
|
9
|
-
export async function getNotification() {
|
|
10
|
-
// 不再获取通知
|
|
11
|
-
return null
|
|
12
|
-
const now = Date.now()
|
|
13
|
-
// 上次记录的时间
|
|
14
|
-
const lastTime = await commonStore.get('lastNotifyTime')
|
|
15
|
-
const diff = now - Number(lastTime)
|
|
16
|
-
const day = new Date(lastTime).getDay()
|
|
17
|
-
const today = new Date().getDay()
|
|
18
|
-
// 日期不同,且时差小于 1 天
|
|
19
|
-
if (day === today && diff < ONE_DAY) return null
|
|
20
|
-
const lastUid = await commonStore.get('lastNotificationUid')
|
|
21
|
-
const data = await postFetch(url)
|
|
22
|
-
const uid = data?.uid || 0
|
|
23
|
-
// 消息已读
|
|
24
|
-
if (Number(lastUid) >= Number(uid)) return
|
|
25
|
-
await commonStore.set('readNotificationUid', data.uid)
|
|
26
|
-
await commonStore.set('lastNotifyTime', Date.now())
|
|
27
|
-
return data
|
|
28
|
-
}
|
package/src/utils/output/link.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import terminalLink from 'terminal-link'
|
|
3
|
-
|
|
4
|
-
export function genClickableLink(link: string) {
|
|
5
|
-
if (terminalLink.isSupported) {
|
|
6
|
-
const clickablelink = terminalLink(link, link)
|
|
7
|
-
return chalk.bold.cyan(clickablelink)
|
|
8
|
-
}
|
|
9
|
-
return chalk.bold.underline.cyan(link)
|
|
10
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import ora from 'ora'
|
|
2
|
-
|
|
3
|
-
class Loading {
|
|
4
|
-
private spinner: ReturnType<typeof ora>
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
process.on('tcbExit', this.stop.bind(this))
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
process.on('tcbError', this.stop.bind(this))
|
|
11
|
-
this.spinner = ora({
|
|
12
|
-
discardStdin: false
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line
|
|
17
|
-
set text(text: string) {
|
|
18
|
-
this.spinner.text = text
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
start(text: string) {
|
|
22
|
-
this.spinner = this.spinner.start(text)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
stop() {
|
|
26
|
-
if (this.spinner) {
|
|
27
|
-
this.spinner = this.spinner.stop()
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
succeed(text: string) {
|
|
32
|
-
if (this.spinner) {
|
|
33
|
-
this.spinner = this.spinner.succeed(text)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
fail(text: string) {
|
|
38
|
-
if (this.spinner) {
|
|
39
|
-
this.spinner = this.spinner.fail(text)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const loadingFactory = (): Loading => {
|
|
45
|
-
return new Loading()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type Task<T> = (flush: (text: string) => void, ...args: any[]) => Promise<T>
|
|
49
|
-
|
|
50
|
-
export interface ILoadingOptions {
|
|
51
|
-
startTip?: string
|
|
52
|
-
successTip?: string
|
|
53
|
-
failTip?: string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 执行异步任务,显示 loading 动画
|
|
58
|
-
* @param task
|
|
59
|
-
* @param options
|
|
60
|
-
*/
|
|
61
|
-
export const execWithLoading = async <T>(
|
|
62
|
-
task: Task<T>,
|
|
63
|
-
options: ILoadingOptions = {}
|
|
64
|
-
): Promise<T> => {
|
|
65
|
-
const { startTip, successTip, failTip } = options
|
|
66
|
-
const loading = loadingFactory()
|
|
67
|
-
|
|
68
|
-
// 刷新 loading 提示
|
|
69
|
-
const flush = (text: string) => {
|
|
70
|
-
loading.text = text
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
loading.start(startTip)
|
|
75
|
-
const res = await task(flush)
|
|
76
|
-
successTip ? loading.succeed(successTip) : loading.stop()
|
|
77
|
-
return res
|
|
78
|
-
} catch (e) {
|
|
79
|
-
failTip ? loading.fail(failTip) : loading.stop()
|
|
80
|
-
throw e
|
|
81
|
-
}
|
|
82
|
-
}
|
package/src/utils/parallel.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export type AsyncTask = () => Promise<any>
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 异步任务并发控制器,以一定的并发数执行所有任务
|
|
5
|
-
* 不具备队列性质,异步任务随机执行
|
|
6
|
-
* 单个任务异常,错误会返回,单不会退出执行
|
|
7
|
-
* 所有任务执行
|
|
8
|
-
*/
|
|
9
|
-
export class AsyncTaskParallelController {
|
|
10
|
-
// 任务最大并发数
|
|
11
|
-
maxParallel: number
|
|
12
|
-
// 异步任务队列
|
|
13
|
-
tasks: AsyncTask[]
|
|
14
|
-
// 检查间隔时间,单位 ms
|
|
15
|
-
checkInterval: number
|
|
16
|
-
// 所有任务数量
|
|
17
|
-
totalTasks: number
|
|
18
|
-
|
|
19
|
-
constructor(maxParallel: number, checkInterval = 20) {
|
|
20
|
-
this.tasks = []
|
|
21
|
-
this.maxParallel = Number(maxParallel) || 20
|
|
22
|
-
this.checkInterval = checkInterval
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
loadTasks(tasks: AsyncTask[]) {
|
|
26
|
-
this.tasks.push(...tasks)
|
|
27
|
-
this.totalTasks = this.tasks.length
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
push(task: AsyncTask) {
|
|
31
|
-
this.tasks.push(task)
|
|
32
|
-
this.totalTasks = this.tasks.length
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 开始执行任务
|
|
36
|
-
async run(): Promise<any[]> {
|
|
37
|
-
// 存储任务执行结果
|
|
38
|
-
const results = []
|
|
39
|
-
// 记录已经运行的任务
|
|
40
|
-
const taskHasRun = []
|
|
41
|
-
// 记录任务是否执行完成
|
|
42
|
-
const taskDone = []
|
|
43
|
-
// 当前正在运行的任务数量
|
|
44
|
-
let runningTask = 0
|
|
45
|
-
|
|
46
|
-
return new Promise((resolve) => {
|
|
47
|
-
// 使用定时器,不阻塞线程
|
|
48
|
-
const timer = setInterval(() => {
|
|
49
|
-
// 全部任务运行完成
|
|
50
|
-
const taskDoneLength = taskDone.filter((item) => item).length
|
|
51
|
-
if (runningTask === 0 && taskDoneLength === this.totalTasks) {
|
|
52
|
-
clearInterval(timer)
|
|
53
|
-
resolve(results)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 当前运行任务数超过最大并发,不再执行新的任务
|
|
57
|
-
if (runningTask >= this.maxParallel) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 遍历任务列表,开始执行还没有执行的任务
|
|
62
|
-
this.tasks.forEach((task, index) => {
|
|
63
|
-
if (!taskHasRun[index] && runningTask < this.maxParallel) {
|
|
64
|
-
runningTask++
|
|
65
|
-
taskHasRun[index] = 1
|
|
66
|
-
task()
|
|
67
|
-
.then((res) => {
|
|
68
|
-
results[index] = res
|
|
69
|
-
})
|
|
70
|
-
.catch((err) => {
|
|
71
|
-
results[index] = err
|
|
72
|
-
})
|
|
73
|
-
.then(() => {
|
|
74
|
-
runningTask--
|
|
75
|
-
taskDone[index] = 1
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
}, this.checkInterval)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import address from 'address'
|
|
2
|
-
import { md5 } from '../tools'
|
|
3
|
-
|
|
4
|
-
// 获取本机 Mac 地址
|
|
5
|
-
export function getMacAddress(): Promise<string> {
|
|
6
|
-
return new Promise(resolve => {
|
|
7
|
-
address.mac((err, mac) => {
|
|
8
|
-
if (err) {
|
|
9
|
-
resolve('')
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
resolve(mac)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function getMacAddressMd5(): Promise<string> {
|
|
18
|
-
const mac = await getMacAddress()
|
|
19
|
-
const macMD5 = md5(mac)
|
|
20
|
-
return macMD5
|
|
21
|
-
}
|
package/src/utils/platform/os.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import os from 'os'
|
|
2
|
-
|
|
3
|
-
const macOSMap = new Map([
|
|
4
|
-
[19, 'Catalina'],
|
|
5
|
-
[18, 'Mojave'],
|
|
6
|
-
[17, 'High Sierra'],
|
|
7
|
-
[16, 'Sierra'],
|
|
8
|
-
[15, 'El Capitan'],
|
|
9
|
-
[14, 'Yosemite'],
|
|
10
|
-
[13, 'Mavericks'],
|
|
11
|
-
[12, 'Mountain Lion'],
|
|
12
|
-
[11, 'Lion'],
|
|
13
|
-
[10, 'Snow Leopard'],
|
|
14
|
-
[9, 'Leopard'],
|
|
15
|
-
[8, 'Tiger'],
|
|
16
|
-
[7, 'Panther'],
|
|
17
|
-
[6, 'Jaguar'],
|
|
18
|
-
[5, 'Puma']
|
|
19
|
-
])
|
|
20
|
-
|
|
21
|
-
const winMap = new Map([
|
|
22
|
-
['10.0', '10'],
|
|
23
|
-
['6.3', '8.1'],
|
|
24
|
-
['6.2', '8'],
|
|
25
|
-
['6.1', '7'],
|
|
26
|
-
['6.0', 'Vista'],
|
|
27
|
-
['5.2', 'Server 2003'],
|
|
28
|
-
['5.1', 'XP'],
|
|
29
|
-
['5.0', '2000'],
|
|
30
|
-
['4.9', 'ME'],
|
|
31
|
-
['4.1', '98'],
|
|
32
|
-
['4.0', '95']
|
|
33
|
-
])
|
|
34
|
-
|
|
35
|
-
export function getPlatformRelease(platform: string, release: string) {
|
|
36
|
-
// macOS
|
|
37
|
-
if (platform === 'darwin') {
|
|
38
|
-
const releaseNum = Number(release.split('.')[0])
|
|
39
|
-
const name = macOSMap.get(releaseNum)
|
|
40
|
-
const version = '10.' + (releaseNum - 4)
|
|
41
|
-
return `${name} ${version}`
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// windows
|
|
45
|
-
if (platform === 'win32') {
|
|
46
|
-
const version = (/\d+\.\d/.exec(release) || [])[0]
|
|
47
|
-
|
|
48
|
-
return `Windows ${winMap.get(version)}`
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 其他 Linux
|
|
52
|
-
return 'Linux'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 获取 hostname 和平台信息
|
|
56
|
-
export function getOSInfo() {
|
|
57
|
-
const hostname = os.hostname()
|
|
58
|
-
const platform = os.platform()
|
|
59
|
-
const release = os.release()
|
|
60
|
-
|
|
61
|
-
const platformRelease = getPlatformRelease(platform, release)
|
|
62
|
-
|
|
63
|
-
return [hostname, platformRelease].join('/')
|
|
64
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import ProgressBar from 'progress'
|
|
2
|
-
|
|
3
|
-
// 打印文件传输进度条
|
|
4
|
-
export function createUploadProgressBar(onFinished: Function, onStart?: Function) {
|
|
5
|
-
let bar
|
|
6
|
-
let lastLoaded = 0
|
|
7
|
-
let finished = false
|
|
8
|
-
|
|
9
|
-
return function (data) {
|
|
10
|
-
const { total, loaded, percent } = data
|
|
11
|
-
if (lastLoaded === 0 && onStart) {
|
|
12
|
-
onStart()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (+percent === 1) {
|
|
16
|
-
if (finished) return
|
|
17
|
-
finished = true
|
|
18
|
-
setTimeout(() => {
|
|
19
|
-
onFinished()
|
|
20
|
-
}, 500)
|
|
21
|
-
bar.tick(total - lastLoaded)
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
const tick = loaded - lastLoaded
|
|
25
|
-
lastLoaded = loaded
|
|
26
|
-
if (bar) {
|
|
27
|
-
bar.tick(tick)
|
|
28
|
-
} else {
|
|
29
|
-
bar = new ProgressBar('文件传输中 [:bar] :percent :etas', {
|
|
30
|
-
total,
|
|
31
|
-
complete: '=',
|
|
32
|
-
incomplete: ' ',
|
|
33
|
-
width: 50
|
|
34
|
-
})
|
|
35
|
-
bar.tick(tick)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|