Skip to content

Commit ca634a6

Browse files
authored
feat(cli): add website deploy (#1190)
1 parent 39345bb commit ca634a6

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

cli/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@types/mime": "^2.0.3",
30-
"@types/node": "^17.0.31"
30+
"@types/node": "^17.0.45"
3131
},
3232
"dependencies": {
3333
"@aws-sdk/client-s3": "^3.45.0",

cli/src/action/deploy/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { AppSchema } from '../../schema/app'
33
import { DeploySchema } from '../../schema/deploy'
44
import { pushAll as pushAllFunctions } from '../function'
55
import { create as createBucket, push as pushBucket } from '../storage'
6+
import { create as createWebsite } from '../website'
67
import { push as pushDependency } from '../dependency'
78
import { pullAll as pullAllPolicies } from '../policy'
89
import { getEmoji } from '../../util/print'
10+
import { websiteControllerFindAll } from '../../api/v1/websitehosting'
911

1012
export async function deploy() {
1113
if (!DeploySchema.exist()) {
@@ -37,7 +39,23 @@ export async function deploy() {
3739
if (!bucketMap.has(bucket.name)) {
3840
await createBucket(bucket.name, { policy: bucket.policy })
3941
} else {
40-
console.log(`${bucket.name} already exist, skip`)
42+
console.log(`bucket ${bucket.name} already exist, skip`)
43+
}
44+
}
45+
}
46+
47+
if (deploySchema?.resources?.websites) {
48+
const websites = await websiteControllerFindAll(appSchema.appid)
49+
const websiteMap = new Map<string, boolean>()
50+
websites.forEach((website) => {
51+
websiteMap.set(website.bucketName, true)
52+
})
53+
54+
for (let website of deploySchema?.resources?.websites) {
55+
if (!websiteMap.has(website.bucketName) && !websiteMap.has(appSchema.appid + '-' + website.bucketName)) {
56+
await createWebsite(website.bucketName, {})
57+
} else {
58+
console.log(`website:${website.bucketName} already exist, skip`)
4159
}
4260
}
4361
}
@@ -48,5 +66,6 @@ export async function deploy() {
4866
await pushBucket(bucket.bucketName, bucket.srcDir, { force: true, detail: false })
4967
}
5068
}
69+
5170
console.log(`${getEmoji('🚀')} deploy success`)
5271
}

cli/src/schema/deploy.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { DEPLOY_SCHEMA_NAME } from '../common/constant'
22
import { exist, loadYamlFile } from '../util/file'
33
import { getAppPath } from '../util/sys'
4-
import path = require('path')
4+
import * as path from 'node:path'
55

66
export class DeploySchema {
77
name: string
88

99
resources?: {
1010
buckets?: BucketResource[]
11+
websites?: WebsiteResource[]
1112
}
1213

1314
actions?: {
@@ -30,6 +31,11 @@ export class BucketResource {
3031
policy: 'private' | 'readonly' | 'readwrite'
3132
}
3233

34+
export class WebsiteResource {
35+
name: string
36+
bucketName: string
37+
}
38+
3339
export class BucketAction {
3440
name: string
3541
bucketName: string

0 commit comments

Comments
 (0)