Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit e363b8f

Browse files
committed
fix merge conflict
2 parents 3d543fd + 5d4551d commit e363b8f

66 files changed

Lines changed: 1763 additions & 322 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
"prettier",
66
"prettier/@typescript-eslint"
77
],
8-
"plugins": [
9-
"@typescript-eslint"
10-
],
8+
"plugins": ["@typescript-eslint"],
119
"rules": {
1210
"no-console": "off",
1311
"no-unused-vars": "error",
14-
"semi": [
15-
"error",
16-
"never"
17-
],
12+
"semi": ["error", "never"],
1813
"quotes": [
1914
"error",
2015
"single",
@@ -24,7 +19,8 @@
2419
],
2520
"@typescript-eslint/explicit-member-accessibility": "off",
2621
"@typescript-eslint/explicit-function-return-type": "off",
27-
"@typescript-eslint/interface-name-prefix": "off"
22+
"@typescript-eslint/interface-name-prefix": "off",
23+
"@typescript-eslint/no-explicit-any": "off"
2824
},
2925
"env": {
3026
"es6": true,
@@ -40,4 +36,4 @@
4036
}
4137
}
4238
]
43-
}
39+
}

.prettierrc.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
module.exports = {
2+
// 一行最多 100 字符
3+
printWidth: 100,
4+
// 使用 4 个空格缩进
25
tabWidth: 4,
6+
// 不使用缩进符,而使用空格
7+
useTabs: false,
8+
// 行尾无分号
39
semi: false,
4-
singleQuote: true
10+
// 使用单引号
11+
singleQuote: true,
12+
// 对象的 key 仅在必要时用引号
13+
quoteProps: 'as-needed',
14+
// 末尾不需要逗号
15+
trailingComma: 'none',
16+
// 大括号内的首尾需要空格
17+
bracketSpacing: true,
18+
// 每个文件格式化的范围是文件的全部内容
19+
rangeStart: 0,
20+
rangeEnd: Infinity,
21+
// 不需要写文件开头的 @prettier
22+
requirePragma: false,
23+
// 不需要自动在文件开头插入 @prettier
24+
insertPragma: false,
25+
// 使用默认的折行标准
26+
proseWrap: 'preserve',
27+
// 换行符使用 lf
28+
endOfLine: 'lf'
529
}

bin/cloudbase.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
const os = require('os')
3+
const path = require('path')
34
const chalk = require('chalk')
45
const Sentry = require('@sentry/node')
56
const program = require('commander')
@@ -8,6 +9,7 @@ const updateNotifier = require('update-notifier')
89
const address = require('address')
910
const pkg = require('../package.json')
1011

12+
let processArgv = process.argv
1113
const isBeta = pkg.version.indexOf('-') > -1
1214

1315
const userNodeVersion = Number(
@@ -52,6 +54,41 @@ notifier.notify({
5254
isGlobal: true
5355
})
5456

57+
// 测试模式
58+
if (processArgv.includes('--deb')) {
59+
console.log(
60+
chalk.bold.yellow('====\n您已经进入 debug 模式!\n移除 --deb 选项退出 debug 模式!\n====')
61+
)
62+
}
63+
64+
if (processArgv.includes('--tcb-test')) {
65+
console.log(
66+
chalk.bold.yellow(
67+
'====\n您已经进入 test 模式!\n移除 --tcb-test 选项退出 test 模式!\n===='
68+
)
69+
)
70+
try {
71+
const envs = require(path.join(process.cwd(), './tcb-test.js'))
72+
for (const key in envs) {
73+
process.env[key] = envs[key]
74+
}
75+
} catch (err) {
76+
console.log(err)
77+
}
78+
}
79+
80+
// debug 模式
81+
process.IS_DEBUG = processArgv.includes('--deb')
82+
83+
// 需要隐藏的选项
84+
const hideArgs = ['--deb', '--tcb-test']
85+
hideArgs.forEach(arg => {
86+
const index = processArgv.indexOf(arg)
87+
if (index > -1) {
88+
processArgv.splice(index, 1)
89+
}
90+
})
91+
5592
// 注册命令
5693
require('../lib')
5794

@@ -71,11 +108,7 @@ Sentry.configureScope(scope => {
71108
})
72109

73110
// 设置 options 选项
74-
program.option(
75-
'--config-file <path>',
76-
'设置配置文件,默认为 ./cloudbaserc.js 或 .cloudbaserc.json'
77-
)
78-
program.option('--debug', 'open debug mode')
111+
program.option('--config-file <path>', '设置配置文件,默认为 ./cloudbaserc.js 或 .cloudbaserc.json')
79112

80113
program.version(pkg.version, '-V, --version', '输出当前 CloudBase CLI 版本')
81114

@@ -100,7 +133,11 @@ ${chalk.gray('–')} 初始化云开发项目
100133
101134
${chalk.gray('–')} 部署云函数
102135
103-
${chalk.cyan('$ cloudbase functions:deploy')}`
136+
${chalk.cyan('$ cloudbase functions:deploy')}
137+
138+
${chalk.gray('–')} 查看命令使用介绍
139+
140+
${chalk.cyan('$ cloudbase functions:log -h')}`
104141
console.log(tips)
105142
})
106143

@@ -109,9 +146,7 @@ if (process.argv.length < 3) {
109146
program.outputHelp()
110147
}
111148

112-
program.parse(process.argv)
113-
114-
process.IS_DEBUG = program.debug
149+
program.parse(processArgv)
115150

116151
function errorHandler(err) {
117152
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']

lib/commands/functions/debug.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/commands/functions/index.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const trigger_delete_1 = require("./trigger-delete");
2727
const invoke_1 = require("./invoke");
2828
const copy_1 = require("./copy");
2929
const code_download_1 = require("./code-download");
30+
const run_1 = require("./run");
3031
function getFunctionContext(name, envId, configPath) {
3132
return __awaiter(this, void 0, void 0, function* () {
3233
const cloudBaseConfig = yield utils_1.resolveCloudBaseConfig(configPath);
@@ -121,16 +122,6 @@ const commands = [
121122
yield detail_1.detail(ctx, options);
122123
})
123124
},
124-
{
125-
cmd: 'functions:invoke [functionName] [params] [envId]',
126-
options: [],
127-
desc: '触发云函数',
128-
handler: (name, jsonStringParams, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
129-
const { configFile } = options.parent;
130-
const ctx = yield getFunctionContext(name, envId, configFile);
131-
yield invoke_1.invoke(ctx, jsonStringParams);
132-
})
133-
},
134125
{
135126
cmd: 'functions:code:update <functionName> [envId]',
136127
options: [
@@ -232,6 +223,54 @@ const commands = [
232223
const ctx = yield getFunctionContext(functionName, envId, configFile);
233224
yield trigger_delete_1.triggerDelete(ctx, triggerName);
234225
})
226+
},
227+
{
228+
cmd: 'functions:invoke [functionName] [params] [envId]',
229+
options: [],
230+
desc: '触发云端部署的云函数',
231+
handler: (name, jsonStringParams, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
232+
const { configFile } = options.parent;
233+
const ctx = yield getFunctionContext(name, envId, configFile);
234+
yield invoke_1.invoke(ctx, jsonStringParams);
235+
})
236+
},
237+
{
238+
cmd: 'functions:run',
239+
options: [
240+
{
241+
flags: '--path <path>',
242+
desc: '云函数路径,使用默认配置直接调用云函数,无需配置文件'
243+
},
244+
{
245+
flags: '--name <name>',
246+
desc: '指定云函数的名称进行调用,需要配置文件'
247+
},
248+
{
249+
flags: '--params <params>',
250+
desc: '调用函数传入的参数,JSON 字符串格式'
251+
},
252+
{
253+
flags: '--port <port>',
254+
desc: '启动调试时监听的端口号,默认为 9229'
255+
},
256+
{
257+
flags: '--debug',
258+
desc: '启动调试模式'
259+
}
260+
],
261+
desc: '本地运行云函数(当前仅支持 Node)',
262+
handler: (options) => __awaiter(void 0, void 0, void 0, function* () {
263+
const { path } = options;
264+
if (path) {
265+
yield run_1.debugFunctionByPath(path, options);
266+
}
267+
else {
268+
const { name } = options;
269+
const { configFile } = options.parent;
270+
const ctx = yield getFunctionContext(name, '', configFile);
271+
yield run_1.debugByConfig(ctx, options);
272+
}
273+
})
235274
}
236275
];
237276
commands.forEach(item => {

0 commit comments

Comments
 (0)