@cloudbase/cli 2.0.12 → 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 (227) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/lib/run/service/deployPackage.js +2 -9
  3. package/lib/utils/debug-logger.js +30 -0
  4. package/lib/utils/net/cloud-api-request.js +7 -1
  5. package/lib/utils/net/http-request.js +16 -5
  6. package/package.json +1 -1
  7. package/types/utils/debug-logger.d.ts +1 -0
  8. package/types/utils/net/http-request.d.ts +6 -2
  9. package/src/auth/index.ts +0 -2
  10. package/src/auth/login.ts +0 -91
  11. package/src/auth/logout.ts +0 -7
  12. package/src/commands/account/index.ts +0 -2
  13. package/src/commands/account/login.ts +0 -192
  14. package/src/commands/account/logout.ts +0 -24
  15. package/src/commands/common.ts +0 -246
  16. package/src/commands/env/base.ts +0 -90
  17. package/src/commands/env/create.ts +0 -92
  18. package/src/commands/env/domain.ts +0 -186
  19. package/src/commands/env/index.ts +0 -4
  20. package/src/commands/env/login.ts +0 -235
  21. package/src/commands/framework/index.ts +0 -124
  22. package/src/commands/functions/alias/getRoute.ts +0 -76
  23. package/src/commands/functions/alias/index.ts +0 -2
  24. package/src/commands/functions/alias/setRoute.ts +0 -82
  25. package/src/commands/functions/code-download.ts +0 -100
  26. package/src/commands/functions/code-update.ts +0 -62
  27. package/src/commands/functions/concurrency/delete.ts +0 -45
  28. package/src/commands/functions/concurrency/index.ts +0 -3
  29. package/src/commands/functions/concurrency/list.ts +0 -58
  30. package/src/commands/functions/concurrency/set.ts +0 -47
  31. package/src/commands/functions/config-update.ts +0 -76
  32. package/src/commands/functions/copy.ts +0 -62
  33. package/src/commands/functions/delete.ts +0 -79
  34. package/src/commands/functions/deploy.ts +0 -293
  35. package/src/commands/functions/detail.ts +0 -138
  36. package/src/commands/functions/index.ts +0 -16
  37. package/src/commands/functions/invoke.ts +0 -121
  38. package/src/commands/functions/layer/bind.ts +0 -182
  39. package/src/commands/functions/layer/common.ts +0 -8
  40. package/src/commands/functions/layer/create.ts +0 -49
  41. package/src/commands/functions/layer/delete.ts +0 -73
  42. package/src/commands/functions/layer/download.ts +0 -92
  43. package/src/commands/functions/layer/index.ts +0 -7
  44. package/src/commands/functions/layer/list.ts +0 -94
  45. package/src/commands/functions/layer/sort.ts +0 -76
  46. package/src/commands/functions/list.ts +0 -68
  47. package/src/commands/functions/log.ts +0 -148
  48. package/src/commands/functions/run.ts +0 -249
  49. package/src/commands/functions/trigger-create.ts +0 -79
  50. package/src/commands/functions/trigger-delete.ts +0 -105
  51. package/src/commands/functions/version/index.ts +0 -2
  52. package/src/commands/functions/version/list.ts +0 -73
  53. package/src/commands/functions/version/publish.ts +0 -43
  54. package/src/commands/gateway/create.ts +0 -109
  55. package/src/commands/gateway/delete.ts +0 -81
  56. package/src/commands/gateway/domain.ts +0 -159
  57. package/src/commands/gateway/index.ts +0 -5
  58. package/src/commands/gateway/list.ts +0 -76
  59. package/src/commands/gateway/switch.ts +0 -107
  60. package/src/commands/helpers/index.ts +0 -3
  61. package/src/commands/helpers/init.ts +0 -431
  62. package/src/commands/helpers/new.ts +0 -117
  63. package/src/commands/helpers/open.ts +0 -67
  64. package/src/commands/hosting/hosting.ts +0 -360
  65. package/src/commands/hosting/index.ts +0 -1
  66. package/src/commands/index.ts +0 -13
  67. package/src/commands/lowcode/app.ts +0 -34
  68. package/src/commands/lowcode/comps.ts +0 -325
  69. package/src/commands/lowcode/index.ts +0 -2
  70. package/src/commands/lowcode/utils.ts +0 -25
  71. package/src/commands/run/create.ts +0 -153
  72. package/src/commands/run/delete.ts +0 -77
  73. package/src/commands/run/image/common.ts +0 -8
  74. package/src/commands/run/image/delete.ts +0 -68
  75. package/src/commands/run/image/download.ts +0 -68
  76. package/src/commands/run/image/index.ts +0 -5
  77. package/src/commands/run/image/list.ts +0 -84
  78. package/src/commands/run/image/upload.ts +0 -76
  79. package/src/commands/run/index.ts +0 -7
  80. package/src/commands/run/list.ts +0 -83
  81. package/src/commands/run/service/config.ts +0 -81
  82. package/src/commands/run/service/create.ts +0 -122
  83. package/src/commands/run/service/deploy.ts +0 -125
  84. package/src/commands/run/service/index.ts +0 -5
  85. package/src/commands/run/service/list.ts +0 -94
  86. package/src/commands/run/service/update.ts +0 -108
  87. package/src/commands/run/standalonegateway/common.ts +0 -8
  88. package/src/commands/run/standalonegateway/create.ts +0 -85
  89. package/src/commands/run/standalonegateway/destroy.ts +0 -59
  90. package/src/commands/run/standalonegateway/index.ts +0 -5
  91. package/src/commands/run/standalonegateway/list.ts +0 -53
  92. package/src/commands/run/standalonegateway/package.ts +0 -62
  93. package/src/commands/run/standalonegateway/turn.ts +0 -63
  94. package/src/commands/run/version/common.ts +0 -8
  95. package/src/commands/run/version/create.ts +0 -369
  96. package/src/commands/run/version/delete.ts +0 -64
  97. package/src/commands/run/version/index.ts +0 -5
  98. package/src/commands/run/version/list.ts +0 -91
  99. package/src/commands/run/version/modify.ts +0 -137
  100. package/src/commands/run/version/update.ts +0 -398
  101. package/src/commands/smart.ts +0 -132
  102. package/src/commands/storage/index.ts +0 -1
  103. package/src/commands/storage/storage.ts +0 -464
  104. package/src/commands/third/index.ts +0 -1
  105. package/src/commands/third/thirdAttach.ts +0 -49
  106. package/src/completion/index.ts +0 -13
  107. package/src/constant.ts +0 -154
  108. package/src/decorators/captureError.ts +0 -25
  109. package/src/decorators/constants.ts +0 -12
  110. package/src/decorators/deprecate.ts +0 -25
  111. package/src/decorators/guard.ts +0 -42
  112. package/src/decorators/index.ts +0 -7
  113. package/src/decorators/injectParams.ts +0 -54
  114. package/src/decorators/params/common.ts +0 -28
  115. package/src/decorators/params/index.ts +0 -35
  116. package/src/env/domain.ts +0 -33
  117. package/src/env/index.ts +0 -63
  118. package/src/env/login.ts +0 -80
  119. package/src/error.ts +0 -36
  120. package/src/function/alias.ts +0 -43
  121. package/src/function/base.ts +0 -253
  122. package/src/function/code.ts +0 -55
  123. package/src/function/concurrency.ts +0 -57
  124. package/src/function/create.ts +0 -78
  125. package/src/function/delete.ts +0 -42
  126. package/src/function/index.ts +0 -11
  127. package/src/function/layer/attach.ts +0 -68
  128. package/src/function/layer/create.ts +0 -63
  129. package/src/function/layer/delete.ts +0 -21
  130. package/src/function/layer/download.ts +0 -54
  131. package/src/function/layer/index.ts +0 -7
  132. package/src/function/layer/list.ts +0 -32
  133. package/src/function/layer/sort.ts +0 -24
  134. package/src/function/trigger.ts +0 -97
  135. package/src/function/update.ts +0 -35
  136. package/src/function/version.ts +0 -39
  137. package/src/function/vpc.ts +0 -22
  138. package/src/gateway/index.ts +0 -137
  139. package/src/help.ts +0 -50
  140. package/src/hosting.ts +0 -212
  141. package/src/index.ts +0 -13
  142. package/src/logger.ts +0 -17
  143. package/src/run/create.ts +0 -23
  144. package/src/run/delete.ts +0 -15
  145. package/src/run/image/build.ts +0 -36
  146. package/src/run/image/delete.ts +0 -14
  147. package/src/run/image/index.ts +0 -4
  148. package/src/run/image/info.ts +0 -27
  149. package/src/run/image/list.ts +0 -23
  150. package/src/run/index.ts +0 -8
  151. package/src/run/list.ts +0 -30
  152. package/src/run/repo.ts +0 -25
  153. package/src/run/service/common.ts +0 -311
  154. package/src/run/service/config.ts +0 -77
  155. package/src/run/service/create.ts +0 -52
  156. package/src/run/service/deployPackage.ts +0 -65
  157. package/src/run/service/index.ts +0 -7
  158. package/src/run/service/list.ts +0 -29
  159. package/src/run/service/showLogs.ts +0 -98
  160. package/src/run/service/update.ts +0 -82
  161. package/src/run/standalonegateway/create.ts +0 -24
  162. package/src/run/standalonegateway/destroy.ts +0 -19
  163. package/src/run/standalonegateway/index.ts +0 -5
  164. package/src/run/standalonegateway/list.ts +0 -74
  165. package/src/run/standalonegateway/package/index.ts +0 -1
  166. package/src/run/standalonegateway/package/list.ts +0 -24
  167. package/src/run/standalonegateway/turn/index.ts +0 -2
  168. package/src/run/standalonegateway/turn/off.ts +0 -19
  169. package/src/run/standalonegateway/turn/on.ts +0 -19
  170. package/src/run/version/create.ts +0 -68
  171. package/src/run/version/delete.ts +0 -16
  172. package/src/run/version/index.ts +0 -6
  173. package/src/run/version/list.ts +0 -17
  174. package/src/run/version/modify.ts +0 -17
  175. package/src/run/version/repo.ts +0 -28
  176. package/src/run/version/update.ts +0 -59
  177. package/src/storage.ts +0 -114
  178. package/src/third/index.ts +0 -13
  179. package/src/types.ts +0 -672
  180. package/src/utils/auth.ts +0 -15
  181. package/src/utils/checkTcbrEnv.ts +0 -69
  182. package/src/utils/cli-table.ts +0 -23
  183. package/src/utils/commonParamsCheck.ts +0 -65
  184. package/src/utils/config.ts +0 -39
  185. package/src/utils/env.ts +0 -244
  186. package/src/utils/fs/del.ts +0 -5
  187. package/src/utils/fs/index.ts +0 -71
  188. package/src/utils/function-packer.ts +0 -97
  189. package/src/utils/index.ts +0 -25
  190. package/src/utils/log.ts +0 -82
  191. package/src/utils/net/cloud-api-request.ts +0 -62
  192. package/src/utils/net/credential.ts +0 -53
  193. package/src/utils/net/http-request.ts +0 -84
  194. package/src/utils/net/index.ts +0 -5
  195. package/src/utils/net/manager-service.ts +0 -36
  196. package/src/utils/net/proxy.ts +0 -6
  197. package/src/utils/notice.ts +0 -28
  198. package/src/utils/output/highlight.ts +0 -5
  199. package/src/utils/output/index.ts +0 -3
  200. package/src/utils/output/link.ts +0 -10
  201. package/src/utils/output/loading.ts +0 -82
  202. package/src/utils/parallel.ts +0 -82
  203. package/src/utils/platform/index.ts +0 -3
  204. package/src/utils/platform/mac.ts +0 -21
  205. package/src/utils/platform/os.ts +0 -64
  206. package/src/utils/platform/port.ts +0 -10
  207. package/src/utils/progress-bar.ts +0 -38
  208. package/src/utils/prompt/index.ts +0 -1
  209. package/src/utils/prompt/select.ts +0 -60
  210. package/src/utils/reporter/agree.ts +0 -20
  211. package/src/utils/reporter/download.ts +0 -26
  212. package/src/utils/reporter/index.ts +0 -3
  213. package/src/utils/reporter/usage.ts +0 -20
  214. package/src/utils/store/auth.ts +0 -49
  215. package/src/utils/store/common.ts +0 -8
  216. package/src/utils/store/db.ts +0 -68
  217. package/src/utils/store/index.ts +0 -5
  218. package/src/utils/store/usage.ts +0 -12
  219. package/src/utils/tcbrApi/callTcbrApi.ts +0 -28
  220. package/src/utils/tcbrApi/index.ts +0 -1
  221. package/src/utils/template.ts +0 -170
  222. package/src/utils/tools/encoding.ts +0 -8
  223. package/src/utils/tools/index.ts +0 -4
  224. package/src/utils/tools/object.ts +0 -33
  225. package/src/utils/tools/time.ts +0 -38
  226. package/src/utils/tools/uid.ts +0 -19
  227. package/src/utils/validator.ts +0 -65
@@ -1,138 +0,0 @@
1
- import chalk from 'chalk'
2
- import { Command, ICommand } from '../common'
3
- import { CloudBaseError } from '../../error'
4
- import { getFunctionDetail } from '../../function'
5
- import { loadingFactory, printHorizontalTable } from '../../utils'
6
- import { InjectParams, ArgsParams, CmdContext, Log, Logger } from '../../decorators'
7
-
8
- const StatusMap = {
9
- Active: '部署完成',
10
- Creating: '创建中',
11
- CreateFailed: '创建失败',
12
- Updating: '更新中',
13
- UpdateFailed: '更新失败'
14
- }
15
-
16
- @ICommand()
17
- export class FunctionDetail extends Command {
18
- get options() {
19
- return {
20
- cmd: 'fn',
21
- childCmd: 'detail <name>',
22
- deprecateCmd: 'functions:detail <name>',
23
- options: [
24
- {
25
- flags: '-e, --envId <envId>',
26
- desc: '环境 Id'
27
- },
28
- {
29
- flags: '--code-secret <codeSecret>',
30
- desc: '代码加密的函数的 CodeSecret'
31
- }
32
- ],
33
- desc: '获取云函数信息'
34
- }
35
- }
36
-
37
- @InjectParams()
38
- async execute(@CmdContext() ctx, @ArgsParams() params) {
39
- const { envId, options } = ctx
40
- const { codeSecret } = options
41
- const name = params?.[0]
42
-
43
- if (!name) {
44
- throw new CloudBaseError('请指定云函数名称!')
45
- }
46
-
47
- const loading = loadingFactory()
48
- loading.start('获取函数信息中...')
49
-
50
- try {
51
- const data = await getFunctionDetail({
52
- envId,
53
- functionName: name,
54
- codeSecret
55
- })
56
-
57
- loading.stop()
58
- this.logDetail(data, name)
59
- } catch (e) {
60
- if (e.code === 'ResourceNotFound.FunctionName') {
61
- throw new CloudBaseError(`[${name}] 函数不存在`)
62
- }
63
- throw e
64
- } finally {
65
- loading.stop()
66
- }
67
- }
68
-
69
- @InjectParams()
70
- logDetail(info, name, @Log() log?: Logger) {
71
- const ResMap = {
72
- Namespace: '环境 Id',
73
- FunctionName: '函数名称',
74
- Status: '状态',
75
- CodeSize: '代码大小(B)',
76
- Environment: '环境变量(key=value)',
77
- Handler: '执行方法',
78
- MemorySize: '内存配置(MB)',
79
- Runtime: '运行环境',
80
- Timeout: '超时时间(S)',
81
- VpcConfig: '网络配置',
82
- Triggers: '触发器',
83
- ModTime: '修改时间',
84
- InstallDependency: '自动安装依赖'
85
- }
86
-
87
- const head = ['信息', '值']
88
-
89
- const tableData = Object.keys(ResMap).map((key) => {
90
- if (key === 'Status') {
91
- return [ResMap[key], StatusMap[info[key]]]
92
- }
93
- // 将环境变量数组转换成 key=value 的形式
94
- if (key === 'Environment') {
95
- const data =
96
- info[key].Variables.map((item) => `${item.Key}=${item.Value}`).join('; ') ||
97
- '无'
98
- return [ResMap[key], data]
99
- }
100
-
101
- if (key === 'Triggers') {
102
- let data = info[key]
103
- .map((item) => `${item.TriggerName}:${item.TriggerDesc}`)
104
- .join('\n')
105
- data = data.length ? `${data}\n` : '无'
106
- return [ResMap[key], data]
107
- }
108
-
109
- if (key === 'VpcConfig') {
110
- const { vpc, subnet }: any = info[key]
111
- if (typeof vpc === 'string') {
112
- return [ResMap[key], `${vpc}/${subnet}`]
113
- } else if (vpc && subnet) {
114
- const data = `${vpc.VpcId}(${vpc.VpcName} | ${subnet.CidrBlock}) / ${subnet.SubnetId}(${subnet.SubnetName})`
115
-
116
- return [ResMap[key], data]
117
- } else {
118
- return [ResMap[key], '无']
119
- }
120
- }
121
-
122
- if (key === 'CodeInfo') {
123
- return [ResMap[key], info[key]]
124
- }
125
-
126
- return [ResMap[key], info[key]]
127
- })
128
-
129
- if (info.StatusDesc) {
130
- tableData.push(['状态描述', info.StatusDesc])
131
- }
132
-
133
- log.info(chalk.green(`云函数 [${name}] 详情:`))
134
- printHorizontalTable(head, tableData)
135
- log.info('函数代码(Java 函数以及入口大于 1 M 的函数不会显示)\n')
136
- log.log(info['CodeInfo'])
137
- }
138
- }
@@ -1,16 +0,0 @@
1
- export * from './deploy'
2
- export * from './list'
3
- export * from './delete'
4
- export * from './config-update'
5
- export * from './invoke'
6
- export * from './log'
7
- export * from './detail'
8
- export * from './copy'
9
- export * from './run'
10
- export * from './trigger-create'
11
- export * from './trigger-delete'
12
- export * from './code-update'
13
- export * from './code-download'
14
- export * from './version'
15
- export * from './concurrency'
16
- export * from './alias'
@@ -1,121 +0,0 @@
1
- import chalk from 'chalk'
2
- import inquirer from 'inquirer'
3
- import { Command, ICommand } from '../common'
4
- import { CloudBaseError } from '../../error'
5
- import { batchInvokeFunctions, invokeFunction } from '../../function'
6
- import { InjectParams, CmdContext, ArgsParams, Log, Logger } from '../../decorators'
7
-
8
- @ICommand()
9
- export class InvokeFunction extends Command {
10
- get options() {
11
- return {
12
- cmd: 'fn',
13
- childCmd: 'invoke [name]',
14
- deprecateCmd: 'functions:invoke [name]',
15
- options: [
16
- {
17
- flags: '-e, --envId <envId>',
18
- desc: '环境 Id'
19
- },
20
- {
21
- flags: '--params <params>',
22
- desc: '调用函数的入参,JSON 字符串形式'
23
- }
24
- ],
25
- desc: '触发云端部署的云函数'
26
- }
27
- }
28
-
29
- @InjectParams()
30
- async execute(@CmdContext() ctx, @ArgsParams() argsParams, @Log() log: Logger) {
31
- const {
32
- envId,
33
- config: { functions },
34
- options
35
- } = ctx
36
- const name = argsParams?.[0]
37
- let isBatchInvoke = false
38
-
39
- // 不指定云函数名称,触发配置文件中的所有函数
40
- if (!name) {
41
- const { isBatch } = await inquirer.prompt({
42
- type: 'confirm',
43
- name: 'isBatch',
44
- message: '无云函数名称,是否需要触发配置文件中的全部云函数?',
45
- default: false
46
- })
47
-
48
- isBatchInvoke = isBatch
49
-
50
- if (!isBatchInvoke) {
51
- throw new CloudBaseError('请指定云函数名称!')
52
- }
53
- }
54
-
55
- let params
56
- const jsonStringParams = options.params
57
- if (jsonStringParams) {
58
- try {
59
- params = JSON.parse(jsonStringParams)
60
- } catch (e) {
61
- console.log(e)
62
- throw new CloudBaseError('jsonStringParams 参数不是正确的 JSON 字符串')
63
- }
64
- }
65
-
66
- if (isBatchInvoke) {
67
- return batchInvokeFunctions({
68
- envId,
69
- functions,
70
- log: true
71
- })
72
- }
73
-
74
- const func = functions.find((item) => item.name === name)
75
-
76
- const configParams = func?.params ? func.params : undefined
77
-
78
- const result = await invokeFunction({
79
- envId,
80
- functionName: name,
81
- params: params || configParams
82
- })
83
-
84
- if (result.InvokeResult === 0) {
85
- log.success(`[${name}] 调用成功\n`)
86
- } else {
87
- log.error(`[${name}] 调用失败\n`)
88
- }
89
-
90
- const ResMap = {
91
- Duration: '运行时间',
92
- MemUsage: '内存占用',
93
- BillDuration: '计费时间',
94
- FunctionRequestId: '请求 Id ',
95
- RetMsg: '返回结果',
96
- ErrMsg: '错误信息',
97
- Log: '调用日志'
98
- }
99
-
100
- const formatInfo = {
101
- ...result,
102
- Duration: Number(result.Duration).toFixed(2) + 'ms',
103
- MemUsage: Number(Number(result.MemUsage) / Math.pow(1024, 2)).toFixed(2) + 'MB',
104
- BillDuration: result.BillDuration + 'ms'
105
- }
106
-
107
- const logInfo = Object.keys(ResMap)
108
- .map((key) => {
109
- if (key === 'Log') {
110
- return `${chalk.bold.cyan(ResMap[key])}:\n${formatInfo[key]}`
111
- } else if (result.InvokeResult === 0 && key === 'ErrMsg') {
112
- return false
113
- } else {
114
- return `${chalk.bold.cyan(ResMap[key])}:${formatInfo[key]}`
115
- }
116
- })
117
- .filter((item) => item)
118
- .join('\n')
119
- console.log(logInfo)
120
- }
121
- }
@@ -1,182 +0,0 @@
1
- import { prompt } from 'enquirer'
2
- import {
3
- listLayers,
4
- listLayerVersions,
5
- attachLayer,
6
- getFunctionDetail,
7
- unAttachLayer,
8
- listFunction
9
- } from '../../../function'
10
- import { Command, ICommand } from '../../common'
11
- import { loadingFactory } from '../../../utils'
12
- import { CloudBaseError } from '../../../error'
13
- import { InjectParams, EnvId, ArgsOptions, ArgsParams } from '../../../decorators'
14
- import { layerCommonOptions } from './common'
15
-
16
- const LayerStatusMap = {
17
- Active: '正常',
18
- Publishing: '发布中',
19
- PublishFailed: '发布失败',
20
- Deleted: '已删除'
21
- }
22
-
23
- @ICommand()
24
- export class AttachFileLayer extends Command {
25
- get options() {
26
- return {
27
- ...layerCommonOptions('bind <name>'),
28
- deprecateCmd: 'functions:layer:bind <name>',
29
- options: [
30
- {
31
- flags: '-e, --envId <envId>',
32
- desc: '环境 Id'
33
- },
34
- {
35
- flags: '--code-secret, <codeSecret>',
36
- desc: '代码加密的函数的 CodeSecret'
37
- }
38
- ],
39
- desc: '绑定文件层到云函数'
40
- }
41
- }
42
-
43
- @InjectParams()
44
- async execute(@EnvId() envId, @ArgsParams() params, @ArgsOptions() options) {
45
- const { codeSecret } = options
46
- const fnName = params?.[0]
47
-
48
- const loading = loadingFactory()
49
- loading.start('数据加载中...')
50
-
51
- // 检查函数是否存在当前环境中
52
- const envFunctions = await listFunction({
53
- envId
54
- })
55
- const exist = envFunctions.find((fn) => fn.FunctionName === fnName)
56
- if (!exist) {
57
- throw new CloudBaseError(`当前环境不存在此函数 [${fnName}]`)
58
- }
59
-
60
- let layers: any[] = await listLayers({
61
- offset: 0,
62
- limit: 200
63
- })
64
-
65
- loading.stop()
66
-
67
- layers = layers.map((item) => ({
68
- name: `[${LayerStatusMap[item.Status] || '异常'}] ${item.LayerName}`,
69
- value: item.LayerName
70
- }))
71
-
72
- if (!layers.length) {
73
- throw new CloudBaseError('没有可用的文件层,请先创建文件层!')
74
- }
75
-
76
- const { layer } = await prompt<any>({
77
- type: 'select',
78
- name: 'layer',
79
- message: '选择文件层名称',
80
- choices: layers,
81
- result(choices) {
82
- const keys = Object.values(this.map(choices)) as string[]
83
- return keys[0]
84
- }
85
- })
86
-
87
- let versions = await listLayerVersions({
88
- name: layer
89
- })
90
-
91
- versions = versions.map((item) => String(item.LayerVersion))
92
-
93
- if (!versions.length) {
94
- throw new CloudBaseError('没有可用的文件层版本,请先创建文件层版本!')
95
- }
96
-
97
- const { version } = await prompt<any>({
98
- type: 'select',
99
- name: 'version',
100
- message: '选择文件层版本',
101
- choices: versions
102
- })
103
-
104
- loading.start('文件层绑定中...')
105
- await attachLayer({
106
- envId,
107
- functionName: fnName,
108
- layerName: layer,
109
- layerVersion: Number(version),
110
- codeSecret
111
- })
112
-
113
- loading.succeed('文件层绑定成功!')
114
- }
115
- }
116
-
117
- @ICommand()
118
- export class UnAttachFileLayer extends Command {
119
- get options() {
120
- return {
121
- ...layerCommonOptions('unbind <name>'),
122
- deprecateCmd: 'functions:layer:unbind <name>',
123
- options: [
124
- {
125
- flags: '-e, --envId <envId>',
126
- desc: '环境 Id'
127
- },
128
- {
129
- flags: '--code-secret, <codeSecret>',
130
- desc: '代码加密的函数的 CodeSecret'
131
- }
132
- ],
133
- desc: '删除云函数绑定的文件层'
134
- }
135
- }
136
-
137
- @InjectParams()
138
- async execute(@EnvId() envId, @ArgsParams() params, @ArgsOptions() options) {
139
- const { codeSecret } = options
140
- const fnName = params?.[0]
141
-
142
- const loading = loadingFactory()
143
- loading.start('数据加载中...')
144
-
145
- const detail = await getFunctionDetail({
146
- envId,
147
- codeSecret,
148
- functionName: fnName
149
- })
150
-
151
- if (!detail?.Layers?.length) {
152
- throw new CloudBaseError('该云函数未绑定文件层!')
153
- }
154
-
155
- loading.stop()
156
-
157
- const layers = detail.Layers.map((item) => ({
158
- name: `名称:${item.LayerName} / 版本: ${item.LayerVersion}`,
159
- value: item
160
- }))
161
-
162
- const { layer } = await prompt<any>({
163
- type: 'select',
164
- name: 'layer',
165
- message: '选择文件层',
166
- choices: layers,
167
- result(choice) {
168
- return this.map(choice)[choice]
169
- }
170
- })
171
-
172
- loading.start('文件层解绑中...')
173
- await unAttachLayer({
174
- envId,
175
- functionName: fnName,
176
- layerName: layer.LayerName,
177
- layerVersion: layer.LayerVersion,
178
- codeSecret
179
- })
180
- loading.succeed('文件层解绑成功!')
181
- }
182
- }
@@ -1,8 +0,0 @@
1
- export const layerCommonOptions = (sub: string) => ({
2
- cmd: 'fn',
3
- childCmd: {
4
- cmd: 'layer',
5
- desc: '云函数层管理'
6
- },
7
- childSubCmd: sub
8
- })
@@ -1,49 +0,0 @@
1
- import path from 'path'
2
- import { Command, ICommand } from '../../common'
3
- import { createLayer } from '../../../function'
4
- import { loadingFactory } from '../../../utils'
5
- import { InjectParams, EnvId, ArgsOptions, ArgsParams } from '../../../decorators'
6
- import { layerCommonOptions } from './common'
7
-
8
- @ICommand()
9
- export class CreateFileLayer extends Command {
10
- get options() {
11
- return {
12
- ...layerCommonOptions('create <alias>'),
13
- deprecateCmd: 'functions:layer:create <alias>',
14
- options: [
15
- {
16
- flags: '-e, --envId <envId>',
17
- desc: '环境 Id'
18
- },
19
- {
20
- flags: '--file, <file>',
21
- desc: '文件路径'
22
- }
23
- ],
24
- desc: '创建函数文件层'
25
- }
26
- }
27
-
28
- @InjectParams()
29
- async execute(@EnvId() envId, @ArgsOptions() options, @ArgsParams() params) {
30
- const alias = params?.[0]
31
- const { file } = options
32
-
33
- const layerName = `${alias}_${envId}`
34
- const filePath = path.resolve(file)
35
- const runtimes = ['Nodejs8.9', 'Php7', 'Java8']
36
-
37
- const loading = loadingFactory()
38
-
39
- loading.start('文件层创建中...')
40
-
41
- await createLayer({
42
- layerName,
43
- runtimes,
44
- contentPath: filePath
45
- })
46
-
47
- loading.succeed('文件层创建成功!')
48
- }
49
- }
@@ -1,73 +0,0 @@
1
- import { prompt } from 'enquirer'
2
- import { Command, ICommand } from '../../common'
3
- import { loadingFactory } from '../../../utils'
4
- import { CloudBaseError } from '../../../error'
5
- import { InjectParams, EnvId } from '../../../decorators'
6
- import { deleteLayer, listLayers, listLayerVersions } from '../../../function'
7
- import { layerCommonOptions } from './common'
8
-
9
- @ICommand()
10
- export class DeleteFileLayer extends Command {
11
- get options() {
12
- return {
13
- ...layerCommonOptions('delete'),
14
- deprecateCmd: 'functions:layer:delete',
15
- options: [
16
- {
17
- flags: '-e, --envId <envId>',
18
- desc: '环境 Id'
19
- }
20
- ],
21
- desc: '删除当前环境的文件层'
22
- }
23
- }
24
-
25
- @InjectParams()
26
- async execute(@EnvId() envId) {
27
- const loading = loadingFactory()
28
- loading.start('数据加载中...')
29
-
30
- let layers: any[] = await listLayers({
31
- offset: 0,
32
- limit: 200
33
- })
34
-
35
- loading.stop()
36
-
37
- // 只能删除当前环境的文件层
38
- layers = layers
39
- .filter((item) => item.LayerName.includes(`_${envId}`))
40
- .map((item) => item.LayerName)
41
-
42
- if (!layers.length) {
43
- throw new CloudBaseError('当前环境没有可用的文件层,请先创建文件层!')
44
- }
45
-
46
- const { layer } = await prompt<any>({
47
- type: 'select',
48
- name: 'layer',
49
- message: '选择文件层名称',
50
- choices: layers
51
- })
52
-
53
- let versions = await listLayerVersions({
54
- name: layer
55
- })
56
-
57
- versions = versions.map((item) => String(item.LayerVersion))
58
-
59
- const { version } = await prompt<any>({
60
- type: 'select',
61
- name: 'version',
62
- message: '选择文件层版本',
63
- choices: versions
64
- })
65
-
66
- loading.start('文件层删除中...')
67
- await deleteLayer({
68
- name: layer,
69
- version: Number(version)
70
- })
71
- loading.succeed('文件层删除成功!')
72
- }
73
- }
@@ -1,92 +0,0 @@
1
- import path from 'path'
2
- import fse from 'fs-extra'
3
- import { prompt } from 'enquirer'
4
- import { loadingFactory } from '../../../utils'
5
- import { CloudBaseError } from '../../../error'
6
- import { Command, ICommand } from '../../common'
7
- import { InjectParams, EnvId, ArgsOptions } from '../../../decorators'
8
- import { downloadLayer, listLayers, listLayerVersions } from '../../../function'
9
- import { layerCommonOptions } from './common'
10
-
11
- @ICommand()
12
- export class DownloadFileLayer extends Command {
13
- get options() {
14
- return {
15
- ...layerCommonOptions('download'),
16
- deprecateCmd: 'functions:layer:download',
17
- options: [
18
- {
19
- flags: '-e, --envId <envId>',
20
- desc: '环境 Id'
21
- },
22
- {
23
- flags: '--dest <dest>',
24
- desc: '下载文件存放的地址'
25
- }
26
- ],
27
- desc: '下载云函数文件层'
28
- }
29
- }
30
-
31
- @InjectParams()
32
- async execute(@EnvId() envId, @ArgsOptions() options) {
33
- const { dest } = options
34
-
35
- const loading = loadingFactory()
36
- loading.start('数据加载中...')
37
-
38
- let layers: any[] = await listLayers({
39
- offset: 0,
40
- limit: 200
41
- })
42
-
43
- loading.stop()
44
-
45
- // 只能下载当前环境的文件层
46
- layers = layers
47
- .filter((item) => item.LayerName.includes(`_${envId}`))
48
- .map((item) => item.LayerName)
49
-
50
- if (!layers.length) {
51
- throw new CloudBaseError('当前环境没有可用的文件层,请先创建文件层!')
52
- }
53
-
54
- const { layer } = await prompt<any>({
55
- type: 'select',
56
- name: 'layer',
57
- message: '选择文件层名称',
58
- choices: layers
59
- })
60
-
61
- let versions = await listLayerVersions({
62
- name: layer
63
- })
64
-
65
- versions = versions.map((item) => String(item.LayerVersion))
66
-
67
- const { version } = await prompt<any>({
68
- type: 'select',
69
- name: 'version',
70
- message: '选择文件层版本',
71
- choices: versions
72
- })
73
-
74
- let destPath
75
-
76
- if (!dest) {
77
- destPath = path.resolve(process.cwd(), 'layers')
78
- }
79
-
80
- loading.start('文件下载中...')
81
-
82
- await fse.ensureDir(destPath)
83
- await downloadLayer({
84
- destPath,
85
- version: Number(version),
86
- name: layer,
87
- unzip: true
88
- })
89
-
90
- loading.succeed('文件下载成功!')
91
- }
92
- }
@@ -1,7 +0,0 @@
1
- export * from './list'
2
- export * from './bind'
3
- export * from './delete'
4
- export * from './create'
5
- export * from './download'
6
- export * from './list'
7
- export * from './sort'