Skip to content

Commit

Permalink
chore: update ts-multiple-functions directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
butonly committed Jan 16, 2025
1 parent 219f673 commit d470776
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 16 deletions.
16 changes: 16 additions & 0 deletions cloudrunfunctions/ts-multiple-functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@
如何调试代码可参考:<https://docs.cloudbase.net/cbrf/how-to-debug-functions-code#%E8%B0%83%E8%AF%95-typescript-%E4%BB%A3%E7%A0%81>

JavaScript 示例代码见:<https://github.com/TencentCloudBase/func-v2-template>

## 项目结构说明

```tree
.
├── README.md # 项目说明
├── cloudrunfunctions # 云函数2.0项目代码目录,每个目录对应一个函数
│ ├── README.md # 云函数说明
│ ├── func-a # 云函数 `func-a` 代码目录
│ └── func-b # 云函数 `func-b` 代码目录
├── node_modules # node_modules [可能有]
├── package.json # package.json [可能有]
├── tsconfig.json # tsconfig.json [可能有]
```

以上,为一个简单项目结构示例,项目中还可能包含很多其他类型的文件,其他文件的组织根据项目需要进行即可
15 changes: 0 additions & 15 deletions cloudrunfunctions/ts-multiple-functions/cloudbase-functions.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# cloudrunfunctions 云函数2.0

该目录下包含两个函数:

* `func-a`:一个简单的单实例多函数示例。
* `func-b`:一个简单的函数示例。

每个函数对应一个 `云函数2.0` 服务,上传云函数时,需要上传对应函数的整个目录。

可根据需要,创建新的函数目录,或者删除现有的函数目录。

## 如何运行?

安装 `tcb-ff` 工具:

```sh
npm install -g @cloudbase/functions-framework
```

进入函数代码目录,`func-a``func-b` 或 其他,执行以下命令:

```sh
tcb-ff
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# func-a 示例函数

一个简单的单实例多函数示例
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"functionsRoot": "built",
"functions": [
{
"name": "func-a-1",
"directory": "func-a-1",
"triggerPath": "/a-1"
},
{
"name": "func-a-2",
"directory": "func-a-2",
"triggerPath": "/a-2"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "func-a",
"version": "1.0.0",
"description": "",
"main": "built/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@cloudbase/functions-typings": "^1.0.0-beta.4"
},
"devDependencies": {
"@types/node": "^22.10.7",
"ts-node": "^10.9.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TcbEventFunction } from '@cloudbase/functions-typings'

// GET no boyd
export const main: TcbEventFunction = function(event, context) {
console.log('hello a-1')
return 'a-1'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TcbEventFunction } from '@cloudbase/functions-typings'

// GET no boyd
export const main: TcbEventFunction = function(event, context) {
console.log('hello a-2')
return 'a-2'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*.ts"
],
"compilerOptions": {
"outDir": "built", /* Specify an output folder for all emitted files. */
"module": "ES2022", /* Specify what module code is generated. */
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# func-b 示例函数

一个简单的函数示例
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "func-b",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "built/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*.ts"
],
"compilerOptions": {
"outDir": "built", /* Specify an output folder for all emitted files. */
"module": "ES2022", /* Specify what module code is generated. */
}
}
3 changes: 2 additions & 1 deletion cloudrunfunctions/ts-multiple-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"ts-node": "^10.9.2"
},
"dependencies": {
"@cloudbase/functions-typings": "1.0.0-beta.4"
"@cloudbase/functions-typings": "1.0.0-beta.4",
"@types/node": "^22.10.7"
}
}

0 comments on commit d470776

Please sign in to comment.