@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.
Files changed (252) 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/commands/run/service/create.js +4 -0
  7. package/lib/commands/run/service/deploy.js +4 -0
  8. package/lib/commands/run/service/update.js +4 -0
  9. package/lib/run/service/common.js +9 -3
  10. package/lib/run/service/deployPackage.js +2 -9
  11. package/lib/utils/checkTcbrEnv.js +5 -4
  12. package/lib/utils/debug-logger.js +30 -0
  13. package/lib/utils/net/cloud-api-request.js +7 -1
  14. package/lib/utils/net/http-request.js +16 -5
  15. package/package.json +5 -4
  16. package/types/commands/lowcode/app.d.ts +0 -10
  17. package/types/run/service/common.d.ts +4 -1
  18. package/types/types.d.ts +4 -0
  19. package/types/utils/debug-logger.d.ts +1 -0
  20. package/types/utils/net/http-request.d.ts +6 -2
  21. package/.history/.gitignore_20220624162613 +0 -84
  22. package/.history/.gitignore_20220627114054 +0 -86
  23. package/.history/package_20220711204706.json +0 -88
  24. package/.history/package_20220711204818.json +0 -88
  25. package/.history/package_20220712151717.json +0 -88
  26. package/.history/package_20220712212537.json +0 -88
  27. package/.history/package_20220722205058.json +0 -88
  28. package/.history/src/commands/lowcode/app_20220624162613.ts +0 -34
  29. package/.history/src/commands/lowcode/app_20220627114205.ts +0 -52
  30. package/.history/src/index_20220624162613.ts +0 -13
  31. package/.history/src/index_20220627113609.ts +0 -15
  32. package/.history/src/index_20220627114102.ts +0 -13
  33. package/src/auth/index.ts +0 -2
  34. package/src/auth/login.ts +0 -91
  35. package/src/auth/logout.ts +0 -7
  36. package/src/commands/account/index.ts +0 -2
  37. package/src/commands/account/login.ts +0 -192
  38. package/src/commands/account/logout.ts +0 -24
  39. package/src/commands/common.ts +0 -246
  40. package/src/commands/env/base.ts +0 -90
  41. package/src/commands/env/create.ts +0 -92
  42. package/src/commands/env/domain.ts +0 -186
  43. package/src/commands/env/index.ts +0 -4
  44. package/src/commands/env/login.ts +0 -235
  45. package/src/commands/framework/index.ts +0 -124
  46. package/src/commands/functions/alias/getRoute.ts +0 -76
  47. package/src/commands/functions/alias/index.ts +0 -2
  48. package/src/commands/functions/alias/setRoute.ts +0 -82
  49. package/src/commands/functions/code-download.ts +0 -100
  50. package/src/commands/functions/code-update.ts +0 -62
  51. package/src/commands/functions/concurrency/delete.ts +0 -45
  52. package/src/commands/functions/concurrency/index.ts +0 -3
  53. package/src/commands/functions/concurrency/list.ts +0 -58
  54. package/src/commands/functions/concurrency/set.ts +0 -47
  55. package/src/commands/functions/config-update.ts +0 -76
  56. package/src/commands/functions/copy.ts +0 -62
  57. package/src/commands/functions/delete.ts +0 -79
  58. package/src/commands/functions/deploy.ts +0 -293
  59. package/src/commands/functions/detail.ts +0 -138
  60. package/src/commands/functions/index.ts +0 -16
  61. package/src/commands/functions/invoke.ts +0 -121
  62. package/src/commands/functions/layer/bind.ts +0 -182
  63. package/src/commands/functions/layer/common.ts +0 -8
  64. package/src/commands/functions/layer/create.ts +0 -49
  65. package/src/commands/functions/layer/delete.ts +0 -73
  66. package/src/commands/functions/layer/download.ts +0 -92
  67. package/src/commands/functions/layer/index.ts +0 -7
  68. package/src/commands/functions/layer/list.ts +0 -94
  69. package/src/commands/functions/layer/sort.ts +0 -76
  70. package/src/commands/functions/list.ts +0 -68
  71. package/src/commands/functions/log.ts +0 -148
  72. package/src/commands/functions/run.ts +0 -249
  73. package/src/commands/functions/trigger-create.ts +0 -79
  74. package/src/commands/functions/trigger-delete.ts +0 -105
  75. package/src/commands/functions/version/index.ts +0 -2
  76. package/src/commands/functions/version/list.ts +0 -73
  77. package/src/commands/functions/version/publish.ts +0 -43
  78. package/src/commands/gateway/create.ts +0 -109
  79. package/src/commands/gateway/delete.ts +0 -81
  80. package/src/commands/gateway/domain.ts +0 -159
  81. package/src/commands/gateway/index.ts +0 -5
  82. package/src/commands/gateway/list.ts +0 -76
  83. package/src/commands/gateway/switch.ts +0 -107
  84. package/src/commands/helpers/index.ts +0 -3
  85. package/src/commands/helpers/init.ts +0 -431
  86. package/src/commands/helpers/new.ts +0 -117
  87. package/src/commands/helpers/open.ts +0 -67
  88. package/src/commands/hosting/hosting.ts +0 -360
  89. package/src/commands/hosting/index.ts +0 -1
  90. package/src/commands/index.ts +0 -13
  91. package/src/commands/lowcode/app.ts +0 -52
  92. package/src/commands/lowcode/comps.ts +0 -325
  93. package/src/commands/lowcode/index.ts +0 -2
  94. package/src/commands/lowcode/utils.ts +0 -25
  95. package/src/commands/run/create.ts +0 -153
  96. package/src/commands/run/delete.ts +0 -77
  97. package/src/commands/run/image/common.ts +0 -8
  98. package/src/commands/run/image/delete.ts +0 -68
  99. package/src/commands/run/image/download.ts +0 -68
  100. package/src/commands/run/image/index.ts +0 -5
  101. package/src/commands/run/image/list.ts +0 -84
  102. package/src/commands/run/image/upload.ts +0 -76
  103. package/src/commands/run/index.ts +0 -7
  104. package/src/commands/run/list.ts +0 -83
  105. package/src/commands/run/service/config.ts +0 -81
  106. package/src/commands/run/service/create.ts +0 -122
  107. package/src/commands/run/service/deploy.ts +0 -125
  108. package/src/commands/run/service/index.ts +0 -5
  109. package/src/commands/run/service/list.ts +0 -94
  110. package/src/commands/run/service/update.ts +0 -108
  111. package/src/commands/run/standalonegateway/common.ts +0 -8
  112. package/src/commands/run/standalonegateway/create.ts +0 -85
  113. package/src/commands/run/standalonegateway/destroy.ts +0 -59
  114. package/src/commands/run/standalonegateway/index.ts +0 -5
  115. package/src/commands/run/standalonegateway/list.ts +0 -53
  116. package/src/commands/run/standalonegateway/package.ts +0 -62
  117. package/src/commands/run/standalonegateway/turn.ts +0 -63
  118. package/src/commands/run/version/common.ts +0 -8
  119. package/src/commands/run/version/create.ts +0 -369
  120. package/src/commands/run/version/delete.ts +0 -64
  121. package/src/commands/run/version/index.ts +0 -5
  122. package/src/commands/run/version/list.ts +0 -91
  123. package/src/commands/run/version/modify.ts +0 -137
  124. package/src/commands/run/version/update.ts +0 -398
  125. package/src/commands/smart.ts +0 -132
  126. package/src/commands/storage/index.ts +0 -1
  127. package/src/commands/storage/storage.ts +0 -464
  128. package/src/commands/third/index.ts +0 -1
  129. package/src/commands/third/thirdAttach.ts +0 -49
  130. package/src/completion/index.ts +0 -13
  131. package/src/constant.ts +0 -154
  132. package/src/decorators/captureError.ts +0 -25
  133. package/src/decorators/constants.ts +0 -12
  134. package/src/decorators/deprecate.ts +0 -25
  135. package/src/decorators/guard.ts +0 -42
  136. package/src/decorators/index.ts +0 -7
  137. package/src/decorators/injectParams.ts +0 -54
  138. package/src/decorators/params/common.ts +0 -28
  139. package/src/decorators/params/index.ts +0 -35
  140. package/src/env/domain.ts +0 -33
  141. package/src/env/index.ts +0 -63
  142. package/src/env/login.ts +0 -80
  143. package/src/error.ts +0 -36
  144. package/src/function/alias.ts +0 -43
  145. package/src/function/base.ts +0 -253
  146. package/src/function/code.ts +0 -55
  147. package/src/function/concurrency.ts +0 -57
  148. package/src/function/create.ts +0 -78
  149. package/src/function/delete.ts +0 -42
  150. package/src/function/index.ts +0 -11
  151. package/src/function/layer/attach.ts +0 -68
  152. package/src/function/layer/create.ts +0 -63
  153. package/src/function/layer/delete.ts +0 -21
  154. package/src/function/layer/download.ts +0 -54
  155. package/src/function/layer/index.ts +0 -7
  156. package/src/function/layer/list.ts +0 -32
  157. package/src/function/layer/sort.ts +0 -24
  158. package/src/function/trigger.ts +0 -97
  159. package/src/function/update.ts +0 -35
  160. package/src/function/version.ts +0 -39
  161. package/src/function/vpc.ts +0 -22
  162. package/src/gateway/index.ts +0 -137
  163. package/src/help.ts +0 -50
  164. package/src/hosting.ts +0 -212
  165. package/src/index.ts +0 -13
  166. package/src/logger.ts +0 -17
  167. package/src/run/create.ts +0 -23
  168. package/src/run/delete.ts +0 -15
  169. package/src/run/image/build.ts +0 -36
  170. package/src/run/image/delete.ts +0 -14
  171. package/src/run/image/index.ts +0 -4
  172. package/src/run/image/info.ts +0 -27
  173. package/src/run/image/list.ts +0 -23
  174. package/src/run/index.ts +0 -8
  175. package/src/run/list.ts +0 -30
  176. package/src/run/repo.ts +0 -25
  177. package/src/run/service/common.ts +0 -311
  178. package/src/run/service/config.ts +0 -77
  179. package/src/run/service/create.ts +0 -52
  180. package/src/run/service/deployPackage.ts +0 -65
  181. package/src/run/service/index.ts +0 -7
  182. package/src/run/service/list.ts +0 -29
  183. package/src/run/service/showLogs.ts +0 -98
  184. package/src/run/service/update.ts +0 -82
  185. package/src/run/standalonegateway/create.ts +0 -24
  186. package/src/run/standalonegateway/destroy.ts +0 -19
  187. package/src/run/standalonegateway/index.ts +0 -5
  188. package/src/run/standalonegateway/list.ts +0 -74
  189. package/src/run/standalonegateway/package/index.ts +0 -1
  190. package/src/run/standalonegateway/package/list.ts +0 -24
  191. package/src/run/standalonegateway/turn/index.ts +0 -2
  192. package/src/run/standalonegateway/turn/off.ts +0 -19
  193. package/src/run/standalonegateway/turn/on.ts +0 -19
  194. package/src/run/version/create.ts +0 -68
  195. package/src/run/version/delete.ts +0 -16
  196. package/src/run/version/index.ts +0 -6
  197. package/src/run/version/list.ts +0 -17
  198. package/src/run/version/modify.ts +0 -17
  199. package/src/run/version/repo.ts +0 -28
  200. package/src/run/version/update.ts +0 -59
  201. package/src/storage.ts +0 -114
  202. package/src/third/index.ts +0 -13
  203. package/src/types.ts +0 -672
  204. package/src/utils/auth.ts +0 -15
  205. package/src/utils/checkTcbrEnv.ts +0 -67
  206. package/src/utils/cli-table.ts +0 -23
  207. package/src/utils/commonParamsCheck.ts +0 -65
  208. package/src/utils/config.ts +0 -39
  209. package/src/utils/env.ts +0 -244
  210. package/src/utils/fs/del.ts +0 -5
  211. package/src/utils/fs/index.ts +0 -71
  212. package/src/utils/function-packer.ts +0 -97
  213. package/src/utils/index.ts +0 -25
  214. package/src/utils/log.ts +0 -82
  215. package/src/utils/net/cloud-api-request.ts +0 -62
  216. package/src/utils/net/credential.ts +0 -53
  217. package/src/utils/net/http-request.ts +0 -84
  218. package/src/utils/net/index.ts +0 -5
  219. package/src/utils/net/manager-service.ts +0 -36
  220. package/src/utils/net/proxy.ts +0 -6
  221. package/src/utils/notice.ts +0 -28
  222. package/src/utils/output/highlight.ts +0 -5
  223. package/src/utils/output/index.ts +0 -3
  224. package/src/utils/output/link.ts +0 -10
  225. package/src/utils/output/loading.ts +0 -82
  226. package/src/utils/parallel.ts +0 -82
  227. package/src/utils/platform/index.ts +0 -3
  228. package/src/utils/platform/mac.ts +0 -21
  229. package/src/utils/platform/os.ts +0 -64
  230. package/src/utils/platform/port.ts +0 -10
  231. package/src/utils/progress-bar.ts +0 -38
  232. package/src/utils/prompt/index.ts +0 -1
  233. package/src/utils/prompt/select.ts +0 -60
  234. package/src/utils/reporter/agree.ts +0 -20
  235. package/src/utils/reporter/download.ts +0 -26
  236. package/src/utils/reporter/index.ts +0 -3
  237. package/src/utils/reporter/usage.ts +0 -20
  238. package/src/utils/store/auth.ts +0 -49
  239. package/src/utils/store/common.ts +0 -8
  240. package/src/utils/store/db.ts +0 -68
  241. package/src/utils/store/index.ts +0 -5
  242. package/src/utils/store/usage.ts +0 -12
  243. package/src/utils/tcbrApi/callTcbrApi.ts +0 -28
  244. package/src/utils/tcbrApi/index.ts +0 -1
  245. package/src/utils/template.ts +0 -170
  246. package/src/utils/tools/encoding.ts +0 -8
  247. package/src/utils/tools/index.ts +0 -4
  248. package/src/utils/tools/object.ts +0 -33
  249. package/src/utils/tools/time.ts +0 -38
  250. package/src/utils/tools/uid.ts +0 -19
  251. package/src/utils/validator.ts +0 -65
  252. package/yarn-error.log +0 -12841
@@ -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'
@@ -1,94 +0,0 @@
1
- import { Command, ICommand } from '../../common'
2
- import { loadingFactory, printHorizontalTable } from '../../../utils'
3
- import { InjectParams, EnvId, ArgsOptions, Log, Logger } from '../../../decorators'
4
- import { listLayers, getFunctionDetail, listLayerVersions } from '../../../function'
5
- import { layerCommonOptions } from './common'
6
-
7
- /**
8
- * 展示文件层列表
9
- * 1. 当不传入函数名时,展示所有文件层
10
- * 2. 当传入函数名时,展示函数绑定的文件层
11
- * 3. 当传入文件层别名时,展示文件层的版本信息
12
- */
13
- @ICommand()
14
- export class ListFileLayer extends Command {
15
- get options() {
16
- return {
17
- ...layerCommonOptions('list'),
18
- deprecateCmd: 'functions:layer:list',
19
- options: [
20
- {
21
- flags: '-e, --envId <envId>',
22
- desc: '环境 Id'
23
- },
24
- {
25
- flags: '--name, <name>',
26
- desc: '函数名称'
27
- },
28
- {
29
- flags: '--layer, <layer>',
30
- desc: '文件层别名'
31
- },
32
- {
33
- flags: '--code-secret, <codeSecret>',
34
- desc: '代码加密的函数的 CodeSecret'
35
- }
36
- ],
37
- desc: '展示文件层列表'
38
- }
39
- }
40
-
41
- @InjectParams()
42
- async execute(@EnvId() envId, @ArgsOptions() options, @Log() log: Logger) {
43
- const { name, layer, codeSecret } = options
44
-
45
- const loading = loadingFactory()
46
- loading.start('数据加载中...')
47
-
48
- let data
49
-
50
- // 展示文件层的版本信息
51
- if (layer && typeof layer === 'string') {
52
- const layerName = `${layer}_${envId}`
53
- data = await listLayerVersions({
54
- name: layerName
55
- })
56
- } else if (name && typeof name === 'string') {
57
- // 展示函数绑定的文件层
58
- const res = await getFunctionDetail({
59
- envId,
60
- functionName: name,
61
- codeSecret
62
- })
63
- data = res?.Layers || []
64
- } else if (envId) {
65
- // 展示所有文件层
66
- data = await listLayers({
67
- offset: 0,
68
- limit: 200
69
- })
70
- data = data.filter((item) => item.LayerName.includes(`_${envId}`))
71
- } else {
72
- // 展示所有文件层
73
- data = await listLayers({
74
- offset: 0,
75
- limit: 200
76
- })
77
- }
78
-
79
- loading.stop()
80
-
81
- const head = ['优先级', '名称', '状态', '版本', '证书', '支持运行时', '创建时间']
82
- const tableData = data.map((item, index) => [
83
- index + 1,
84
- item.LayerName,
85
- item.Status,
86
- item.LayerVersion,
87
- item.LicenseInfo || '空',
88
- item.CompatibleRuntimes.join(' | '),
89
- item.AddTime
90
- ])
91
- printHorizontalTable(head, tableData)
92
- log.info('Tips:函数绑定多个版本时,同名文件将按优先级从小到大的顺序进行覆盖执行。')
93
- }
94
- }
@@ -1,76 +0,0 @@
1
- import _ from 'lodash'
2
- import { prompt } from 'enquirer'
3
-
4
- import { Command, ICommand } from '../../common'
5
- import { loadingFactory } from '../../../utils'
6
- import { CloudBaseError } from '../../../error'
7
- import { getFunctionDetail, sortLayer } from '../../../function'
8
- import { InjectParams, CmdContext } from '../../../decorators'
9
- import { layerCommonOptions } from './common'
10
-
11
- @ICommand()
12
- export class SortFileLayer extends Command {
13
- get options() {
14
- return {
15
- ...layerCommonOptions('sort <name>'),
16
- deprecateCmd: 'functions:layer:sort <name>',
17
- options: [
18
- {
19
- flags: '-e, --envId <envId>',
20
- desc: '环境 Id'
21
- },
22
- {
23
- flags: '--code-secret, <codeSecret>',
24
- desc: '代码加密的函数的 CodeSecret'
25
- }
26
- ],
27
- desc: '重新排列云函数绑定的文件层的顺序'
28
- }
29
- }
30
-
31
- @InjectParams()
32
- async execute(@CmdContext() ctx) {
33
- const { envId, options, params } = ctx
34
- const { codeSecret } = options
35
- const fnName = params?.[0]
36
-
37
- const loading = loadingFactory()
38
- loading.start('数据加载中...')
39
- const detail = await getFunctionDetail({
40
- envId,
41
- codeSecret,
42
- functionName: fnName
43
- })
44
- loading.stop()
45
-
46
- const layers = detail.Layers.map((item) => ({
47
- name: `${item.LayerName} - ${item.LayerVersion}`,
48
- value: item
49
- }))
50
-
51
- if (!layers.length) {
52
- throw new CloudBaseError('没有可用的文件层,请先创建文件层!')
53
- }
54
-
55
- let { sortLayers } = await prompt<any>({
56
- type: 'sort',
57
- name: 'sortLayers',
58
- message: '选择文件层',
59
- numbered: true,
60
- choices: layers,
61
- result(choices) {
62
- return Object.values(this.map(choices)) as any
63
- }
64
- })
65
-
66
- sortLayers = sortLayers.map((item) => _.pick(item, ['LayerName', 'LayerVersion']))
67
-
68
- loading.start('文件层排序中...')
69
- await sortLayer({
70
- envId,
71
- functionName: fnName,
72
- layers: sortLayers
73
- })
74
- loading.succeed('文件层排序成功!')
75
- }
76
- }
@@ -1,68 +0,0 @@
1
- import { Command, ICommand } from '../common'
2
- import { CloudBaseError } from '../../error'
3
- import { listFunction } from '../../function'
4
- import { printHorizontalTable, loadingFactory } from '../../utils'
5
- import { InjectParams, EnvId, ArgsOptions } from '../../decorators'
6
- import { StatusMap } from '../../constant'
7
-
8
- @ICommand()
9
- export class ListFunction extends Command {
10
- get options() {
11
- return {
12
- cmd: 'fn',
13
- childCmd: 'list',
14
- deprecateCmd: 'functions:list',
15
- options: [
16
- {
17
- flags: '-e, --envId <envId>',
18
- desc: '环境 Id'
19
- },
20
- { flags: '-l, --limit <limit>', desc: '返回数据长度,默认值为 20' },
21
- {
22
- flags: '-o, --offset <offset>',
23
- desc: '数据偏移量,默认值为 0'
24
- }
25
- ],
26
- desc: '展示云函数列表'
27
- }
28
- }
29
-
30
- @InjectParams()
31
- async execute(@EnvId() envId, @ArgsOptions() options) {
32
- let { limit = 20, offset = 0 } = options
33
- limit = Number(limit)
34
- offset = Number(offset)
35
- if (!Number.isInteger(limit) || !Number.isInteger(offset)) {
36
- throw new CloudBaseError('limit 和 offset 必须为整数')
37
- }
38
-
39
- if (limit < 0 || offset < 0) {
40
- throw new CloudBaseError('limit 和 offset 必须为大于 0 的整数')
41
- }
42
-
43
- const loading = loadingFactory()
44
-
45
- loading.start('数据加载中...')
46
-
47
- const data = await listFunction({
48
- envId,
49
- limit: Number(limit),
50
- offset: Number(offset)
51
- })
52
-
53
- loading.stop()
54
-
55
- const head: string[] = ['函数 Id', '函数名称', '运行时', '创建时间', '修改时间', '状态']
56
-
57
- const tableData = data.map((item) => [
58
- item.FunctionId,
59
- item.FunctionName,
60
- item.Runtime,
61
- item.AddTime,
62
- item.ModTime,
63
- StatusMap[item.Status]
64
- ])
65
-
66
- printHorizontalTable(head, tableData)
67
- }
68
- }