Skip to content

Commit 80e2890

Browse files
committed
feat: support custom entry file and all scf config
1 parent f40f3bd commit 80e2890

File tree

12 files changed

+210
-57
lines changed

12 files changed

+210
-57
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
env:
12+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
with:
17+
persist-credentials: false
18+
19+
- name: Install Node.js and npm
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 14.x
23+
registry-url: https://registry.npmjs.org
24+
25+
- name: Retrieve dependencies from cache
26+
id: cacheNpm
27+
uses: actions/cache@v2
28+
with:
29+
path: |
30+
~/.npm
31+
node_modules
32+
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
33+
restore-keys: npm-v14-${{ runner.os }}-refs/heads/master-
34+
35+
- name: Install dependencies
36+
if: steps.cacheNpm.outputs.cache-hit != 'true'
37+
run: |
38+
npm update --no-save
39+
npm update --save-dev --no-save
40+
- name: Releasing
41+
run: |
42+
npm run release
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
45+
GIT_AUTHOR_NAME: slsplus
46+
GIT_AUTHOR_EMAIL: yuga.sun.bj@gmail.com
47+
GIT_COMMITTER_NAME: slsplus
48+
GIT_COMMITTER_EMAIL: yuga.sun.bj@gmail.com

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
- name: Running integration tests
42+
run: npm run test
43+
env:
44+
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
45+
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

.github/workflows/validate.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Validate
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
lintAndFormatting:
9+
name: Lint & Formatting
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
42+
- name: Validate Formatting
43+
run: npm run prettier:fix
44+
- name: Validate Lint rules
45+
run: npm run lint:fix

.travis.yml

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

docs/configure.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ inputs:
1717
serviceName: mytest # api网关服务名称
1818
runtime: Nodejs10.15 # 运行环境
1919
serviceId: service-np1uloxw # api网关服务ID
20+
entryFile: sls.js # 自定义 server 的入口文件名,默认为 sls.js,如果不想修改文件名为 sls.js 可以自定义
2021
src: ./src # 第一种为string时,会打包src对应目录下的代码上传到默认cos上。
2122
# src: # 第二种,部署src下的文件代码,并打包成zip上传到bucket上
2223
# src: ./src # 本地需要打包的文件目录
@@ -75,19 +76,20 @@ inputs:
7576
7677
主要的参数
7778
78-
| 参数名称 | 是否必选 | 默认值 | 描述 |
79-
| ------------------------------------ | :------: | :-------------: | :------------------------------------------------------------------ |
80-
| runtime | 否 | `Nodejs10.15` | 执行环境, 目前支持: Nodejs6.10, Nodejs8.9, Nodejs10.15, Nodejs12.16 |
81-
| region | 否 | `ap-guangzhou` | 项目部署所在区域,默认广州区 |
82-
| functionName | 否 | | 云函数名称 |
83-
| serviceName | 否 | | API 网关服务名称, 默认创建一个新的服务名称 |
84-
| serviceId | 否 | | API 网关服务 ID,如果存在将使用这个 API 网关服务 |
85-
| src | 否 | `process.cwd()` | 默认为当前目录, 如果是对象, 配置参数参考 [执行目录](#执行目录) |
86-
| layers | 否 | | 云函数绑定的 layer, 配置参数参考 [层配置](#层配置) |
87-
| [functionConf](#函数配置) | 否 | | 函数配置 |
88-
| [apigatewayConf](#API-网关配置) | 否 | | API 网关配置 |
89-
| [cloudDNSConf](#DNS-配置) | 否 | | DNS 配置 |
90-
| [Region special config](#指定区配置) | 否 | | 指定区配置 |
79+
| 参数名称 | 必选 | 默认值 | 描述 |
80+
| ------------------------------------ | :--: | :-------------: | :------------------------------------------------------------------ |
81+
| runtime | 否 | `Nodejs10.15` | 执行环境, 目前支持: Nodejs6.10, Nodejs8.9, Nodejs10.15, Nodejs12.16 |
82+
| region | 否 | `ap-guangzhou` | 项目部署所在区域,默认广州区 |
83+
| functionName | 否 | | 云函数名称 |
84+
| serviceName | 否 | | API 网关服务名称, 默认创建一个新的服务名称 |
85+
| serviceId | 否 | | API 网关服务 ID,如果存在将使用这个 API 网关服务 |
86+
| entryFile | 否 | `sls.js` | 自定义 server 的入口文件名 |
87+
| src | 否 | `process.cwd()` | 默认为当前目录, 如果是对象, 配置参数参考 [执行目录](#执行目录) |
88+
| layers | 否 | | 云函数绑定的 layer, 配置参数参考 [层配置](#层配置) |
89+
| [functionConf](#函数配置) | 否 | | 函数配置 |
90+
| [apigatewayConf](#API-网关配置) | 否 | | API 网关配置 |
91+
| [cloudDNSConf](#DNS-配置) | 否 | | DNS 配置 |
92+
| [Region special config](#指定区配置) | 否 | | 指定区配置 |
9193

9294
## 执行目录
9395

package.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"access": "public"
66
},
77
"scripts": {
8-
"int-test": "jest ./tests/integration.test.js --testEnvironment node",
9-
"test": "npm run lint && npm run prettier && npm run int-test",
8+
"test": "jest ./tests/integration.test.js --testEnvironment node",
109
"commitlint": "commitlint -f HEAD@{15}",
1110
"lint": "eslint --ext .js,.ts,.tsx .",
1211
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
@@ -58,5 +57,27 @@
5857
"lint-staged": "^10.0.8",
5958
"prettier": "^1.19.1",
6059
"semantic-release": "^17.0.4"
61-
}
60+
},
61+
"description": "Easily deploy serverless Express.js applications to Tencent Cloud with the Serverless Framework",
62+
"directories": {
63+
"doc": "docs",
64+
"example": "example",
65+
"test": "tests"
66+
},
67+
"repository": {
68+
"type": "git",
69+
"url": "git+https://github.com/serverless-components/tencent-express.git"
70+
},
71+
"keywords": [
72+
"serverless-express",
73+
"serverless",
74+
"express",
75+
"serverless-framework",
76+
"serverless-components",
77+
"tencent-cloud"
78+
],
79+
"bugs": {
80+
"url": "https://github.com/serverless-components/tencent-express/issues"
81+
},
82+
"homepage": "https://github.com/serverless-components/tencent-express#readme"
6283
}

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: express
2-
version: 0.1.5
2+
version: 0.2.0
33
author: Tencent Cloud, Inc.
44
org: Tencent Cloud, Inc.
55
description: Deploy a serverless Express.js application on Tencent SCF and API Gateway.

src/_shims/handler.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const path = require('path')
44
const { createServer, proxy } = require('tencent-serverless-http')
55

66
let server
7+
let app
78

89
exports.handler = async (event, context) => {
9-
const userSls = path.join(__dirname, '..', 'sls.js')
10-
let app
10+
const userSls = path.join(__dirname, '..', process.env.SLS_ENTRY_FILE)
1111
if (fs.existsSync(userSls)) {
12-
// load the user provided app
12+
// eslint-disable-next-line
13+
console.log(`Using user custom entry file ${process.env.SLS_ENTRY_FILE}`)
1314
app = require(userSls)
1415
} else {
15-
// load the built-in default app
1616
app = require('./sls.js')
1717
}
1818

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const CONFIGS = {
33
'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/express-demo.zip',
44
compName: 'express',
55
compFullname: 'Express.js',
6+
defaultEntryFile: 'sls.js',
67
handler: 'sl_handler.handler',
78
runtime: 'Nodejs10.15',
89
timeout: 3,

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"download": "^8.0.0",
4-
"tencent-component-toolkit": "^1.16.4",
4+
"tencent-component-toolkit": "^1.17.0",
55
"type": "^2.0.0"
66
}
77
}

0 commit comments

Comments
 (0)