Skip to content

Commit 968b74b

Browse files
committed
feat: suppport cache bucket name in state
1 parent 9819887 commit 968b74b

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

__tests__/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const instanceYaml = {
2222
index: 'index.html',
2323
error: 'index.html'
2424
},
25-
bucketName: 'my-bucket',
25+
bucketName: 'website-integration-test',
2626
region: 'ap-guangzhou',
2727
}
2828
}

example/serverless.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
org: orgDemo
21
app: appDemo
32
stage: dev
4-
component: website
3+
4+
component: website@dev
55
name: websiteDemo
66

77
inputs:
@@ -10,5 +10,5 @@ inputs:
1010
index: index.html
1111
error: index.html
1212
region: ap-guangzhou
13-
bucketName: my-bucket
13+
bucketName: website-demo
1414
protocol: https

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: website
2-
version: 0.1.4
2+
version: 0.2.0
33
author: 'Tencent Cloud, Inc.'
44
org: 'Tencent Cloud, Inc.'
55
description: Deploy a static website on Tencent Cloud.

src/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"dependencies": {
33
"download": "^8.0.0",
4-
"tencent-component-toolkit": "^2.5.5",
5-
"type": "^2.1.0"
4+
"tencent-component-toolkit": "^2.5.5"
65
}
76
}

src/serverless.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class ServerlessComponent extends Component {
2222
}
2323
}
2424

25+
getAppId() {
26+
return this.credentials.tencent.tmpSecrets.appId
27+
}
28+
2529
getDefaultProtocol(protocols) {
2630
if (String(protocols).includes('https')) {
2731
return 'https'
@@ -87,6 +91,7 @@ class ServerlessComponent extends Component {
8791
}
8892
this.state = {
8993
region,
94+
bucket: websiteInputs.bucket,
9095
website: websiteInputs
9196
}
9297

src/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const removeAppid = (str, appid) => {
4141
}
4242

4343
const prepareInputs = async (instance, inputs) => {
44+
const { state } = instance
4445
let code = inputs.src || ''
4546
code =
4647
typeof code === 'string'
@@ -51,8 +52,8 @@ const prepareInputs = async (instance, inputs) => {
5152
...code
5253
}
5354

54-
const zipPath = await getCodeZipPath(this, code)
55-
const { appId } = instance.credentials.tencent.tmpSecrets
55+
const zipPath = await getCodeZipPath(instance, code)
56+
const appId = instance.getAppId()
5657
const envPath = (inputs.srcOriginal && inputs.srcOriginal.envPath) || './'
5758
let sourceDirectory = await instance.unzip(zipPath)
5859
if (!code.src) {
@@ -62,7 +63,7 @@ const prepareInputs = async (instance, inputs) => {
6263

6364
const region = inputs.region || CONFIGS.region
6465
const bucketName =
65-
removeAppid(inputs.bucketName, appId) || `sls-website-${region}-${generateId()}`
66+
removeAppid(inputs.bucketName || state.bucket, appId) || `sls-website-${region}-${generateId()}`
6667

6768
const websiteInputs = Object.assign(inputs, {
6869
replace: inputs.replace,

0 commit comments

Comments
 (0)