@cloudbase/cli 2.0.12-alpha.1 → 2.0.13
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/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/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/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
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import inquirer from 'inquirer'
|
|
2
|
-
import { Command, ICommand } from '../common'
|
|
3
|
-
import { CloudBaseError } from '../../error'
|
|
4
|
-
import { printHorizontalTable } from '../../utils'
|
|
5
|
-
import { InjectParams, EnvId, Log, Logger } from '../../decorators'
|
|
6
|
-
import { getLoginConfigList, updateLoginConfig, createLoginConfig } from '../../env'
|
|
7
|
-
|
|
8
|
-
const platformMap = {
|
|
9
|
-
'WECHAT-OPEN': '微信开放平台',
|
|
10
|
-
'WECHAT-PUBLIC': '微信公众平台',
|
|
11
|
-
ANONYMOUS: '匿名登录'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@ICommand()
|
|
15
|
-
export class ListLoginCommand extends Command {
|
|
16
|
-
get options() {
|
|
17
|
-
return {
|
|
18
|
-
cmd: 'env',
|
|
19
|
-
childCmd: {
|
|
20
|
-
cmd: 'login',
|
|
21
|
-
desc: '登录授权管理'
|
|
22
|
-
},
|
|
23
|
-
childSubCmd: 'list',
|
|
24
|
-
deprecateCmd: 'env:login:list',
|
|
25
|
-
options: [
|
|
26
|
-
{
|
|
27
|
-
flags: '-e, --envId <envId>',
|
|
28
|
-
desc: '环境 Id'
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
desc: '列出环境登录配置'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@InjectParams()
|
|
36
|
-
async execute(@EnvId() envId) {
|
|
37
|
-
const configList = await getLoginConfigList({
|
|
38
|
-
envId
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const head = ['平台', '平台 Id', '创建时间', '状态']
|
|
42
|
-
const tableData = configList.map((item) => [
|
|
43
|
-
platformMap[item.Platform] ? platformMap[item.Platform] : item.Platform,
|
|
44
|
-
item.PlatformId,
|
|
45
|
-
item.CreateTime,
|
|
46
|
-
item.Status === 'ENABLE' ? '启用' : '禁用'
|
|
47
|
-
])
|
|
48
|
-
printHorizontalTable(head, tableData)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@ICommand()
|
|
53
|
-
export class CreateLoginCommand extends Command {
|
|
54
|
-
get options() {
|
|
55
|
-
return {
|
|
56
|
-
cmd: 'env',
|
|
57
|
-
childCmd: 'login',
|
|
58
|
-
childSubCmd: 'create',
|
|
59
|
-
deprecateCmd: 'env:login:create',
|
|
60
|
-
options: [
|
|
61
|
-
{
|
|
62
|
-
flags: '-e, --envId <envId>',
|
|
63
|
-
desc: '环境 Id'
|
|
64
|
-
}
|
|
65
|
-
],
|
|
66
|
-
desc: '添加环境登录方式配置'
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@InjectParams()
|
|
71
|
-
async execute(@EnvId() envId, @Log() log: Logger) {
|
|
72
|
-
const { platform } = await inquirer.prompt([
|
|
73
|
-
{
|
|
74
|
-
type: 'list',
|
|
75
|
-
name: 'platform',
|
|
76
|
-
choices: [
|
|
77
|
-
{
|
|
78
|
-
name: '微信公众平台',
|
|
79
|
-
value: 'WECHAT-PUBLIC'
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: '微信开放平台',
|
|
83
|
-
value: 'WECHAT-OPEN'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: '匿名登录',
|
|
87
|
-
value: 'ANONYMOUS'
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
|
-
message: '请选择登录方式:',
|
|
91
|
-
default: 'WECHAT-PUBLIC'
|
|
92
|
-
}
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
let appId
|
|
96
|
-
let appSecret
|
|
97
|
-
|
|
98
|
-
// 微信登录,需要配置 AppId 和 AppSecret
|
|
99
|
-
if (platform === 'WECHAT-OPEN' || platform === 'WECHAT-PUBLIC') {
|
|
100
|
-
const input = await inquirer.prompt([
|
|
101
|
-
{
|
|
102
|
-
type: 'input',
|
|
103
|
-
name: 'appId',
|
|
104
|
-
message: '请输入 AppId:'
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: 'input',
|
|
108
|
-
name: 'appSecret',
|
|
109
|
-
message: '请输入 AppSecret:'
|
|
110
|
-
}
|
|
111
|
-
])
|
|
112
|
-
|
|
113
|
-
appId = input?.appId
|
|
114
|
-
appSecret = input?.appSecret
|
|
115
|
-
|
|
116
|
-
if (!appId || !appSecret) {
|
|
117
|
-
throw new CloudBaseError('appId 和 appSecret 不能为空!')
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 匿名登录
|
|
122
|
-
if (platform === 'ANONYMOUS') {
|
|
123
|
-
appId = 'anonymous'
|
|
124
|
-
appSecret = 'anonymous'
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
await createLoginConfig({
|
|
129
|
-
envId,
|
|
130
|
-
appId,
|
|
131
|
-
appSecret,
|
|
132
|
-
platform
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
log.success('创建登录方式成功!')
|
|
136
|
-
} catch (e) {
|
|
137
|
-
if (e.code === 'ResourceInUse') {
|
|
138
|
-
log.error('登录方式已开启')
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@ICommand()
|
|
145
|
-
export class UpdateLogin extends Command {
|
|
146
|
-
get options() {
|
|
147
|
-
return {
|
|
148
|
-
cmd: 'env',
|
|
149
|
-
childCmd: 'login',
|
|
150
|
-
childSubCmd: 'update',
|
|
151
|
-
deprecateCmd: 'env:login:update',
|
|
152
|
-
options: [
|
|
153
|
-
{
|
|
154
|
-
flags: '-e, --envId <envId>',
|
|
155
|
-
desc: '环境 Id'
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
desc: '更新环境登录方式配置'
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
@InjectParams()
|
|
163
|
-
async execute(@EnvId() envId, @Log() log: Logger) {
|
|
164
|
-
const configList = await getLoginConfigList({
|
|
165
|
-
envId
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
const configChoices = configList.map((item) => ({
|
|
169
|
-
name: `${platformMap[item.Platform]}:${item.PlatformId} [${
|
|
170
|
-
item.Status === 'ENABLE' ? '启用' : '禁用'
|
|
171
|
-
}]`,
|
|
172
|
-
value: item,
|
|
173
|
-
short: `${platformMap[item.Platform]}:${item.PlatformId}`
|
|
174
|
-
}))
|
|
175
|
-
|
|
176
|
-
const { config, status } = await inquirer.prompt([
|
|
177
|
-
{
|
|
178
|
-
type: 'list',
|
|
179
|
-
name: 'config',
|
|
180
|
-
choices: configChoices,
|
|
181
|
-
message: '请选择需要配置的条目:'
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
type: 'list',
|
|
185
|
-
name: 'status',
|
|
186
|
-
choices: [
|
|
187
|
-
{
|
|
188
|
-
name: '启用',
|
|
189
|
-
value: 'ENABLE'
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: '禁用',
|
|
193
|
-
value: 'DISABLE'
|
|
194
|
-
}
|
|
195
|
-
],
|
|
196
|
-
message: '请选择登录方式状态:',
|
|
197
|
-
default: '启用'
|
|
198
|
-
}
|
|
199
|
-
])
|
|
200
|
-
|
|
201
|
-
const platform = config.Platform
|
|
202
|
-
|
|
203
|
-
let appId
|
|
204
|
-
let appSecret
|
|
205
|
-
|
|
206
|
-
if (platform === 'WECHAT-OPEN' || platform === 'WECHAT-PUBLIC') {
|
|
207
|
-
const input = await inquirer.prompt([
|
|
208
|
-
{
|
|
209
|
-
type: 'input',
|
|
210
|
-
name: 'appId',
|
|
211
|
-
message: '请输入 AppId(配置状态时可不填):'
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
type: 'input',
|
|
215
|
-
name: 'appSecret',
|
|
216
|
-
message: '请输入 AppSecret(配置状态时可不填):'
|
|
217
|
-
}
|
|
218
|
-
])
|
|
219
|
-
|
|
220
|
-
appId = input?.appId
|
|
221
|
-
appSecret = input?.appSecret
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// 检查平台配置是否存在,若存在则更新配置,否则创建配置
|
|
225
|
-
await updateLoginConfig({
|
|
226
|
-
envId,
|
|
227
|
-
configId: config.Id,
|
|
228
|
-
appId,
|
|
229
|
-
appSecret,
|
|
230
|
-
status
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
log.success('更新登录方式成功!')
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { run } from '@cloudbase/framework-core'
|
|
2
|
-
import { Command, ICommand } from '../common'
|
|
3
|
-
import { ICommandContext } from '../../types'
|
|
4
|
-
import { InjectParams, CmdContext, ArgsParams, Log, Logger, ArgsOptions } from '../../decorators'
|
|
5
|
-
|
|
6
|
-
import * as Hosting from '../../hosting'
|
|
7
|
-
import * as Function from '../../function'
|
|
8
|
-
import { authSupevisor } from '../../utils'
|
|
9
|
-
|
|
10
|
-
async function callFramework(ctx, command, module, params?) {
|
|
11
|
-
const { envId, config } = ctx
|
|
12
|
-
const { bumpVersion, versionRemark } = ctx.options
|
|
13
|
-
|
|
14
|
-
const loginState = await authSupevisor.getLoginState()
|
|
15
|
-
const { token, secretId, secretKey } = loginState
|
|
16
|
-
|
|
17
|
-
await run(
|
|
18
|
-
{
|
|
19
|
-
projectPath: process.cwd(),
|
|
20
|
-
cloudbaseConfig: {
|
|
21
|
-
secretId,
|
|
22
|
-
secretKey,
|
|
23
|
-
token,
|
|
24
|
-
envId
|
|
25
|
-
},
|
|
26
|
-
config,
|
|
27
|
-
logLevel: process.argv.includes('--verbose') ? 'debug' : 'info',
|
|
28
|
-
resourceProviders: {
|
|
29
|
-
hosting: Hosting,
|
|
30
|
-
function: Function
|
|
31
|
-
},
|
|
32
|
-
bumpVersion: Boolean(bumpVersion),
|
|
33
|
-
versionRemark
|
|
34
|
-
},
|
|
35
|
-
command,
|
|
36
|
-
module,
|
|
37
|
-
params
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@ICommand()
|
|
42
|
-
export class FrameworkDeploy extends Command {
|
|
43
|
-
get options() {
|
|
44
|
-
return {
|
|
45
|
-
cmd: 'framework',
|
|
46
|
-
childCmd: 'deploy [module]',
|
|
47
|
-
deprecateCmd: 'framework:deploy [module]',
|
|
48
|
-
options: [
|
|
49
|
-
{
|
|
50
|
-
flags: '-e, --envId <envId>',
|
|
51
|
-
desc: '环境 Id'
|
|
52
|
-
},
|
|
53
|
-
{ flags: '--verbose', desc: '是否打印详细日志' }
|
|
54
|
-
],
|
|
55
|
-
desc: '云开发 Serverless 应用框架:部署全栈应用'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
@InjectParams()
|
|
60
|
-
async execute(@CmdContext() ctx: ICommandContext, @Log() logger: Logger, @ArgsParams() params) {
|
|
61
|
-
const [module] = params || []
|
|
62
|
-
await callFramework(ctx, 'deploy', module)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@ICommand()
|
|
67
|
-
export class FrameworkCompile extends Command {
|
|
68
|
-
get options() {
|
|
69
|
-
return {
|
|
70
|
-
cmd: 'framework',
|
|
71
|
-
childCmd: 'compile [module]',
|
|
72
|
-
deprecateCmd: 'framework:compile [module]',
|
|
73
|
-
options: [
|
|
74
|
-
{
|
|
75
|
-
flags: '-e, --envId <envId>',
|
|
76
|
-
desc: '环境 Id'
|
|
77
|
-
},
|
|
78
|
-
{ flags: '--verbose', desc: '是否打印详细日志' },
|
|
79
|
-
{ flags: '--bumpVersion', desc: '是否生成新版本' },
|
|
80
|
-
{
|
|
81
|
-
flags: '--versionRemark <versionRemark>',
|
|
82
|
-
desc: '新版本描述信息'
|
|
83
|
-
}
|
|
84
|
-
],
|
|
85
|
-
desc: '云开发 Serverless 应用框架:编译应用描述文件'
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@InjectParams()
|
|
90
|
-
async execute(@CmdContext() ctx: ICommandContext, @Log() logger: Logger, @ArgsParams() params) {
|
|
91
|
-
const [module] = params || []
|
|
92
|
-
await callFramework(ctx, 'compile', module)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@ICommand()
|
|
97
|
-
export class FrameworkRun extends Command {
|
|
98
|
-
get options() {
|
|
99
|
-
return {
|
|
100
|
-
cmd: 'framework',
|
|
101
|
-
childCmd: 'run [command]',
|
|
102
|
-
deprecateCmd: 'framework:run [command]',
|
|
103
|
-
options: [
|
|
104
|
-
{
|
|
105
|
-
flags: '-e, --envId <envId>',
|
|
106
|
-
desc: '环境 Id'
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
flags: '--plugin <plugin>',
|
|
110
|
-
desc: '执行命令的插件'
|
|
111
|
-
}
|
|
112
|
-
],
|
|
113
|
-
desc: '云开发 Serverless 应用框架:执行自定义命令'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@InjectParams()
|
|
118
|
-
async execute(@CmdContext() ctx: ICommandContext, @Log() logger: Logger, @ArgsParams() params, @ArgsOptions() options) {
|
|
119
|
-
const [command] = params || []
|
|
120
|
-
const { plugin } = options
|
|
121
|
-
|
|
122
|
-
await callFramework(ctx, 'run', plugin, { runCommandKey: command })
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Command, ICommand } from '../../common'
|
|
3
|
-
import { loadingFactory, printHorizontalTable } from '../../../utils'
|
|
4
|
-
import { getFunctionAliasConfig } from '../../../function'
|
|
5
|
-
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function parseRoutingConfigValue(expression: string) {
|
|
9
|
-
const commaIndex = expression.indexOf(',')
|
|
10
|
-
const valueExpression = expression.substring(commaIndex + 1, expression.length - 1)
|
|
11
|
-
return valueExpression
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@ICommand()
|
|
15
|
-
export class getFunctionRoutingConfig extends Command {
|
|
16
|
-
get options() {
|
|
17
|
-
return {
|
|
18
|
-
cmd: 'fn',
|
|
19
|
-
childCmd: 'get-route <name>',
|
|
20
|
-
options: [
|
|
21
|
-
{
|
|
22
|
-
flags: '-e, --envId <envId>',
|
|
23
|
-
desc: '环境 Id'
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
desc: '查看函数版本流量配置'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@InjectParams()
|
|
31
|
-
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
32
|
-
const name = params?.[0]
|
|
33
|
-
|
|
34
|
-
const {
|
|
35
|
-
envId
|
|
36
|
-
} = ctx
|
|
37
|
-
|
|
38
|
-
const loading = loadingFactory()
|
|
39
|
-
loading.start(`查询函数 [${name}] 版本流量配置中...`)
|
|
40
|
-
|
|
41
|
-
const aliasRes = await getFunctionAliasConfig({
|
|
42
|
-
envId,
|
|
43
|
-
functionName: name,
|
|
44
|
-
name: '$DEFAULT'
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const routingConfig = aliasRes?.RoutingConfig?.AddtionVersionMatchs
|
|
48
|
-
let finalConfig = []
|
|
49
|
-
if (routingConfig.length === 1) {
|
|
50
|
-
finalConfig.push({
|
|
51
|
-
version: routingConfig[0].Version,
|
|
52
|
-
value: parseRoutingConfigValue(routingConfig[0].Expression)
|
|
53
|
-
})
|
|
54
|
-
} else if (routingConfig.length === 2) {
|
|
55
|
-
finalConfig.push({
|
|
56
|
-
version: routingConfig[0].Version,
|
|
57
|
-
value: parseRoutingConfigValue(routingConfig[0].Expression)
|
|
58
|
-
}, {
|
|
59
|
-
version: routingConfig[1].Version,
|
|
60
|
-
value: 100 - Number(parseRoutingConfigValue(routingConfig[0].Expression))
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
loading.stop()
|
|
65
|
-
|
|
66
|
-
const head: string[] = ['版本', '流量比例']
|
|
67
|
-
|
|
68
|
-
const tableData = finalConfig.map((item) => [
|
|
69
|
-
item.version,
|
|
70
|
-
item.value
|
|
71
|
-
])
|
|
72
|
-
|
|
73
|
-
printHorizontalTable(head, tableData)
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Command, ICommand } from '../../common'
|
|
3
|
-
import { CloudBaseError } from '../../../error'
|
|
4
|
-
import { loadingFactory } from '../../../utils'
|
|
5
|
-
import { setFunctionAliasConfig } from '../../../function'
|
|
6
|
-
import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@ICommand()
|
|
10
|
-
export class setFunctionRoutingConfig extends Command {
|
|
11
|
-
get options() {
|
|
12
|
-
return {
|
|
13
|
-
cmd: 'fn',
|
|
14
|
-
childCmd: 'config-route <name> <version1> <traffic1> [version2] [traffic2]',
|
|
15
|
-
options: [
|
|
16
|
-
{
|
|
17
|
-
flags: '-e, --envId <envId>',
|
|
18
|
-
desc: '环境 Id'
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
desc: '设置函数版本流量配置'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@InjectParams()
|
|
26
|
-
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
27
|
-
const name = params?.[0]
|
|
28
|
-
const version1 = params?.[1]
|
|
29
|
-
const traffic1 = Number(params?.[2])
|
|
30
|
-
|
|
31
|
-
const version2 = params?.[3]
|
|
32
|
-
const traffic2 = Number(params?.[4])
|
|
33
|
-
|
|
34
|
-
// 校验
|
|
35
|
-
|
|
36
|
-
// 1. version2 及 traffic2 必须同时存在
|
|
37
|
-
if ((version2 === undefined && traffic2 !== undefined) || (version2 !== undefined && traffic2 === undefined)) {
|
|
38
|
-
throw new CloudBaseError('version2 和 traffic2 必须同时设置')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (traffic1 !== undefined && traffic2 !== undefined) {
|
|
42
|
-
if (traffic1 + traffic2 !== 100) {
|
|
43
|
-
throw new CloudBaseError('traffic1 和 traffic2 同时设置时,需保证总和 100')
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const {
|
|
48
|
-
envId
|
|
49
|
-
} = ctx
|
|
50
|
-
|
|
51
|
-
const loading = loadingFactory()
|
|
52
|
-
loading.start(`设置函数 [${name}] 版本流量配置中...`)
|
|
53
|
-
|
|
54
|
-
let routingConfigParams = {
|
|
55
|
-
AddtionVersionMatchs: [{
|
|
56
|
-
Expression: `[0,${traffic1})`,
|
|
57
|
-
Key: "invoke.headers.X-Tcb-Route-Key",
|
|
58
|
-
Method: "range",
|
|
59
|
-
Version: version1
|
|
60
|
-
}]
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (version2 !== undefined) {
|
|
64
|
-
routingConfigParams.AddtionVersionMatchs.push({
|
|
65
|
-
Expression: `[${traffic1},${100})`,
|
|
66
|
-
Key: "invoke.headers.X-Tcb-Route-Key",
|
|
67
|
-
Method: "range",
|
|
68
|
-
Version: version2
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
await setFunctionAliasConfig({
|
|
73
|
-
envId,
|
|
74
|
-
functionName: name,
|
|
75
|
-
name: '$DEFAULT',
|
|
76
|
-
functionVersion: '$LATEST',
|
|
77
|
-
routingConfig: routingConfigParams
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
loading.succeed(`设置函数 [${name}] 版本流量配置成功!`)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fse from 'fs-extra'
|
|
3
|
-
import inquirer from 'inquirer'
|
|
4
|
-
import { Command, ICommand } from '../common'
|
|
5
|
-
import { CloudBaseError } from '../../error'
|
|
6
|
-
import { InjectParams, CmdContext, ArgsParams } from '../../decorators'
|
|
7
|
-
import { downloadFunctionCode, getFunctionDetail } from '../../function'
|
|
8
|
-
import { loadingFactory, checkFullAccess, delSync, highlightCommand } from '../../utils'
|
|
9
|
-
|
|
10
|
-
@ICommand()
|
|
11
|
-
export class CodeDownload extends Command {
|
|
12
|
-
get options() {
|
|
13
|
-
return {
|
|
14
|
-
cmd: 'fn',
|
|
15
|
-
childCmd: {
|
|
16
|
-
cmd: 'code',
|
|
17
|
-
desc: '函数代码管理'
|
|
18
|
-
},
|
|
19
|
-
childSubCmd: 'download <name> [dest]',
|
|
20
|
-
deprecateCmd: 'functions:download <name> [dest]',
|
|
21
|
-
options: [
|
|
22
|
-
{
|
|
23
|
-
flags: '-e, --envId <envId>',
|
|
24
|
-
desc: '环境 Id'
|
|
25
|
-
},
|
|
26
|
-
{ flags: '-l, --limit <limit>', desc: '返回数据长度,默认值为 20' },
|
|
27
|
-
{
|
|
28
|
-
flags: '--code-secret <codeSecret>',
|
|
29
|
-
desc: '代码加密的函数的 CodeSecret'
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
desc: '下载云函数代码'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@InjectParams()
|
|
37
|
-
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
38
|
-
const { envId, config, options } = ctx
|
|
39
|
-
const { codeSecret } = options
|
|
40
|
-
|
|
41
|
-
const name = params?.[0]
|
|
42
|
-
const dest = params?.[1]
|
|
43
|
-
|
|
44
|
-
if (!name) {
|
|
45
|
-
throw new CloudBaseError('请指定云函数名称!')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 检查函数是否存在
|
|
49
|
-
try {
|
|
50
|
-
await getFunctionDetail({
|
|
51
|
-
envId,
|
|
52
|
-
codeSecret,
|
|
53
|
-
functionName: name
|
|
54
|
-
})
|
|
55
|
-
} catch (e) {
|
|
56
|
-
if (e.code === 'ResourceNotFound.FunctionName') {
|
|
57
|
-
throw new CloudBaseError(
|
|
58
|
-
`云函数 [${name}] 不存在!\n\n使用 ${highlightCommand(
|
|
59
|
-
'cloudbase functions:list'
|
|
60
|
-
)} 命令查看已部署云函数`
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
let destPath = dest
|
|
67
|
-
|
|
68
|
-
// 没有指定下载路径时,使用函数名作为存储文件夹
|
|
69
|
-
if (!destPath) {
|
|
70
|
-
destPath = path.resolve(config.functionRoot, name)
|
|
71
|
-
// 路径已存在,询问是否覆盖
|
|
72
|
-
if (checkFullAccess(destPath)) {
|
|
73
|
-
const { override } = await inquirer.prompt({
|
|
74
|
-
type: 'confirm',
|
|
75
|
-
name: 'override',
|
|
76
|
-
message: '函数已经存在,是否覆盖原文件?',
|
|
77
|
-
default: false
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
if (!override) {
|
|
81
|
-
throw new CloudBaseError('下载终止!')
|
|
82
|
-
}
|
|
83
|
-
// 删除原文件
|
|
84
|
-
delSync([destPath])
|
|
85
|
-
}
|
|
86
|
-
await fse.ensureDir(destPath)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const loading = loadingFactory()
|
|
90
|
-
loading.start('文件下载中...')
|
|
91
|
-
await downloadFunctionCode({
|
|
92
|
-
envId,
|
|
93
|
-
functionName: name,
|
|
94
|
-
destPath: destPath,
|
|
95
|
-
codeSecret: codeSecret,
|
|
96
|
-
unzip: true
|
|
97
|
-
})
|
|
98
|
-
loading.succeed(`[${name}] 云函数代码下载成功!`)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { Command, ICommand } from '../common'
|
|
3
|
-
import { CloudBaseError } from '../../error'
|
|
4
|
-
import { loadingFactory } from '../../utils'
|
|
5
|
-
import { updateFunctionCode } from '../../function'
|
|
6
|
-
import { InjectParams, CmdContext, ArgsParams } from '../../decorators'
|
|
7
|
-
|
|
8
|
-
@ICommand()
|
|
9
|
-
export class CodeUpdate extends Command {
|
|
10
|
-
get options() {
|
|
11
|
-
return {
|
|
12
|
-
cmd: 'fn',
|
|
13
|
-
childCmd: {
|
|
14
|
-
cmd: 'code',
|
|
15
|
-
desc: '函数代码管理'
|
|
16
|
-
},
|
|
17
|
-
childSubCmd: 'update <name>',
|
|
18
|
-
deprecateCmd: 'functions:code:update <name>',
|
|
19
|
-
options: [
|
|
20
|
-
{
|
|
21
|
-
flags: '-e, --envId <envId>',
|
|
22
|
-
desc: '环境 Id'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
flags: '--code-secret <codeSecret>',
|
|
26
|
-
desc: '传入此参数将保护代码,格式为 36 位大小写字母和数字'
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
desc: '更新云函数代码'
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@InjectParams()
|
|
34
|
-
async execute(@CmdContext() ctx, @ArgsParams() params) {
|
|
35
|
-
const { envId, config, options } = ctx
|
|
36
|
-
const { codeSecret } = options
|
|
37
|
-
|
|
38
|
-
const name = params?.[0]
|
|
39
|
-
|
|
40
|
-
if (!name) {
|
|
41
|
-
throw new CloudBaseError('请指定云函数名称!')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const func = config.functions.find((item) => item.name === name) || { name }
|
|
45
|
-
|
|
46
|
-
const loading = loadingFactory()
|
|
47
|
-
|
|
48
|
-
loading.start(`[${func.name}] 函数代码更新中...`)
|
|
49
|
-
try {
|
|
50
|
-
await updateFunctionCode({
|
|
51
|
-
func,
|
|
52
|
-
envId,
|
|
53
|
-
codeSecret,
|
|
54
|
-
functionRootPath: path.join(process.cwd(), config.functionRoot)
|
|
55
|
-
})
|
|
56
|
-
loading.succeed(`[${func.name}] 函数代码更新成功!`)
|
|
57
|
-
} catch (e) {
|
|
58
|
-
loading.stop()
|
|
59
|
-
throw e
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|