Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chhpt committed Dec 9, 2019
2 parents 3d543fd + 5d4551d commit e363b8f
Show file tree
Hide file tree
Showing 66 changed files with 1,763 additions and 322 deletions.
14 changes: 5 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
"prettier",
"prettier/@typescript-eslint"
],
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"no-console": "off",
"no-unused-vars": "error",
"semi": [
"error",
"never"
],
"semi": ["error", "never"],
"quotes": [
"error",
"single",
Expand All @@ -24,7 +19,8 @@
],
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/interface-name-prefix": "off"
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"env": {
"es6": true,
Expand All @@ -40,4 +36,4 @@
}
}
]
}
}
26 changes: 25 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
module.exports = {
// 一行最多 100 字符
printWidth: 100,
// 使用 4 个空格缩进
tabWidth: 4,
// 不使用缩进符,而使用空格
useTabs: false,
// 行尾无分号
semi: false,
singleQuote: true
// 使用单引号
singleQuote: true,
// 对象的 key 仅在必要时用引号
quoteProps: 'as-needed',
// 末尾不需要逗号
trailingComma: 'none',
// 大括号内的首尾需要空格
bracketSpacing: true,
// 每个文件格式化的范围是文件的全部内容
rangeStart: 0,
rangeEnd: Infinity,
// 不需要写文件开头的 @prettier
requirePragma: false,
// 不需要自动在文件开头插入 @prettier
insertPragma: false,
// 使用默认的折行标准
proseWrap: 'preserve',
// 换行符使用 lf
endOfLine: 'lf'
}
53 changes: 44 additions & 9 deletions bin/cloudbase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const os = require('os')
const path = require('path')
const chalk = require('chalk')
const Sentry = require('@sentry/node')
const program = require('commander')
Expand All @@ -8,6 +9,7 @@ const updateNotifier = require('update-notifier')
const address = require('address')
const pkg = require('../package.json')

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

const userNodeVersion = Number(
Expand Down Expand Up @@ -52,6 +54,41 @@ notifier.notify({
isGlobal: true
})

// 测试模式
if (processArgv.includes('--deb')) {
console.log(
chalk.bold.yellow('====\n您已经进入 debug 模式!\n移除 --deb 选项退出 debug 模式!\n====')
)
}

if (processArgv.includes('--tcb-test')) {
console.log(
chalk.bold.yellow(
'====\n您已经进入 test 模式!\n移除 --tcb-test 选项退出 test 模式!\n===='
)
)
try {
const envs = require(path.join(process.cwd(), './tcb-test.js'))
for (const key in envs) {
process.env[key] = envs[key]
}
} catch (err) {
console.log(err)
}
}

// debug 模式
process.IS_DEBUG = processArgv.includes('--deb')

// 需要隐藏的选项
const hideArgs = ['--deb', '--tcb-test']
hideArgs.forEach(arg => {
const index = processArgv.indexOf(arg)
if (index > -1) {
processArgv.splice(index, 1)
}
})

// 注册命令
require('../lib')

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

// 设置 options 选项
program.option(
'--config-file <path>',
'设置配置文件,默认为 ./cloudbaserc.js 或 .cloudbaserc.json'
)
program.option('--debug', 'open debug mode')
program.option('--config-file <path>', '设置配置文件,默认为 ./cloudbaserc.js 或 .cloudbaserc.json')

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

Expand All @@ -100,7 +133,11 @@ ${chalk.gray('–')} 初始化云开发项目
${chalk.gray('–')} 部署云函数
${chalk.cyan('$ cloudbase functions:deploy')}`
${chalk.cyan('$ cloudbase functions:deploy')}
${chalk.gray('–')} 查看命令使用介绍
${chalk.cyan('$ cloudbase functions:log -h')}`
console.log(tips)
})

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

program.parse(process.argv)

process.IS_DEBUG = program.debug
program.parse(processArgv)

function errorHandler(err) {
const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']
Expand Down
20 changes: 0 additions & 20 deletions lib/commands/functions/debug.js

This file was deleted.

59 changes: 49 additions & 10 deletions lib/commands/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const trigger_delete_1 = require("./trigger-delete");
const invoke_1 = require("./invoke");
const copy_1 = require("./copy");
const code_download_1 = require("./code-download");
const run_1 = require("./run");
function getFunctionContext(name, envId, configPath) {
return __awaiter(this, void 0, void 0, function* () {
const cloudBaseConfig = yield utils_1.resolveCloudBaseConfig(configPath);
Expand Down Expand Up @@ -121,16 +122,6 @@ const commands = [
yield detail_1.detail(ctx, options);
})
},
{
cmd: 'functions:invoke [functionName] [params] [envId]',
options: [],
desc: '触发云函数',
handler: (name, jsonStringParams, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
const { configFile } = options.parent;
const ctx = yield getFunctionContext(name, envId, configFile);
yield invoke_1.invoke(ctx, jsonStringParams);
})
},
{
cmd: 'functions:code:update <functionName> [envId]',
options: [
Expand Down Expand Up @@ -232,6 +223,54 @@ const commands = [
const ctx = yield getFunctionContext(functionName, envId, configFile);
yield trigger_delete_1.triggerDelete(ctx, triggerName);
})
},
{
cmd: 'functions:invoke [functionName] [params] [envId]',
options: [],
desc: '触发云端部署的云函数',
handler: (name, jsonStringParams, envId, options) => __awaiter(void 0, void 0, void 0, function* () {
const { configFile } = options.parent;
const ctx = yield getFunctionContext(name, envId, configFile);
yield invoke_1.invoke(ctx, jsonStringParams);
})
},
{
cmd: 'functions:run',
options: [
{
flags: '--path <path>',
desc: '云函数路径,使用默认配置直接调用云函数,无需配置文件'
},
{
flags: '--name <name>',
desc: '指定云函数的名称进行调用,需要配置文件'
},
{
flags: '--params <params>',
desc: '调用函数传入的参数,JSON 字符串格式'
},
{
flags: '--port <port>',
desc: '启动调试时监听的端口号,默认为 9229'
},
{
flags: '--debug',
desc: '启动调试模式'
}
],
desc: '本地运行云函数(当前仅支持 Node)',
handler: (options) => __awaiter(void 0, void 0, void 0, function* () {
const { path } = options;
if (path) {
yield run_1.debugFunctionByPath(path, options);
}
else {
const { name } = options;
const { configFile } = options.parent;
const ctx = yield getFunctionContext(name, '', configFile);
yield run_1.debugByConfig(ctx, options);
}
})
}
];
commands.forEach(item => {
Expand Down
Loading

0 comments on commit e363b8f

Please sign in to comment.