-
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): impl website command (#854)
* feat: impl website command
- Loading branch information
Showing
6 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { websiteControllerBindDomain, websiteControllerCreate, websiteControllerFindAll, websiteControllerRemove } from "../../api/v1/websitehosting" | ||
import { readApplicationConfig } from "../../config/application" | ||
import * as Table from 'cli-table3' | ||
import { formatDate } from "../../util/format" | ||
import { BindCustomDomainDto, CreateWebsiteDto } from "../../api/v1/data-contracts" | ||
import { getEmoji } from "../../util/print" | ||
|
||
|
||
export async function list() { | ||
const appConfig = readApplicationConfig() | ||
const websites = await websiteControllerFindAll(appConfig.appid) | ||
const table = new Table({ | ||
head: ['bucketName', 'domain', 'state', 'updatedAt'], | ||
}) | ||
for (let item of websites) { | ||
table.push([item.bucketName, item.domain, item.state, formatDate(item.updatedAt),]) | ||
} | ||
console.log(table.toString()) | ||
} | ||
|
||
export async function create(bucketName: string, options: any) { | ||
const appConfig = readApplicationConfig() | ||
|
||
if (!bucketName.startsWith(appConfig.appid + '-')) { | ||
bucketName = appConfig.appid + '-' + bucketName | ||
} | ||
|
||
const createDto: CreateWebsiteDto = { | ||
bucketName, | ||
state: 'Active', | ||
} | ||
const website = await websiteControllerCreate(appConfig.appid, createDto) | ||
|
||
if (options) { } | ||
|
||
console.log(`${getEmoji('✅')} create website success!`) | ||
console.log(`You can access through this domain: ${website.domain}`) | ||
} | ||
|
||
export async function del(bucketName: string, options: any) { | ||
const appConfig = readApplicationConfig() | ||
const websites = await websiteControllerFindAll(appConfig.appid) | ||
|
||
if (options) { | ||
} | ||
|
||
if (!bucketName.startsWith(appConfig.appid + '-')) { | ||
bucketName = appConfig.appid + '-' + bucketName | ||
} | ||
|
||
const targetId = websites.find((item) => item.bucketName === bucketName)?.id | ||
if (!targetId) { | ||
console.log(`${getEmoji('❌')} website ${bucketName} not found`) | ||
return | ||
} | ||
await websiteControllerRemove(appConfig.appid, targetId) | ||
|
||
console.log(`${getEmoji('✅')} delete website success!`) | ||
} | ||
|
||
export async function custom(bucketName: string, domain: string, options: any) { | ||
const appConfig = readApplicationConfig() | ||
const websites = await websiteControllerFindAll(appConfig.appid) | ||
|
||
if (options) { | ||
} | ||
|
||
if (!bucketName.startsWith(appConfig.appid + '-')) { | ||
bucketName = appConfig.appid + '-' + bucketName | ||
} | ||
|
||
const targetId = websites.find((item) => item.bucketName === bucketName)?.id | ||
if (!targetId) { | ||
console.log(`${getEmoji('❌')} website ${bucketName} not found`) | ||
return | ||
} | ||
|
||
const patchDto: BindCustomDomainDto = { | ||
domain, | ||
} | ||
const website = await websiteControllerBindDomain(appConfig.appid, targetId, patchDto) | ||
|
||
console.log(`${getEmoji('✅')} bind custom success!`) | ||
console.log(`You can access through this domain: ${website.domain}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Command, program } from 'commander' | ||
import { create, custom, del, list } from '../../action/website' | ||
import { checkApplication } from '../../common/hook' | ||
|
||
|
||
export function command(): Command { | ||
const cmd = program.command('website').hook('preAction', () => { | ||
checkApplication() | ||
}) | ||
|
||
cmd | ||
.command('list') | ||
.description('website list') | ||
.action(() => { | ||
list() | ||
}) | ||
|
||
cmd | ||
.command('create <bucketName>') | ||
.description('create a website') | ||
.action((bucketName, options) => { | ||
create(bucketName, options) | ||
}) | ||
|
||
|
||
cmd | ||
.command('del <bucketName>') | ||
.description('del website') | ||
.action((bucketName, options) => { | ||
del(bucketName, options) | ||
}) | ||
|
||
cmd | ||
.command('custom <bucketName> <domain>') | ||
.description('custom website domain') | ||
.action((bucketName, domain, options) => { | ||
custom(bucketName, domain, options) | ||
}) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters