Skip to content

Commit 35df162

Browse files
committed
feat: enable no input for website create
1 parent 4ebd911 commit 35df162

File tree

6 files changed

+22
-29
lines changed

6 files changed

+22
-29
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"commitlint": "commitlint -f HEAD@{15}",
1212
"lint": "eslint --ext .js,.ts,.tsx .",
1313
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
14-
"prettier": "prettier --check **/*.{css,html,js,json,md,yaml,yml}",
15-
"prettier:fix": "prettier --write **/*.{css,html,js,json,md,yaml,yml}",
14+
"prettier": "prettier --check '**/*.{css,html,js,json,md,yaml,yml}'",
15+
"prettier:fix": "prettier --write '**/*.{css,html,js,json,md,yaml,yml}'",
1616
"release": "semantic-release",
1717
"release-local": "node -r dotenv/config node_modules/semantic-release/bin/semantic-release --no-ci --dry-run",
1818
"check-dependencies": "npx npm-check --skip-unused --update"

serverless.component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ author: Tencent Cloud, Inc.
44
org: Tencent Cloud, Inc.
55
description: Deploys Tencent Website.
66
keywords: tencent, serverless, website
7-
repo: https://github.com/serverless-components/tencent-website/tree/v2
8-
readme: https://github.com/serverless-components/tencent-website/tree/v2/README.md
7+
repo: https://github.com/serverless-components/tencent-website
8+
readme: https://github.com/serverless-components/tencent-website/tree/master/README.md
99
license: MIT
1010
main: ./src
1111
webDeployable: true

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const CONFIGS = {
22
templateUrl:
33
'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/website-demo.zip',
44
region: 'ap-guangzhou',
5+
compName: 'website',
6+
compFullname: 'Website',
57
indexPage: 'index.html',
68
errorPage: 'error.html',
79
protocol: 'http',

src/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{
2-
"name": "@serverless/website",
3-
"main": "./serverless.js",
4-
"publishConfig": {
5-
"access": "public"
6-
},
72
"dependencies": {
83
"download": "^8.0.0",
9-
"tencent-component-toolkit": "^1.11.4",
4+
"tencent-component-toolkit": "^1.12.10",
105
"type": "^2.0.0"
116
}
127
}

src/serverless.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ServerlessComponent extends Component {
7373
}
7474

7575
async deploy(inputs) {
76-
console.log(`Deploying Tencent Website ...`)
76+
console.log(`Deploying Tencent ${CONFIGS.compFullname}`)
7777

7878
const credentials = this.getCredentials()
7979

@@ -85,26 +85,21 @@ class ServerlessComponent extends Component {
8585
const output = {
8686
region
8787
}
88+
this.state = {
89+
region,
90+
website: websiteInputs
91+
}
8892

8993
if (websiteInputs.useDefault) {
9094
output.templateUrl = CONFIGS.templateUrl
9195
}
9296

9397
inputs.srcOriginal = inputs.srcOriginal || {}
9498

95-
// 创建cos对象
9699
const cos = new Cos(credentials, region)
97-
98-
console.log(`Deploying Website ...`)
99-
100-
// 部署网站
101100
const websiteUrl = await cos.website(websiteInputs)
102101

103102
output.website = this.getDefaultProtocol(websiteInputs.protocol) + '://' + websiteUrl
104-
this.state = {
105-
region,
106-
website: websiteInputs
107-
}
108103

109104
const cosOriginAdd = `${websiteInputs.bucket}.cos-website.${websiteInputs.region}.myqcloud.com`
110105
if (inputs.hosts && inputs.hosts.length > 0) {
@@ -115,30 +110,29 @@ class ServerlessComponent extends Component {
115110
originPullProtocol: websiteInputs.protocol
116111
})
117112

118-
output.cdnDomains = deployCdnRes.cdnResult
119113
this.state.cdn = deployCdnRes.outputs
114+
output.cdnDomains = deployCdnRes.cdnResult
120115
}
121116

122117
await this.save()
123-
console.log(`Deployed Tencent Website.`)
118+
console.log(`Deployed Tencent ${CONFIGS.compFullname} success`)
124119

125120
return output
126121
}
127122

128123
// eslint-disable-next-line
129124
async remove(inputs = {}) {
130-
console.log(`Removing Webiste ...`)
125+
console.log(`Removing ${CONFIGS.compFullname}`)
131126

132127
const credentials = this.getCredentials()
133128

134129
// 默认值
135130
const { region } = this.state
136-
const stateCdn = this.state.cdn
137131

138-
// 创建cos对象
139132
const cos = new Cos(credentials, region)
140133
await cos.remove(this.state.website)
141134

135+
const stateCdn = this.state.cdn
142136
if (stateCdn) {
143137
const cdn = new Cdn(credentials, region)
144138
for (let i = 0; i < stateCdn.length; i++) {
@@ -150,7 +144,7 @@ class ServerlessComponent extends Component {
150144
}
151145

152146
this.state = {}
153-
console.log(`Removed Website`)
147+
console.log(`Removed ${CONFIGS.compFullname}`)
154148
}
155149
}
156150

src/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const prepareInputs = async (instance, inputs) => {
5353
}
5454
console.log(`Files unzipped into ${sourceDirectory}...`)
5555

56+
const region = inputs.region || CONFIGS.region
57+
5658
return {
5759
useDefault: !code.src,
5860
code: {
@@ -62,9 +64,9 @@ const prepareInputs = async (instance, inputs) => {
6264
envPath: path.join(sourceDirectory, envPath)
6365
},
6466
env: inputs.env,
65-
bucket: `${inputs.bucketName}-${appId}`,
66-
region: inputs.region || CONFIGS.region,
67-
protocol: inputs.protocol || CONFIGS.protocolc,
67+
bucket: `${inputs.bucketName || `sls-website-${region}-${generateId()}`}-${appId}`,
68+
region: region,
69+
protocol: inputs.protocol || CONFIGS.protocol,
6870
cors: inputs.cors
6971
}
7072
}

0 commit comments

Comments
 (0)