@cloudbase/cli 2.2.13 → 2.3.0
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/.editorconfig +9 -9
- package/.eslintignore +7 -7
- package/.eslintrc +35 -35
- package/.prettierrc.js +29 -29
- package/.vscode/launch.json +26 -26
- package/LICENSE +5 -5
- package/README.md +35 -35
- package/bin/cloudbase.js +6 -6
- package/bin/tcb.js +332 -330
- package/changelog.md +6 -6
- package/jest.config.js +17 -17
- package/lib/commands/account/login.js +14 -14
- package/lib/commands/lowcode/app.js +6 -1
- package/lib/commands/storage/storage.js +1 -1
- package/lib/env/login.js +7 -7
- package/lib/utils/checkTcbrEnv.js +21 -21
- package/package.json +3 -3
- package/post-install.js +61 -61
- package/runtime/nodejs/bootstrap.js +255 -255
- package/runtime/nodejs/runtime.js +183 -183
- package/templates/html/loginFail.html +90 -90
- package/templates/html/loginSuccess.html +86 -86
- package/templates/server/node/_gitignore +54 -54
- package/templates/server/node/cloudbaserc.json +10 -10
- package/templates/server/node/index.js +5 -5
- package/templates/server/node/package.json +9 -9
- package/tsconfig.json +19 -19
- package/tsconfig.test.json +13 -13
package/bin/tcb.js
CHANGED
|
@@ -1,331 +1,333 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const os = require('os')
|
|
3
|
-
const yargsParser = require('yargs-parser')
|
|
4
|
-
const chalk = require('chalk')
|
|
5
|
-
const address = require('address')
|
|
6
|
-
const { program } = require('commander')
|
|
7
|
-
const Sentry = require('@sentry/node')
|
|
8
|
-
const logSymbols = require('log-symbols')
|
|
9
|
-
const didYouMean = require('didyoumean')
|
|
10
|
-
const updateNotifier = require('update-notifier')
|
|
11
|
-
const frameworkPkg = require('@cloudbase/framework-core/package.json')
|
|
12
|
-
const
|
|
13
|
-
const {
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const {
|
|
21
|
-
const {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
'ap-
|
|
29
|
-
'ap-
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Sentry
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
console.log(chalk.gray(`CloudBase
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
program.
|
|
100
|
-
program.option('--
|
|
101
|
-
program.option('
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
processArgv
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
//
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const os = require('os')
|
|
3
|
+
const yargsParser = require('yargs-parser')
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
const address = require('address')
|
|
6
|
+
const { program } = require('commander')
|
|
7
|
+
const Sentry = require('@sentry/node')
|
|
8
|
+
const logSymbols = require('log-symbols')
|
|
9
|
+
const didYouMean = require('didyoumean')
|
|
10
|
+
const updateNotifier = require('update-notifier')
|
|
11
|
+
const frameworkPkg = require('@cloudbase/framework-core/package.json')
|
|
12
|
+
const wedaPkg = require('@cloudbase/lowcode-cli/package.json')
|
|
13
|
+
const { CloudApiService } = require('@cloudbase/cloud-api')
|
|
14
|
+
const { getCredentialWithoutCheck } = require('@cloudbase/toolbox')
|
|
15
|
+
const { Confirm } = require('enquirer')
|
|
16
|
+
const execa = require('execa')
|
|
17
|
+
|
|
18
|
+
const pkg = require('../package.json')
|
|
19
|
+
const store = require('../lib/utils/store')
|
|
20
|
+
const { ALL_COMMANDS } = require('../lib/constant')
|
|
21
|
+
const { getProxy } = require('../lib/utils/net')
|
|
22
|
+
const { getCloudBaseConfig, getPrivateSettings } = require('../lib/utils/config')
|
|
23
|
+
const { registerCommands } = require('../lib')
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const regionSupported = ['ap-shanghai', 'ap-beijing', 'ap-guangzhou']
|
|
27
|
+
const regionSupportedMap = {
|
|
28
|
+
'ap-shanghai': '上海',
|
|
29
|
+
'ap-beijing': '北京',
|
|
30
|
+
'ap-guangzhou': '广州',
|
|
31
|
+
'sh': '上海',
|
|
32
|
+
'bj': '北京',
|
|
33
|
+
'gz': '广州'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function main() {
|
|
37
|
+
let processArgv = process.argv
|
|
38
|
+
const isBeta = pkg.version.indexOf('-') > -1
|
|
39
|
+
process.CLI_VERSION = pkg.version
|
|
40
|
+
|
|
41
|
+
const [major, minor] = process.versions.node.split('.').slice(0, 2)
|
|
42
|
+
|
|
43
|
+
// Node 版本检验提示
|
|
44
|
+
if (Number(major) < 8 || (Number(major) === 8 && Number(minor) < 6)) {
|
|
45
|
+
console.log(
|
|
46
|
+
chalk.bold.red(
|
|
47
|
+
'您的 Node 版本较低,CloudBase CLI 可能无法正常运行,请升级 Node 到 v8.6.0 以上!\n'
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Sentry 错误上报
|
|
53
|
+
Sentry.init({
|
|
54
|
+
release: pkg.version,
|
|
55
|
+
dsn: 'https://fff0077d06624655ad70d1ee25df419e@report.url.cn/sentry/1782',
|
|
56
|
+
httpsProxy: getProxy() || '',
|
|
57
|
+
serverName: os.hostname(),
|
|
58
|
+
integrations: [
|
|
59
|
+
new Sentry.Integrations.OnUnhandledRejection({
|
|
60
|
+
mode: 'none'
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// 输出版本信息
|
|
66
|
+
console.log(chalk.gray(`CloudBase CLI ${pkg.version}`))
|
|
67
|
+
console.log(chalk.gray(`CloudBase Framework ${frameworkPkg.version}`))
|
|
68
|
+
console.log(chalk.gray(`Weda ${wedaPkg.version}`))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const yargsParsedResult = yargsParser(process.argv.slice(2));
|
|
72
|
+
const config = await getCloudBaseConfig(yargsParsedResult.configFile);
|
|
73
|
+
const privateSettings = getPrivateSettings(config);
|
|
74
|
+
if (privateSettings) {
|
|
75
|
+
console.log(chalk.gray(`检测到私有化配置`))
|
|
76
|
+
if (privateSettings.endpoints && privateSettings.endpoints.cliApi) {
|
|
77
|
+
// 初始化 lowcode 服务cliapi入口
|
|
78
|
+
process.env.CLOUDBASE_LOWCODE_CLOUDAPI_URL = privateSettings.endpoints.cliApi;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
// 注册命令
|
|
83
|
+
await registerCommands()
|
|
84
|
+
|
|
85
|
+
// 设置 Sentry 上报的用户 uin
|
|
86
|
+
Sentry.configureScope((scope) => {
|
|
87
|
+
try {
|
|
88
|
+
const credential = store.authStore.get('credential') || {}
|
|
89
|
+
scope.setUser({
|
|
90
|
+
uin: credential.uin || '',
|
|
91
|
+
ip: address.ip() || ''
|
|
92
|
+
})
|
|
93
|
+
} catch (e) {
|
|
94
|
+
Sentry.captureException(e)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// 设置 options 选项
|
|
99
|
+
program.storeOptionsAsProperties(false)
|
|
100
|
+
program.option('--verbose', '打印出内部运行信息')
|
|
101
|
+
program.option('--mode <mode>', '指定加载 env 文件的环境')
|
|
102
|
+
program.option('--config-file <path>', '设置配置文件,默认为 cloudbaserc.json')
|
|
103
|
+
program.option('-r, --region <region>', '指定环境地域')
|
|
104
|
+
|
|
105
|
+
if (!privateSettings) {
|
|
106
|
+
// HACK: 隐藏自动生成的 help 信息
|
|
107
|
+
program.helpOption(false)
|
|
108
|
+
}
|
|
109
|
+
const isCommandEmpty = yargsParsedResult._.length === 0;
|
|
110
|
+
|
|
111
|
+
// -v 时输出的版本信息,设置时避免影响其他命令使用 -v
|
|
112
|
+
if (isCommandEmpty) {
|
|
113
|
+
program.version(
|
|
114
|
+
`\nCLI: ${pkg.version}\nFramework: ${frameworkPkg.version}\nWeda: ${wedaPkg.version}`,
|
|
115
|
+
'-v, --version',
|
|
116
|
+
'输出当前 CloudBase CLI 版本'
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 处理无效命令
|
|
121
|
+
program.action(() => {
|
|
122
|
+
const args = program.args
|
|
123
|
+
if (!Array.isArray(args) || !args.length) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
const cmd = args.join(' ')
|
|
127
|
+
console.log(chalk.bold.red('Error: ') + `${cmd} 不是有效的命令`)
|
|
128
|
+
didYouMean.threshold = 0.5
|
|
129
|
+
didYouMean.caseSensitive = false
|
|
130
|
+
const suggest = didYouMean(cmd, ALL_COMMANDS)
|
|
131
|
+
if (suggest) {
|
|
132
|
+
console.log(chalk.bold(`\n您是不是想使用命令:tcb ${suggest}\n`))
|
|
133
|
+
}
|
|
134
|
+
console.log(`💡使用 ${chalk.bold('tcb -h')} 查看所有命令`)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
// 没有使用命令
|
|
138
|
+
if (isCommandEmpty) {
|
|
139
|
+
if (privateSettings) {
|
|
140
|
+
program.outputHelp()
|
|
141
|
+
} else {
|
|
142
|
+
if (['-h', '--help'].includes(processArgv[2])) {
|
|
143
|
+
// 需要隐藏的选项
|
|
144
|
+
const hideArgs = ['-h', '--help']
|
|
145
|
+
hideArgs.forEach((arg) => {
|
|
146
|
+
const index = processArgv.indexOf(arg)
|
|
147
|
+
if (index > -1) {
|
|
148
|
+
processArgv.splice(index, 1)
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
const { outputHelpInfo } = require('../lib/help')
|
|
152
|
+
outputHelpInfo()
|
|
153
|
+
} else if (!['-v', '--version'].includes(processArgv[2])) {
|
|
154
|
+
// HACK: framework 智能命令
|
|
155
|
+
const { smartDeploy } = require('../lib')
|
|
156
|
+
smartDeploy()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
program.parse(processArgv)
|
|
163
|
+
} catch (e) {
|
|
164
|
+
const errMsg = `${logSymbols.error} ${e.message || '参数异常,请检查您是否使用了正确的命令!'}`
|
|
165
|
+
console.log(errMsg)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 处理异常
|
|
170
|
+
*/
|
|
171
|
+
async function errorHandler(err) {
|
|
172
|
+
process.emit('tcbError')
|
|
173
|
+
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']
|
|
174
|
+
// 忽略自定义错误的错误栈
|
|
175
|
+
if (err && err.stack && !stackIngoreErrors.includes(err.name)) {
|
|
176
|
+
console.log(err.stack)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 3 空格,兼容中文字符编码长度问题
|
|
180
|
+
if (err && err.message) {
|
|
181
|
+
let errMsg = logSymbols.error + ' ' + err.message
|
|
182
|
+
errMsg += err.requestId ? `\n${err.requestId}` : ''
|
|
183
|
+
console.log(errMsg)
|
|
184
|
+
|
|
185
|
+
// 多地域错误提示
|
|
186
|
+
if (errMsg.includes('Environment') && errMsg.includes('not found')) {
|
|
187
|
+
// 检查是否已经指定了 -r 或 --region 参数,如未指定则尝试获取地域信息
|
|
188
|
+
const regionSpecified = processArgv.indexOf('-r') !== -1 || processArgv.indexOf('--region') !== -1
|
|
189
|
+
const region = yargsParsedResult.r || yargsParsedResult.region
|
|
190
|
+
const multiRegionErrMsg = `\n此环境可能不属于当前账号,或为非${regionSupportedMap[region] || '上海'}地域环境,如需切换地域请追加参数(例:-r gz),请检查环境归属,参考多地域使用方法:https://docs.cloudbase.net/cli-v1/region.html`
|
|
191
|
+
if (!regionSpecified) {
|
|
192
|
+
|
|
193
|
+
// 从 -e 参数、--envId 参数和配置文件中获取环境 id
|
|
194
|
+
const envId = yargsParsedResult.e || yargsParsedResult.envId || config.envId
|
|
195
|
+
|
|
196
|
+
// 调用 API 接口尝试查询环境信息
|
|
197
|
+
const predictRegion = await tryTellEnvRegion(envId)
|
|
198
|
+
|
|
199
|
+
if (regionSupported.includes(predictRegion)) {
|
|
200
|
+
// 让用户选择是否切换地域
|
|
201
|
+
const prompt = new Confirm({
|
|
202
|
+
type: 'confirm',
|
|
203
|
+
name: 'confirm',
|
|
204
|
+
message: `该环境可能属于 ${regionSupportedMap[predictRegion]} 地域,是否切换地域并重新执行命令?`,
|
|
205
|
+
initial: 'Y'
|
|
206
|
+
})
|
|
207
|
+
const confirm = await prompt.run()
|
|
208
|
+
if (confirm) {
|
|
209
|
+
// 检查原始命令是否已经追加了 -r 参数,如果有则替换,如果没有则追加
|
|
210
|
+
const regionArgIndex = processArgv.indexOf('-r')
|
|
211
|
+
if (regionArgIndex !== -1) {
|
|
212
|
+
processArgv[regionArgIndex + 1] = predictRegion
|
|
213
|
+
} else {
|
|
214
|
+
processArgv.push('-r', predictRegion)
|
|
215
|
+
}
|
|
216
|
+
// 重新执行命令
|
|
217
|
+
const newArgvStr = processArgv.slice(2).join(' ')
|
|
218
|
+
console.log(`\n${chalk.yellow.bold('正在重新执行命令:')} tcb ${newArgvStr}\n`)
|
|
219
|
+
await execa('tcb', processArgv.slice(2), {
|
|
220
|
+
stdio: 'inherit'
|
|
221
|
+
})
|
|
222
|
+
process.emit('tcbExit')
|
|
223
|
+
process.exit(0)
|
|
224
|
+
} else {
|
|
225
|
+
console.log(chalk.yellow.bold(multiRegionErrMsg))
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
console.log(chalk.yellow.bold(multiRegionErrMsg))
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 输出详细的错误信息
|
|
235
|
+
if (processArgv.includes('--verbose')) {
|
|
236
|
+
console.log(err)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
process.emit('tcbExit')
|
|
240
|
+
setTimeout(() => {
|
|
241
|
+
process.exit(1)
|
|
242
|
+
}, 1000)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const isTokenExpired = (credential, gap = 120) =>
|
|
246
|
+
credential.accessTokenExpired && Number(credential.accessTokenExpired) < Date.now() + gap * 1000
|
|
247
|
+
|
|
248
|
+
async function tryTellEnvRegion(envId) {
|
|
249
|
+
// 依次调用不同地域的 API 接口查询环境信息
|
|
250
|
+
const fetchedRegion = await Promise.all(regionSupported.map(async region => {
|
|
251
|
+
const { EnvList = [] } = await fetchEnvInfoWithRegion(envId, region)
|
|
252
|
+
if (EnvList.length !== 0 && EnvList.find(item => item.EnvId === envId)) {
|
|
253
|
+
return res.EnvList[0].Region
|
|
254
|
+
}
|
|
255
|
+
return ''
|
|
256
|
+
}))
|
|
257
|
+
|
|
258
|
+
let predictRegion = ''
|
|
259
|
+
fetchedRegion.forEach(region => {
|
|
260
|
+
if (region) {
|
|
261
|
+
predictRegion = region
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
return predictRegion
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 在指定地域调用 API 接口查询环境信息
|
|
268
|
+
async function fetchEnvInfoWithRegion(envId, region) {
|
|
269
|
+
let commonCredential = {}
|
|
270
|
+
const commonOpts = {
|
|
271
|
+
service: 'tcb',
|
|
272
|
+
version: '2019-09-24',
|
|
273
|
+
proxy: getProxy(),
|
|
274
|
+
timeout: 15000,
|
|
275
|
+
getCredential: async () => {
|
|
276
|
+
if (commonCredential.secretId && !isTokenExpired(commonCredential)) {
|
|
277
|
+
return commonCredential
|
|
278
|
+
}
|
|
279
|
+
const credential = await getCredentialWithoutCheck()
|
|
280
|
+
if (!credential) {
|
|
281
|
+
throw new Error('无有效身份信息,请使用 cloudbase login 登录')
|
|
282
|
+
}
|
|
283
|
+
commonCredential = credential
|
|
284
|
+
return {
|
|
285
|
+
...credential,
|
|
286
|
+
tokenExpired: Number(credential.accessTokenExpired)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const apiName = 'DescribeEnvs'
|
|
291
|
+
const tcbApi = new CloudApiService({
|
|
292
|
+
...commonOpts,
|
|
293
|
+
region
|
|
294
|
+
})
|
|
295
|
+
const res = await tcbApi.request(apiName, {
|
|
296
|
+
EnvId: envId,
|
|
297
|
+
})
|
|
298
|
+
return res
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
process.on('uncaughtException', errorHandler)
|
|
302
|
+
process.on('unhandledRejection', errorHandler)
|
|
303
|
+
|
|
304
|
+
// 检查更新
|
|
305
|
+
const ONE_DAY = 86400000
|
|
306
|
+
// Beta 版 1 个小时检查一次,稳定版 1 天检查一次
|
|
307
|
+
const CheckInterval = isBeta ? 3600000 : ONE_DAY
|
|
308
|
+
|
|
309
|
+
const notifier = updateNotifier({
|
|
310
|
+
pkg,
|
|
311
|
+
distTag: isBeta ? 'beta' : 'latest',
|
|
312
|
+
// 检查更新间隔 1 天
|
|
313
|
+
updateCheckInterval: CheckInterval
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
notifier.notify({
|
|
317
|
+
isGlobal: true
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (require.main === module) {
|
|
323
|
+
try {
|
|
324
|
+
main()
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.log(error)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
process.on('unhandledRejection', (err) => {
|
|
330
|
+
console.log('unhandledRejection', err)
|
|
331
|
+
})
|
|
332
|
+
|
|
331
333
|
exports.main = main
|