@cloudbase/cli 2.3.0 → 2.3.2

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.
@@ -1,183 +1,183 @@
1
- /* eslint-disable */
2
- const fs = require('fs')
3
- const crypto = require('crypto')
4
-
5
- var GLOBAL_FUNCTION_HANDLER = process.argv[2] || process.env.SCF_FUNCTION_HANDLER || 'index.main'
6
- var GLOBAL_FUNCTION_NAME = process.env.SCF_FUNCTION_NAME || 'main'
7
- var GLOBAL_EVENT_BODY =
8
- process.argv[3] ||
9
- process.env.SCF_EVENT_BODY ||
10
- (process.env.DOCKER_USE_STDIN && fs.readFileSync('/dev/stdin', 'utf8')) ||
11
- '{}'
12
-
13
- var GLOBAL_USER_FILE_PATH = process.env.GLOBAL_USER_FILE_PATH || ''
14
- var GLOBAL_VERSION = process.env.SCF_FUNCTION_VERSION || '$LATEST'
15
- var GLOBAL_MEM_SIZE = process.env.SCF_FUNCTION_MEMORY_SIZE || '256'
16
- var GLOBAL_TIMEOUT = process.env.SCF_FUNCTION_TIMEOUT || '3'
17
- var GLOBAL_ENVIRON = process.env.SCF_FUNCTION_ENVIRON || ''
18
- var GLOBAL_IS_QUIET = process.env.SCF_DISPLAY_IS_QUIET === 'True' || false
19
-
20
- var GLOBAL_REQUEST_ID = uuid()
21
- var GLOBAL_START_TIME = process.hrtime()
22
- var GLOBAL_SOCK = -1
23
- var GLOBAL_STAGE = 0
24
-
25
- module.exports = {
26
- init: function() {
27
- if (!GLOBAL_IS_QUIET) {
28
- consoleLog('开始本地执行云函数,受环境影响,执行结果可能与云端存在一定差异!')
29
- consoleLog('START RequestId: ' + GLOBAL_REQUEST_ID)
30
- }
31
- return 0
32
- },
33
- wait_for_invoke: function() {
34
- var invokeInfo = []
35
-
36
- GLOBAL_STAGE += 1
37
- switch (GLOBAL_STAGE) {
38
- case 1:
39
- invokeInfo.cmd = 'RELOAD'
40
- invokeInfo.context = GLOBAL_USER_FILE_PATH + GLOBAL_FUNCTION_HANDLER
41
- invokeInfo.globalHandler = GLOBAL_FUNCTION_HANDLER
42
- invokeInfo.filePath = GLOBAL_USER_FILE_PATH
43
- break
44
- case 2:
45
- invokeInfo.cmd = 'EVENT'
46
- invokeInfo.sockfd = GLOBAL_SOCK
47
- invokeInfo.event = GLOBAL_EVENT_BODY
48
- invokeInfo.context = initContext()
49
- break
50
- default:
51
- process.exit()
52
- }
53
-
54
- return invokeInfo
55
- },
56
- log: function(str) {
57
- // consoleLog(formatSystem(str))
58
- },
59
- console_log: function(str, err = false) {
60
- if (!GLOBAL_IS_QUIET) {
61
- if (err === false) {
62
- consoleLog(formatConsole(str))
63
- } else {
64
- consoleLogErr(formatConsole(str))
65
- }
66
- }
67
- },
68
- report_fail: function(stackTrace, errNum, errType = 0) {
69
- const result = {}
70
-
71
- result['errorCode'] = 1
72
- result['errorMessage'] = 'user code exception caught'
73
- if (stackTrace) {
74
- result['stackTrace'] = stackTrace
75
- }
76
-
77
- reportDone('', (errType = 1))
78
- // console.dir(result);
79
- consoleLogErr(JSON.stringify(result))
80
- },
81
- report_running: function() {
82
- GLOBAL_START_TIME = process.hrtime()
83
- },
84
- report_done: function(resultStr, errType = 0) {
85
- reportDone(resultStr, errType)
86
- }
87
- }
88
-
89
- function initContext() {
90
- var context = {}
91
- context['function_version'] = GLOBAL_VERSION
92
- context['function_name'] = GLOBAL_FUNCTION_NAME
93
-
94
- context['time_limit_in_ms'] = GLOBAL_TIMEOUT
95
- context['memory_limit_in_mb'] = GLOBAL_MEM_SIZE
96
-
97
- context['request_id'] = GLOBAL_REQUEST_ID
98
- context['environ'] = GLOBAL_ENVIRON
99
-
100
- return JSON.stringify(context)
101
- }
102
-
103
- function reportDone(resultStr, errType = 0) {
104
- if (GLOBAL_IS_QUIET) {
105
- if (typeof resultStr === 'string') {
106
- if (errType === 0) consoleLog(resultStr)
107
- else consoleLogErr(resultStr)
108
- }
109
- return
110
- }
111
-
112
- var diffMs = hrTimeMs(process.hrtime(GLOBAL_START_TIME))
113
- var billedMs = Math.min(100 * (Math.floor(diffMs / 100) + 1), GLOBAL_TIMEOUT * 1000)
114
- if (errType === 0) {
115
- consoleLog('END RequestId: ' + GLOBAL_REQUEST_ID)
116
- consoleLog(
117
- [
118
- '运行信息:',
119
- 'REPORT RequestId: ' + GLOBAL_REQUEST_ID,
120
- 'Duration: ' + diffMs.toFixed(2) + ' ms',
121
- 'Billed Duration: ' + billedMs + ' ms',
122
- 'Memory Size: ' + GLOBAL_MEM_SIZE + ' MB',
123
- 'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB'
124
- ].join('\n')
125
- )
126
- } else {
127
- consoleLogErr(
128
- [
129
- '运行信息:',
130
- 'REPORT RequestId: ' + GLOBAL_REQUEST_ID,
131
- 'Duration: ' + diffMs.toFixed(2) + ' ms',
132
- 'Billed Duration: ' + billedMs + ' ms',
133
- 'Memory Size: ' + GLOBAL_MEM_SIZE + ' MB',
134
- 'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB'
135
- ].join('\n')
136
- )
137
- }
138
-
139
- if (typeof resultStr === 'string') {
140
- if (errType === 0) {
141
- consoleLog('返回结果:\n' + resultStr)
142
- } else {
143
- consoleLogErr('返回结果:\n' + resultStr)
144
- }
145
- }
146
- }
147
-
148
- function consoleLog(str) {
149
- process.stdout.write(str + '\n')
150
- }
151
-
152
- function consoleLogErr(str) {
153
- process.stderr.write(str + '\n')
154
- }
155
-
156
- function formatConsole(str) {
157
- return str.replace(/^[0-9TZ:.-]+\t[0-9a-f-]+\t/, '\u001b[34m$&\u001b[0m')
158
- }
159
-
160
- function formatSystem(str) {
161
- return '\u001b[32m' + str + '\u001b[0m'
162
- }
163
-
164
- function hrTimeMs(hrtime) {
165
- return (hrtime[0] * 1e9 + hrtime[1]) / 1e6
166
- }
167
-
168
- function uuid() {
169
- return (
170
- crypto.randomBytes(4).toString('hex') +
171
- '-' +
172
- crypto.randomBytes(2).toString('hex') +
173
- '-' +
174
- crypto
175
- .randomBytes(2)
176
- .toString('hex')
177
- .replace(/^./, '1') +
178
- '-' +
179
- crypto.randomBytes(2).toString('hex') +
180
- '-' +
181
- crypto.randomBytes(6).toString('hex')
182
- )
183
- }
1
+ /* eslint-disable */
2
+ const fs = require('fs')
3
+ const crypto = require('crypto')
4
+
5
+ var GLOBAL_FUNCTION_HANDLER = process.argv[2] || process.env.SCF_FUNCTION_HANDLER || 'index.main'
6
+ var GLOBAL_FUNCTION_NAME = process.env.SCF_FUNCTION_NAME || 'main'
7
+ var GLOBAL_EVENT_BODY =
8
+ process.argv[3] ||
9
+ process.env.SCF_EVENT_BODY ||
10
+ (process.env.DOCKER_USE_STDIN && fs.readFileSync('/dev/stdin', 'utf8')) ||
11
+ '{}'
12
+
13
+ var GLOBAL_USER_FILE_PATH = process.env.GLOBAL_USER_FILE_PATH || ''
14
+ var GLOBAL_VERSION = process.env.SCF_FUNCTION_VERSION || '$LATEST'
15
+ var GLOBAL_MEM_SIZE = process.env.SCF_FUNCTION_MEMORY_SIZE || '256'
16
+ var GLOBAL_TIMEOUT = process.env.SCF_FUNCTION_TIMEOUT || '3'
17
+ var GLOBAL_ENVIRON = process.env.SCF_FUNCTION_ENVIRON || ''
18
+ var GLOBAL_IS_QUIET = process.env.SCF_DISPLAY_IS_QUIET === 'True' || false
19
+
20
+ var GLOBAL_REQUEST_ID = uuid()
21
+ var GLOBAL_START_TIME = process.hrtime()
22
+ var GLOBAL_SOCK = -1
23
+ var GLOBAL_STAGE = 0
24
+
25
+ module.exports = {
26
+ init: function() {
27
+ if (!GLOBAL_IS_QUIET) {
28
+ consoleLog('开始本地执行云函数,受环境影响,执行结果可能与云端存在一定差异!')
29
+ consoleLog('START RequestId: ' + GLOBAL_REQUEST_ID)
30
+ }
31
+ return 0
32
+ },
33
+ wait_for_invoke: function() {
34
+ var invokeInfo = []
35
+
36
+ GLOBAL_STAGE += 1
37
+ switch (GLOBAL_STAGE) {
38
+ case 1:
39
+ invokeInfo.cmd = 'RELOAD'
40
+ invokeInfo.context = GLOBAL_USER_FILE_PATH + GLOBAL_FUNCTION_HANDLER
41
+ invokeInfo.globalHandler = GLOBAL_FUNCTION_HANDLER
42
+ invokeInfo.filePath = GLOBAL_USER_FILE_PATH
43
+ break
44
+ case 2:
45
+ invokeInfo.cmd = 'EVENT'
46
+ invokeInfo.sockfd = GLOBAL_SOCK
47
+ invokeInfo.event = GLOBAL_EVENT_BODY
48
+ invokeInfo.context = initContext()
49
+ break
50
+ default:
51
+ process.exit()
52
+ }
53
+
54
+ return invokeInfo
55
+ },
56
+ log: function(str) {
57
+ // consoleLog(formatSystem(str))
58
+ },
59
+ console_log: function(str, err = false) {
60
+ if (!GLOBAL_IS_QUIET) {
61
+ if (err === false) {
62
+ consoleLog(formatConsole(str))
63
+ } else {
64
+ consoleLogErr(formatConsole(str))
65
+ }
66
+ }
67
+ },
68
+ report_fail: function(stackTrace, errNum, errType = 0) {
69
+ const result = {}
70
+
71
+ result['errorCode'] = 1
72
+ result['errorMessage'] = 'user code exception caught'
73
+ if (stackTrace) {
74
+ result['stackTrace'] = stackTrace
75
+ }
76
+
77
+ reportDone('', (errType = 1))
78
+ // console.dir(result);
79
+ consoleLogErr(JSON.stringify(result))
80
+ },
81
+ report_running: function() {
82
+ GLOBAL_START_TIME = process.hrtime()
83
+ },
84
+ report_done: function(resultStr, errType = 0) {
85
+ reportDone(resultStr, errType)
86
+ }
87
+ }
88
+
89
+ function initContext() {
90
+ var context = {}
91
+ context['function_version'] = GLOBAL_VERSION
92
+ context['function_name'] = GLOBAL_FUNCTION_NAME
93
+
94
+ context['time_limit_in_ms'] = GLOBAL_TIMEOUT
95
+ context['memory_limit_in_mb'] = GLOBAL_MEM_SIZE
96
+
97
+ context['request_id'] = GLOBAL_REQUEST_ID
98
+ context['environ'] = GLOBAL_ENVIRON
99
+
100
+ return JSON.stringify(context)
101
+ }
102
+
103
+ function reportDone(resultStr, errType = 0) {
104
+ if (GLOBAL_IS_QUIET) {
105
+ if (typeof resultStr === 'string') {
106
+ if (errType === 0) consoleLog(resultStr)
107
+ else consoleLogErr(resultStr)
108
+ }
109
+ return
110
+ }
111
+
112
+ var diffMs = hrTimeMs(process.hrtime(GLOBAL_START_TIME))
113
+ var billedMs = Math.min(100 * (Math.floor(diffMs / 100) + 1), GLOBAL_TIMEOUT * 1000)
114
+ if (errType === 0) {
115
+ consoleLog('END RequestId: ' + GLOBAL_REQUEST_ID)
116
+ consoleLog(
117
+ [
118
+ '运行信息:',
119
+ 'REPORT RequestId: ' + GLOBAL_REQUEST_ID,
120
+ 'Duration: ' + diffMs.toFixed(2) + ' ms',
121
+ 'Billed Duration: ' + billedMs + ' ms',
122
+ 'Memory Size: ' + GLOBAL_MEM_SIZE + ' MB',
123
+ 'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB'
124
+ ].join('\n')
125
+ )
126
+ } else {
127
+ consoleLogErr(
128
+ [
129
+ '运行信息:',
130
+ 'REPORT RequestId: ' + GLOBAL_REQUEST_ID,
131
+ 'Duration: ' + diffMs.toFixed(2) + ' ms',
132
+ 'Billed Duration: ' + billedMs + ' ms',
133
+ 'Memory Size: ' + GLOBAL_MEM_SIZE + ' MB',
134
+ 'Max Memory Used: ' + Math.round(process.memoryUsage().rss / (1024 * 1024)) + ' MB'
135
+ ].join('\n')
136
+ )
137
+ }
138
+
139
+ if (typeof resultStr === 'string') {
140
+ if (errType === 0) {
141
+ consoleLog('返回结果:\n' + resultStr)
142
+ } else {
143
+ consoleLogErr('返回结果:\n' + resultStr)
144
+ }
145
+ }
146
+ }
147
+
148
+ function consoleLog(str) {
149
+ process.stdout.write(str + '\n')
150
+ }
151
+
152
+ function consoleLogErr(str) {
153
+ process.stderr.write(str + '\n')
154
+ }
155
+
156
+ function formatConsole(str) {
157
+ return str.replace(/^[0-9TZ:.-]+\t[0-9a-f-]+\t/, '\u001b[34m$&\u001b[0m')
158
+ }
159
+
160
+ function formatSystem(str) {
161
+ return '\u001b[32m' + str + '\u001b[0m'
162
+ }
163
+
164
+ function hrTimeMs(hrtime) {
165
+ return (hrtime[0] * 1e9 + hrtime[1]) / 1e6
166
+ }
167
+
168
+ function uuid() {
169
+ return (
170
+ crypto.randomBytes(4).toString('hex') +
171
+ '-' +
172
+ crypto.randomBytes(2).toString('hex') +
173
+ '-' +
174
+ crypto
175
+ .randomBytes(2)
176
+ .toString('hex')
177
+ .replace(/^./, '1') +
178
+ '-' +
179
+ crypto.randomBytes(2).toString('hex') +
180
+ '-' +
181
+ crypto.randomBytes(6).toString('hex')
182
+ )
183
+ }
@@ -1,90 +1,90 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title>CloudBase CLI</title>
7
-
8
- <style media="screen">
9
- body {
10
- background: #eceff1;
11
- color: rgba(0, 0, 0, 0.87);
12
- font-family: Roboto, Helvetica, Arial, sans-serif;
13
- margin: 0;
14
- padding: 0;
15
- }
16
- #message {
17
- background: white;
18
- max-width: 360px;
19
- margin: 100px auto 16px;
20
- padding: 32px 24px 8px;
21
- border-radius: 3px;
22
- }
23
- #message h2 {
24
- color: #f44336;
25
- font-weight: bold;
26
- font-size: 16px;
27
- margin: 0 0 8px;
28
- }
29
- #message h1 {
30
- font-size: 22px;
31
- font-weight: 300;
32
- color: rgba(0, 0, 0, 0.6);
33
- margin: 0 0 16px;
34
- }
35
- #message p {
36
- line-height: 140%;
37
- margin: 16px 0 24px;
38
- font-size: 14px;
39
- }
40
- #message a {
41
- display: block;
42
- text-align: center;
43
- background: #039be5;
44
- text-transform: uppercase;
45
- text-decoration: none;
46
- color: white;
47
- padding: 16px;
48
- border-radius: 4px;
49
- }
50
- #message,
51
- #message a {
52
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
53
- }
54
- #load {
55
- color: rgba(0, 0, 0, 0.4);
56
- text-align: center;
57
- font-size: 13px;
58
- }
59
- @media (max-width: 600px) {
60
- body,
61
- #message {
62
- margin-top: 0;
63
- background: white;
64
- box-shadow: none;
65
- }
66
- body {
67
- border-top: 16px solid #f44336;
68
- }
69
- }
70
- code {
71
- background: #37474f;
72
- color: white;
73
- border-radius: 2px;
74
- padding: 2px 4px;
75
- font-size: 12px;
76
- margin: 0 4px;
77
- }
78
- </style>
79
- </head>
80
- <body>
81
- <div id="message">
82
- <h2>失败!</h2>
83
- <h1>CloudBase CLI 登录失败</h1>
84
- <p>
85
- CloudBase CLI 登录失败,请检验终端网络是否联通,然后使用
86
- <code>cloudbase login</code> 再次登录 。
87
- </p>
88
- </div>
89
- </body>
90
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>CloudBase CLI</title>
7
+
8
+ <style media="screen">
9
+ body {
10
+ background: #eceff1;
11
+ color: rgba(0, 0, 0, 0.87);
12
+ font-family: Roboto, Helvetica, Arial, sans-serif;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+ #message {
17
+ background: white;
18
+ max-width: 360px;
19
+ margin: 100px auto 16px;
20
+ padding: 32px 24px 8px;
21
+ border-radius: 3px;
22
+ }
23
+ #message h2 {
24
+ color: #f44336;
25
+ font-weight: bold;
26
+ font-size: 16px;
27
+ margin: 0 0 8px;
28
+ }
29
+ #message h1 {
30
+ font-size: 22px;
31
+ font-weight: 300;
32
+ color: rgba(0, 0, 0, 0.6);
33
+ margin: 0 0 16px;
34
+ }
35
+ #message p {
36
+ line-height: 140%;
37
+ margin: 16px 0 24px;
38
+ font-size: 14px;
39
+ }
40
+ #message a {
41
+ display: block;
42
+ text-align: center;
43
+ background: #039be5;
44
+ text-transform: uppercase;
45
+ text-decoration: none;
46
+ color: white;
47
+ padding: 16px;
48
+ border-radius: 4px;
49
+ }
50
+ #message,
51
+ #message a {
52
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
53
+ }
54
+ #load {
55
+ color: rgba(0, 0, 0, 0.4);
56
+ text-align: center;
57
+ font-size: 13px;
58
+ }
59
+ @media (max-width: 600px) {
60
+ body,
61
+ #message {
62
+ margin-top: 0;
63
+ background: white;
64
+ box-shadow: none;
65
+ }
66
+ body {
67
+ border-top: 16px solid #f44336;
68
+ }
69
+ }
70
+ code {
71
+ background: #37474f;
72
+ color: white;
73
+ border-radius: 2px;
74
+ padding: 2px 4px;
75
+ font-size: 12px;
76
+ margin: 0 4px;
77
+ }
78
+ </style>
79
+ </head>
80
+ <body>
81
+ <div id="message">
82
+ <h2>失败!</h2>
83
+ <h1>CloudBase CLI 登录失败</h1>
84
+ <p>
85
+ CloudBase CLI 登录失败,请检验终端网络是否联通,然后使用
86
+ <code>cloudbase login</code> 再次登录 。
87
+ </p>
88
+ </div>
89
+ </body>
90
+ </html>