@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.
Files changed (244) hide show
  1. package/.vscode/launch.json +0 -10
  2. package/.vscode/settings.json +3 -0
  3. package/bin/cloudbase.js +0 -0
  4. package/bin/tcb.js +0 -0
  5. package/lib/commands/lowcode/app.js +2 -30
  6. package/lib/run/service/deployPackage.js +2 -9
  7. package/lib/utils/checkTcbrEnv.js +5 -4
  8. package/lib/utils/debug-logger.js +30 -0
  9. package/lib/utils/net/cloud-api-request.js +7 -1
  10. package/lib/utils/net/http-request.js +16 -5
  11. package/package.json +5 -4
  12. package/types/commands/lowcode/app.d.ts +0 -10
  13. package/types/utils/debug-logger.d.ts +1 -0
  14. package/types/utils/net/http-request.d.ts +6 -2
  15. package/.history/.gitignore_20220624162613 +0 -84
  16. package/.history/.gitignore_20220627114054 +0 -86
  17. package/.history/package_20220711204706.json +0 -88
  18. package/.history/package_20220711204818.json +0 -88
  19. package/.history/package_20220712151717.json +0 -88
  20. package/.history/src/commands/lowcode/app_20220624162613.ts +0 -34
  21. package/.history/src/commands/lowcode/app_20220627114205.ts +0 -52
  22. package/.history/src/index_20220624162613.ts +0 -13
  23. package/.history/src/index_20220627113609.ts +0 -15
  24. package/.history/src/index_20220627114102.ts +0 -13
  25. package/src/auth/index.ts +0 -2
  26. package/src/auth/login.ts +0 -91
  27. package/src/auth/logout.ts +0 -7
  28. package/src/commands/account/index.ts +0 -2
  29. package/src/commands/account/login.ts +0 -192
  30. package/src/commands/account/logout.ts +0 -24
  31. package/src/commands/common.ts +0 -246
  32. package/src/commands/env/base.ts +0 -90
  33. package/src/commands/env/create.ts +0 -92
  34. package/src/commands/env/domain.ts +0 -186
  35. package/src/commands/env/index.ts +0 -4
  36. package/src/commands/env/login.ts +0 -235
  37. package/src/commands/framework/index.ts +0 -124
  38. package/src/commands/functions/alias/getRoute.ts +0 -76
  39. package/src/commands/functions/alias/index.ts +0 -2
  40. package/src/commands/functions/alias/setRoute.ts +0 -82
  41. package/src/commands/functions/code-download.ts +0 -100
  42. package/src/commands/functions/code-update.ts +0 -62
  43. package/src/commands/functions/concurrency/delete.ts +0 -45
  44. package/src/commands/functions/concurrency/index.ts +0 -3
  45. package/src/commands/functions/concurrency/list.ts +0 -58
  46. package/src/commands/functions/concurrency/set.ts +0 -47
  47. package/src/commands/functions/config-update.ts +0 -76
  48. package/src/commands/functions/copy.ts +0 -62
  49. package/src/commands/functions/delete.ts +0 -79
  50. package/src/commands/functions/deploy.ts +0 -293
  51. package/src/commands/functions/detail.ts +0 -138
  52. package/src/commands/functions/index.ts +0 -16
  53. package/src/commands/functions/invoke.ts +0 -121
  54. package/src/commands/functions/layer/bind.ts +0 -182
  55. package/src/commands/functions/layer/common.ts +0 -8
  56. package/src/commands/functions/layer/create.ts +0 -49
  57. package/src/commands/functions/layer/delete.ts +0 -73
  58. package/src/commands/functions/layer/download.ts +0 -92
  59. package/src/commands/functions/layer/index.ts +0 -7
  60. package/src/commands/functions/layer/list.ts +0 -94
  61. package/src/commands/functions/layer/sort.ts +0 -76
  62. package/src/commands/functions/list.ts +0 -68
  63. package/src/commands/functions/log.ts +0 -148
  64. package/src/commands/functions/run.ts +0 -249
  65. package/src/commands/functions/trigger-create.ts +0 -79
  66. package/src/commands/functions/trigger-delete.ts +0 -105
  67. package/src/commands/functions/version/index.ts +0 -2
  68. package/src/commands/functions/version/list.ts +0 -73
  69. package/src/commands/functions/version/publish.ts +0 -43
  70. package/src/commands/gateway/create.ts +0 -109
  71. package/src/commands/gateway/delete.ts +0 -81
  72. package/src/commands/gateway/domain.ts +0 -159
  73. package/src/commands/gateway/index.ts +0 -5
  74. package/src/commands/gateway/list.ts +0 -76
  75. package/src/commands/gateway/switch.ts +0 -107
  76. package/src/commands/helpers/index.ts +0 -3
  77. package/src/commands/helpers/init.ts +0 -431
  78. package/src/commands/helpers/new.ts +0 -117
  79. package/src/commands/helpers/open.ts +0 -67
  80. package/src/commands/hosting/hosting.ts +0 -360
  81. package/src/commands/hosting/index.ts +0 -1
  82. package/src/commands/index.ts +0 -13
  83. package/src/commands/lowcode/app.ts +0 -52
  84. package/src/commands/lowcode/comps.ts +0 -325
  85. package/src/commands/lowcode/index.ts +0 -2
  86. package/src/commands/lowcode/utils.ts +0 -25
  87. package/src/commands/run/create.ts +0 -153
  88. package/src/commands/run/delete.ts +0 -77
  89. package/src/commands/run/image/common.ts +0 -8
  90. package/src/commands/run/image/delete.ts +0 -68
  91. package/src/commands/run/image/download.ts +0 -68
  92. package/src/commands/run/image/index.ts +0 -5
  93. package/src/commands/run/image/list.ts +0 -84
  94. package/src/commands/run/image/upload.ts +0 -76
  95. package/src/commands/run/index.ts +0 -7
  96. package/src/commands/run/list.ts +0 -83
  97. package/src/commands/run/service/config.ts +0 -81
  98. package/src/commands/run/service/create.ts +0 -122
  99. package/src/commands/run/service/deploy.ts +0 -125
  100. package/src/commands/run/service/index.ts +0 -5
  101. package/src/commands/run/service/list.ts +0 -94
  102. package/src/commands/run/service/update.ts +0 -108
  103. package/src/commands/run/standalonegateway/common.ts +0 -8
  104. package/src/commands/run/standalonegateway/create.ts +0 -85
  105. package/src/commands/run/standalonegateway/destroy.ts +0 -59
  106. package/src/commands/run/standalonegateway/index.ts +0 -5
  107. package/src/commands/run/standalonegateway/list.ts +0 -53
  108. package/src/commands/run/standalonegateway/package.ts +0 -62
  109. package/src/commands/run/standalonegateway/turn.ts +0 -63
  110. package/src/commands/run/version/common.ts +0 -8
  111. package/src/commands/run/version/create.ts +0 -369
  112. package/src/commands/run/version/delete.ts +0 -64
  113. package/src/commands/run/version/index.ts +0 -5
  114. package/src/commands/run/version/list.ts +0 -91
  115. package/src/commands/run/version/modify.ts +0 -137
  116. package/src/commands/run/version/update.ts +0 -398
  117. package/src/commands/smart.ts +0 -132
  118. package/src/commands/storage/index.ts +0 -1
  119. package/src/commands/storage/storage.ts +0 -464
  120. package/src/commands/third/index.ts +0 -1
  121. package/src/commands/third/thirdAttach.ts +0 -49
  122. package/src/completion/index.ts +0 -13
  123. package/src/constant.ts +0 -154
  124. package/src/decorators/captureError.ts +0 -25
  125. package/src/decorators/constants.ts +0 -12
  126. package/src/decorators/deprecate.ts +0 -25
  127. package/src/decorators/guard.ts +0 -42
  128. package/src/decorators/index.ts +0 -7
  129. package/src/decorators/injectParams.ts +0 -54
  130. package/src/decorators/params/common.ts +0 -28
  131. package/src/decorators/params/index.ts +0 -35
  132. package/src/env/domain.ts +0 -33
  133. package/src/env/index.ts +0 -63
  134. package/src/env/login.ts +0 -80
  135. package/src/error.ts +0 -36
  136. package/src/function/alias.ts +0 -43
  137. package/src/function/base.ts +0 -253
  138. package/src/function/code.ts +0 -55
  139. package/src/function/concurrency.ts +0 -57
  140. package/src/function/create.ts +0 -78
  141. package/src/function/delete.ts +0 -42
  142. package/src/function/index.ts +0 -11
  143. package/src/function/layer/attach.ts +0 -68
  144. package/src/function/layer/create.ts +0 -63
  145. package/src/function/layer/delete.ts +0 -21
  146. package/src/function/layer/download.ts +0 -54
  147. package/src/function/layer/index.ts +0 -7
  148. package/src/function/layer/list.ts +0 -32
  149. package/src/function/layer/sort.ts +0 -24
  150. package/src/function/trigger.ts +0 -97
  151. package/src/function/update.ts +0 -35
  152. package/src/function/version.ts +0 -39
  153. package/src/function/vpc.ts +0 -22
  154. package/src/gateway/index.ts +0 -137
  155. package/src/help.ts +0 -50
  156. package/src/hosting.ts +0 -212
  157. package/src/index.ts +0 -13
  158. package/src/logger.ts +0 -17
  159. package/src/run/create.ts +0 -23
  160. package/src/run/delete.ts +0 -15
  161. package/src/run/image/build.ts +0 -36
  162. package/src/run/image/delete.ts +0 -14
  163. package/src/run/image/index.ts +0 -4
  164. package/src/run/image/info.ts +0 -27
  165. package/src/run/image/list.ts +0 -23
  166. package/src/run/index.ts +0 -8
  167. package/src/run/list.ts +0 -30
  168. package/src/run/repo.ts +0 -25
  169. package/src/run/service/common.ts +0 -311
  170. package/src/run/service/config.ts +0 -77
  171. package/src/run/service/create.ts +0 -52
  172. package/src/run/service/deployPackage.ts +0 -65
  173. package/src/run/service/index.ts +0 -7
  174. package/src/run/service/list.ts +0 -29
  175. package/src/run/service/showLogs.ts +0 -98
  176. package/src/run/service/update.ts +0 -82
  177. package/src/run/standalonegateway/create.ts +0 -24
  178. package/src/run/standalonegateway/destroy.ts +0 -19
  179. package/src/run/standalonegateway/index.ts +0 -5
  180. package/src/run/standalonegateway/list.ts +0 -74
  181. package/src/run/standalonegateway/package/index.ts +0 -1
  182. package/src/run/standalonegateway/package/list.ts +0 -24
  183. package/src/run/standalonegateway/turn/index.ts +0 -2
  184. package/src/run/standalonegateway/turn/off.ts +0 -19
  185. package/src/run/standalonegateway/turn/on.ts +0 -19
  186. package/src/run/version/create.ts +0 -68
  187. package/src/run/version/delete.ts +0 -16
  188. package/src/run/version/index.ts +0 -6
  189. package/src/run/version/list.ts +0 -17
  190. package/src/run/version/modify.ts +0 -17
  191. package/src/run/version/repo.ts +0 -28
  192. package/src/run/version/update.ts +0 -59
  193. package/src/storage.ts +0 -114
  194. package/src/third/index.ts +0 -13
  195. package/src/types.ts +0 -672
  196. package/src/utils/auth.ts +0 -15
  197. package/src/utils/checkTcbrEnv.ts +0 -67
  198. package/src/utils/cli-table.ts +0 -23
  199. package/src/utils/commonParamsCheck.ts +0 -65
  200. package/src/utils/config.ts +0 -39
  201. package/src/utils/env.ts +0 -244
  202. package/src/utils/fs/del.ts +0 -5
  203. package/src/utils/fs/index.ts +0 -71
  204. package/src/utils/function-packer.ts +0 -97
  205. package/src/utils/index.ts +0 -25
  206. package/src/utils/log.ts +0 -82
  207. package/src/utils/net/cloud-api-request.ts +0 -62
  208. package/src/utils/net/credential.ts +0 -53
  209. package/src/utils/net/http-request.ts +0 -84
  210. package/src/utils/net/index.ts +0 -5
  211. package/src/utils/net/manager-service.ts +0 -36
  212. package/src/utils/net/proxy.ts +0 -6
  213. package/src/utils/notice.ts +0 -28
  214. package/src/utils/output/highlight.ts +0 -5
  215. package/src/utils/output/index.ts +0 -3
  216. package/src/utils/output/link.ts +0 -10
  217. package/src/utils/output/loading.ts +0 -82
  218. package/src/utils/parallel.ts +0 -82
  219. package/src/utils/platform/index.ts +0 -3
  220. package/src/utils/platform/mac.ts +0 -21
  221. package/src/utils/platform/os.ts +0 -64
  222. package/src/utils/platform/port.ts +0 -10
  223. package/src/utils/progress-bar.ts +0 -38
  224. package/src/utils/prompt/index.ts +0 -1
  225. package/src/utils/prompt/select.ts +0 -60
  226. package/src/utils/reporter/agree.ts +0 -20
  227. package/src/utils/reporter/download.ts +0 -26
  228. package/src/utils/reporter/index.ts +0 -3
  229. package/src/utils/reporter/usage.ts +0 -20
  230. package/src/utils/store/auth.ts +0 -49
  231. package/src/utils/store/common.ts +0 -8
  232. package/src/utils/store/db.ts +0 -68
  233. package/src/utils/store/index.ts +0 -5
  234. package/src/utils/store/usage.ts +0 -12
  235. package/src/utils/tcbrApi/callTcbrApi.ts +0 -28
  236. package/src/utils/tcbrApi/index.ts +0 -1
  237. package/src/utils/template.ts +0 -170
  238. package/src/utils/tools/encoding.ts +0 -8
  239. package/src/utils/tools/index.ts +0 -4
  240. package/src/utils/tools/object.ts +0 -33
  241. package/src/utils/tools/time.ts +0 -38
  242. package/src/utils/tools/uid.ts +0 -19
  243. package/src/utils/validator.ts +0 -65
  244. package/yarn-error.log +0 -12841
@@ -1,79 +0,0 @@
1
- import inquirer from 'inquirer'
2
- import { Command, ICommand } from '../common'
3
- import { successLog } from '../../logger'
4
- import { CloudBaseError } from '../../error'
5
- import { createFunctionTriggers, batchCreateTriggers } from '../../function'
6
- import { InjectParams, CmdContext, ArgsParams } from '../../decorators'
7
-
8
- @ICommand()
9
- export class CreateTrigger extends Command {
10
- get options() {
11
- return {
12
- cmd: 'fn',
13
- childCmd: { cmd: 'trigger', desc: '函数触发器操作' },
14
- childSubCmd: 'create [functionName]',
15
- deprecateCmd: 'functions:trigger:create [functionName]',
16
- options: [
17
- {
18
- flags: '-e, --envId <envId>',
19
- desc: '环境 Id'
20
- }
21
- ],
22
- desc: '创建云函数触发器'
23
- }
24
- }
25
-
26
- @InjectParams()
27
- async execute(@CmdContext() ctx, @ArgsParams() params) {
28
- const {
29
- envId,
30
- config: { functions }
31
- } = ctx
32
-
33
- const name = params?.[0]
34
-
35
- let isBatchCreateTrigger = false
36
-
37
- // 不指定云函数名称,创建配置文件中所有函数的所有触发器
38
- if (!name) {
39
- const { isBatch } = await inquirer.prompt({
40
- type: 'confirm',
41
- name: 'isBatch',
42
- message: '无云函数名称,是否需要部署配置文件中的【全部云函数】的全部触发器?',
43
- default: false
44
- })
45
-
46
- isBatchCreateTrigger = isBatch
47
-
48
- if (!isBatchCreateTrigger) {
49
- throw new CloudBaseError('请指定云函数名称!')
50
- }
51
- }
52
-
53
- if (isBatchCreateTrigger) {
54
- return batchCreateTriggers({
55
- envId,
56
- functions
57
- })
58
- }
59
-
60
- const functionItem = functions.find((item) => item.name === name)
61
-
62
- if (!functionItem) {
63
- throw new CloudBaseError('未找到相关函数配置,请检查函数名是否正确')
64
- }
65
-
66
- const { triggers } = functionItem
67
-
68
- if (!triggers || !triggers.length) {
69
- throw new CloudBaseError('触发器配置不能为空')
70
- }
71
-
72
- await createFunctionTriggers({
73
- envId,
74
- functionName: name,
75
- triggers
76
- })
77
- successLog(`[${name}] 创建云函数触发器成功!`)
78
- }
79
- }
@@ -1,105 +0,0 @@
1
- import inquirer from 'inquirer'
2
- import { Command, ICommand } from '../common'
3
- import { CloudBaseError } from '../../error'
4
- import { InjectParams, CmdContext, ArgsParams } from '../../decorators'
5
- import { batchDeleteTriggers, deleteFunctionTrigger } from '../../function'
6
-
7
- @ICommand()
8
- export class DeleteTrigger extends Command {
9
- get options() {
10
- return {
11
- cmd: 'fn',
12
- childCmd: { cmd: 'trigger', desc: '函数触发器操作' },
13
- childSubCmd: 'delete [functionName] [triggerName]',
14
- deprecateCmd: 'functions:trigger:delete [functionName] [triggerName]',
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 {
28
- envId,
29
- config: { functions }
30
- } = ctx
31
-
32
- const name = params?.[0]
33
- const triggerName = params?.[1]
34
-
35
- let isBatchDeleteTriggers
36
- let isBatchDeleteFunctionTriggers = false
37
-
38
- // 不指定云函数名称,删除配置文件中所有函数的所有触发器
39
- if (!name) {
40
- const answer = await inquirer.prompt({
41
- type: 'confirm',
42
- name: 'isBatch',
43
- message: '无云函数名称,是否需要删除配置文件中的【全部云函数】的全部触发器?',
44
- default: false
45
- })
46
-
47
- // 危险操作,再次确认
48
- if (answer.isBatch) {
49
- const { reConfirm } = await inquirer.prompt({
50
- type: 'confirm',
51
- name: 'reConfirm',
52
- message: '确定要删除配置文件中的【全部云函数】的全部触发器?',
53
- default: false
54
- })
55
- isBatchDeleteTriggers = reConfirm
56
- }
57
-
58
- if (!isBatchDeleteTriggers) {
59
- throw new CloudBaseError('请指定云函数名称以及触发器名称!')
60
- }
61
- }
62
-
63
- if (isBatchDeleteTriggers) {
64
- return batchDeleteTriggers({
65
- envId,
66
- functions
67
- })
68
- }
69
-
70
- // 指定了函数名称,但没有指定触发器名称,删除此函数的所有触发器
71
- if (!triggerName && name) {
72
- const { isBatch } = await inquirer.prompt({
73
- type: 'confirm',
74
- name: 'isBatch',
75
- message: '没有指定触发器名称,是否需要此云函数的全部触发器?',
76
- default: false
77
- })
78
-
79
- isBatchDeleteFunctionTriggers = isBatch
80
-
81
- if (!isBatchDeleteFunctionTriggers) {
82
- throw new CloudBaseError('请指定云函数名称以及触发器名称!')
83
- }
84
- }
85
-
86
- if (isBatchDeleteFunctionTriggers) {
87
- const func = functions.find((item) => item.name === name)
88
- return batchDeleteTriggers({
89
- envId,
90
- functions: [func]
91
- })
92
- }
93
-
94
- if (!triggerName) {
95
- throw new CloudBaseError('触发器名称不能为空')
96
- }
97
-
98
- // 删除指定函数的单个触发器
99
- await deleteFunctionTrigger({
100
- envId,
101
- functionName: name,
102
- triggerName
103
- })
104
- }
105
- }
@@ -1,2 +0,0 @@
1
- export * from './publish'
2
- export * from './list'
@@ -1,73 +0,0 @@
1
-
2
- import { Command, ICommand } from '../../common'
3
- import { CloudBaseError } from '../../../error'
4
- import { loadingFactory, printHorizontalTable } from '../../../utils'
5
- import { listFunctionVersions } from '../../../function'
6
- import { InjectParams, CmdContext, ArgsParams, ArgsOptions } from '../../../decorators'
7
- import { StatusMap } from '../../../constant'
8
-
9
-
10
- @ICommand()
11
- export class ListFunctionVersion extends Command {
12
- get options() {
13
- return {
14
- cmd: 'fn',
15
- childCmd: 'list-function-versions <name>',
16
- options: [
17
- {
18
- flags: '-e, --envId <envId>',
19
- desc: '环境 Id'
20
- },
21
- { flags: '-l, --limit <limit>', desc: '返回数据长度,默认值为 20' },
22
- {
23
- flags: '-o, --offset <offset>',
24
- desc: '数据偏移量,默认值为 0'
25
- }
26
- ],
27
- desc: '展示函数版本列表'
28
- }
29
- }
30
-
31
- @InjectParams()
32
- async execute(@CmdContext() ctx, @ArgsParams() params, @ArgsOptions() options) {
33
- const name = params?.[0]
34
- let { limit = 20, offset = 0 } = options
35
- limit = Number(limit)
36
- offset = Number(offset)
37
- if (!Number.isInteger(limit) || !Number.isInteger(offset)) {
38
- throw new CloudBaseError('limit 和 offset 必须为整数')
39
- }
40
-
41
- if (limit < 0 || offset < 0) {
42
- throw new CloudBaseError('limit 和 offset 必须为大于 0 的整数')
43
- }
44
-
45
- const {
46
- envId
47
- } = ctx
48
-
49
- const loading = loadingFactory()
50
- loading.start(`拉取函数 [${name}] 版本列表中...`)
51
-
52
- const res = await listFunctionVersions({
53
- envId,
54
- functionName: name,
55
- offset,
56
- limit
57
- })
58
-
59
- loading.stop()
60
-
61
- const head: string[] = ['版本', '描述', '创建时间', '修改时间', '状态']
62
-
63
- const tableData = res.Versions.map((item) => [
64
- item.Version,
65
- item.Description,
66
- item.AddTime,
67
- item.ModTime,
68
- StatusMap[item.Status]
69
- ])
70
-
71
- printHorizontalTable(head, tableData)
72
- }
73
- }
@@ -1,43 +0,0 @@
1
-
2
- import { Command, ICommand } from '../../common'
3
- import { CloudBaseError } from '../../../error'
4
- import { loadingFactory } from '../../../utils'
5
- import { publishVersion } from '../../../function'
6
- import { InjectParams, CmdContext, ArgsParams } from '../../../decorators'
7
-
8
- @ICommand()
9
- export class PublishFunctionVersion extends Command {
10
- get options() {
11
- return {
12
- cmd: 'fn',
13
- childCmd: 'publish-version <name> [description]',
14
- options: [
15
- {
16
- flags: '-e, --envId <envId>',
17
- desc: '环境 Id'
18
- }
19
- ],
20
- desc: '发布函数新版本'
21
- }
22
- }
23
-
24
- @InjectParams()
25
- async execute(@CmdContext() ctx, @ArgsParams() params) {
26
- const name = params?.[0]
27
- const description = params?.[1]
28
- const {
29
- envId
30
- } = ctx
31
-
32
- const loading = loadingFactory()
33
- loading.start(`发布函数 [${name}] 新版本中...`)
34
-
35
- await publishVersion({
36
- envId,
37
- functionName: name,
38
- description
39
- })
40
-
41
- loading.succeed(`发布函数 [${name}] 新版本成功!`)
42
- }
43
- }
@@ -1,109 +0,0 @@
1
- import { prompt } from 'enquirer'
2
- import { Command, ICommand } from '../common'
3
- import { CloudBaseError } from '../../error'
4
- import { createGateway, queryGatewayDomain } from '../../gateway'
5
- import { listFunction } from '../../function'
6
- import { assertTruthy } from '../../utils/validator'
7
- import { loadingFactory, genClickableLink } from '../../utils'
8
- import { InjectParams, EnvId, ArgsOptions } from '../../decorators'
9
-
10
- @ICommand()
11
- export class CreateService extends Command {
12
- get options() {
13
- return {
14
- cmd: 'service',
15
- childCmd: 'create',
16
- deprecateCmd: 'service:create',
17
- options: [
18
- {
19
- flags: '-e, --envId <envId>',
20
- desc: '环境 Id'
21
- },
22
- {
23
- flags: '-p, --service-path <servicePath>',
24
- desc: 'HTTP 访问服务路径,如 api'
25
- },
26
- {
27
- flags: '-f, --function <name>',
28
- desc: 'HTTP 访问服务路径绑定的云函数名称'
29
- }
30
- ],
31
- desc: '创建 HTTP 访问服务'
32
- }
33
- }
34
-
35
- @InjectParams()
36
- async execute(@EnvId() envId, @ArgsOptions() options) {
37
- let { function: functionName, servicePath } = options
38
- const loading = loadingFactory()
39
-
40
- if (!servicePath || !functionName) {
41
- loading.start('数据加载中...')
42
- const functions = await listFunction({
43
- envId,
44
- limit: 100,
45
- offset: 0
46
- })
47
-
48
- loading.stop()
49
-
50
- if (!functions.length) {
51
- throw new CloudBaseError('当前环境下不存在可用的云函数,请先创建云函数!')
52
- }
53
-
54
- let { name } = await prompt<any>({
55
- type: 'select',
56
- name: 'name',
57
- message: '请选择创建HTTP 访问服务的云函数',
58
- choices: functions.map((item) => item.FunctionName)
59
- })
60
-
61
- let { path } = await prompt<any>({
62
- type: 'input',
63
- name: 'path',
64
- message: '请输入HTTP 访问服务路径'
65
- })
66
-
67
- functionName = name
68
- servicePath = path
69
- }
70
-
71
- assertTruthy(servicePath, '请指定需要创建的HTTP 访问服务路径!')
72
-
73
- // 创建云函数网关
74
- loading.start(`[${functionName}] HTTP 访问服务创建中...`)
75
-
76
- // 补充 / 符号
77
- servicePath = servicePath[0] === '/' ? servicePath : `/${servicePath}`
78
-
79
- try {
80
- // step1: 判断云函数是否存在
81
- const functionList = await listFunction({
82
- envId,
83
- limit: 100
84
- })
85
- const isExisted = functionList.filter((item) => item.FunctionName === functionName)
86
- if (isExisted.length <= 0) {
87
- throw new CloudBaseError(`[${functionName}] 云函数不存在!`)
88
- }
89
-
90
- // step2: 创建云函数网关
91
- await createGateway({
92
- envId,
93
- path: servicePath,
94
- name: functionName
95
- })
96
-
97
- // 查询访问域名
98
- const res = await queryGatewayDomain({ envId })
99
- const link = genClickableLink(`https://${res.DefaultDomain}${servicePath}`)
100
- loading.succeed(`HTTP 访问服务创建成功!\n点击访问> ${link}`)
101
- } catch (e) {
102
- loading.stop()
103
- if (e.code === 'InvalidParameter.APICreated') {
104
- throw new CloudBaseError('路径已存在!')
105
- }
106
- throw e
107
- }
108
- }
109
- }
@@ -1,81 +0,0 @@
1
- import { prompt } from 'enquirer'
2
- import { Command, ICommand } from '../common'
3
- import { loadingFactory } from '../../utils'
4
- import { InjectParams, EnvId, ArgsOptions } from '../../decorators'
5
- import { deleteGateway, queryGateway } from '../../gateway'
6
-
7
- @ICommand()
8
- export class DeleteServiceCommand extends Command {
9
- get options() {
10
- return {
11
- cmd: 'service',
12
- childCmd: 'delete',
13
- deprecateCmd: 'service:delete',
14
- options: [
15
- {
16
- flags: '-e, --envId <envId>',
17
- desc: '环境 Id'
18
- },
19
- {
20
- flags: '-p, --service-path <servicePath>',
21
- desc: 'HTTP 访问服务路径,删除此路径对应的 HTTP 访问服务'
22
- },
23
- {
24
- flags: '-i, --service-id <serviceId>',
25
- desc: 'HTTP 访问服务 Id,删除此 Id 对应的 HTTP 访问服务'
26
- },
27
- {
28
- flags: '-n, --name <name>',
29
- desc: '云函数函数名称,删除此函数绑定的所有 HTTP 访问服务'
30
- }
31
- ],
32
- desc: '删除 HTTP 访问服务'
33
- }
34
- }
35
-
36
- @InjectParams()
37
- async execute(@EnvId() envId, @ArgsOptions() options) {
38
- let { servicePath, serviceId, name } = options
39
-
40
- // 当没有指定要删除的服务时,获取所有服务列表,并提示
41
- if (!servicePath && !serviceId && (!name || typeof name !== 'string')) {
42
- const { APISet: allServices } = await queryGateway({
43
- envId
44
- })
45
-
46
- const { selected } = await prompt<any>({
47
- type: 'select',
48
- name: 'selected',
49
- message: '请选择需要删除的 Service',
50
- choices: allServices.map((item) => ({
51
- name: `函数名:${item.Name}/路径:${item.Path}`,
52
- value: item.APIId
53
- })),
54
- result(choices) {
55
- return Object.values(this.map(choices)) as any
56
- }
57
- })
58
- serviceId = selected?.[0]
59
- }
60
-
61
- if (servicePath) {
62
- servicePath = servicePath[0] === '/' ? servicePath : `/${servicePath}`
63
- }
64
-
65
- const loading = loadingFactory()
66
- loading.start('HTTP 访问服务删除中...')
67
-
68
- try {
69
- await deleteGateway({
70
- envId,
71
- name,
72
- path: servicePath,
73
- gatewayId: serviceId
74
- })
75
- loading.succeed('HTTP 访问服务删除成功!')
76
- } catch (e) {
77
- loading.stop()
78
- throw e
79
- }
80
- }
81
- }
@@ -1,159 +0,0 @@
1
- import { Command, ICommand } from '../common'
2
- import { CloudBaseError } from '../../error'
3
- import { loadingFactory, printHorizontalTable, formatDate } from '../../utils'
4
- import { InjectParams, EnvId, ArgsParams, ArgsOptions, Log, Logger } from '../../decorators'
5
- import { bindGatewayDomain, queryGatewayDomain, unbindGatewayDomain } from '../../gateway'
6
-
7
- const SERVICE_STATUS_MAP = {
8
- 1: '部署中',
9
- 2: '部署失败',
10
- 3: '部署成功',
11
- 4: '删除中',
12
- 5: '删除失败'
13
- }
14
-
15
- // 暂时无法支持
16
- export class BindCustomDomainCommand extends Command {
17
- get options() {
18
- return {
19
- cmd: 'service',
20
- childCmd: { cmd: 'domain', desc: 'HTTP 访问服务域名管理' },
21
- childSubCmd: 'bind <domain>',
22
- deprecateCmd: 'service:domain:bind <domain>',
23
- options: [
24
- {
25
- flags: '-e, --envId <envId>',
26
- desc: '环境 Id'
27
- }
28
- ],
29
- desc: '绑定自定义HTTP 访问服务域名'
30
- }
31
- }
32
-
33
- @InjectParams()
34
- async execute(@EnvId() envId, @ArgsParams() params) {
35
- const domain = params?.[0]
36
-
37
- console.log(domain)
38
-
39
- if (!domain) {
40
- throw new CloudBaseError('请指定需要绑定的HTTP 访问服务域名!')
41
- }
42
-
43
- const loading = loadingFactory()
44
- loading.start(`HTTP 访问服务域名 [${domain}] 绑定中...`)
45
-
46
- try {
47
- await bindGatewayDomain({
48
- envId,
49
- domain
50
- })
51
- loading.succeed(`HTTP 访问服务域名[${domain}] 绑定成功!`)
52
- } catch (e) {
53
- loading.stop()
54
- throw e
55
- }
56
- }
57
- }
58
-
59
- @ICommand()
60
- export class GetCustomDomainsCommand extends Command {
61
- get options() {
62
- return {
63
- cmd: 'service',
64
- childCmd: 'domain',
65
- childSubCmd: 'list',
66
- deprecateCmd: 'service:domain:list',
67
- options: [
68
- {
69
- flags: '-e, --envId <envId>',
70
- desc: '环境 Id'
71
- },
72
- {
73
- flags: '-d, --domain <domain>',
74
- desc: '域名'
75
- }
76
- ],
77
- desc: '查询 HTTP 访问服务自定义域名'
78
- }
79
- }
80
-
81
- @InjectParams()
82
- async execute(@EnvId() envId, @ArgsOptions() options, @Log() log: Logger) {
83
- const { domain: domainName } = options
84
-
85
- if (!envId && !domainName) {
86
- throw new CloudBaseError('请指定需要查询的环境 ID 或HTTP 访问服务域名!')
87
- }
88
-
89
- const loading = loadingFactory()
90
- loading.start('查询HTTP 访问服务域名中...')
91
-
92
- try {
93
- const res = await queryGatewayDomain({
94
- envId,
95
- domain: domainName
96
- })
97
-
98
- loading.succeed('查询HTTP 访问服务域名成功!')
99
-
100
- if (!res?.ServiceSet?.length) {
101
- log.info('HTTP 访问服务域名为空!')
102
- return
103
- }
104
-
105
- const head = ['域名', '状态', '创建时间']
106
- const tableData = res.ServiceSet.map((item) => [
107
- item.Domain,
108
- SERVICE_STATUS_MAP[item.Status],
109
- formatDate(item.OpenTime * 1000, 'yyyy-MM-dd hh:mm:ss')
110
- ])
111
- printHorizontalTable(head, tableData)
112
- } catch (e) {
113
- loading.stop()
114
- throw e
115
- }
116
- }
117
- }
118
-
119
- @ICommand()
120
- export class UnbindCustomDomainCommand extends Command {
121
- get options() {
122
- return {
123
- cmd: 'service',
124
- childCmd: 'domain',
125
- childSubCmd: 'unbind <domain>',
126
- deprecateCmd: 'service:domain:unbind <domain>',
127
- options: [
128
- {
129
- flags: '-e, --envId <envId>',
130
- desc: '环境 Id'
131
- }
132
- ],
133
- desc: '解绑自定义HTTP 访问服务域名'
134
- }
135
- }
136
-
137
- @InjectParams()
138
- async execute(@EnvId() envId, @ArgsParams() params) {
139
- const domain = params?.[0]
140
-
141
- if (!domain) {
142
- throw new CloudBaseError('请指定需要解绑的HTTP 访问服务域名!')
143
- }
144
-
145
- const loading = loadingFactory()
146
- loading.start(`HTTP Service域名 [${domain}] 解绑中...`)
147
-
148
- try {
149
- await unbindGatewayDomain({
150
- envId,
151
- domain
152
- })
153
- loading.succeed(`HTTP Service域名 [${domain}] 解绑成功!`)
154
- } catch (e) {
155
- loading.stop()
156
- throw e
157
- }
158
- }
159
- }
@@ -1,5 +0,0 @@
1
- export * from './create'
2
- export * from './delete'
3
- export * from './domain'
4
- export * from './list'
5
- export * from './switch'