Skip to content

Commit

Permalink
feat: support remote manifest config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizhenpeng committed Jan 15, 2024
1 parent bd40ed6 commit b47b739
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
"listr": "^0.14.3",
"node-fetch": "^3.3.2",
"onebot-feishu": "workspace:^",
"ora": "^8.0.1",
"picocolors": "^1.0.0",
Expand Down
9 changes: 3 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function builder(yargs: Argv) {
}

export async function handler(argv: any) {
// 如果没有接收到参数,就询问是否从剪切板读取
// 如果没有接收到参数,默认读取同级目录下的 one-bot.json 文件
if (argv._.length === 1) {
const answer = await confirm({
message: 'read the deployment configuration file from the clipboard ?',
Expand Down
27 changes: 24 additions & 3 deletions src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Ajv from 'ajv'
import fs from 'fs-extra'
import fetch from 'node-fetch'

export interface FeishuPlatformConfig {
appId?: string
Expand Down Expand Up @@ -106,7 +107,14 @@ export class DeployConfig {
return path.startsWith('http')
}

async loadFile(path: string): Promise<string> {
async loadFileByPath(path: string) {
if (this.isUrl(path))
return this.remoteLoadFile(path)
else
return this.loadLocalFile(path)
}

async loadLocalFile(path: string): Promise<string> {
if (!await this.isFileExist(path))
throw new Error('the file is not exist')

Expand All @@ -118,17 +126,30 @@ export class DeployConfig {
})
}

// http://127.0.0.1:8080/mock.config.json
async remoteLoadFile(url: string): Promise<string> {
try {
const response = await fetch(url)
const jsonData = await response.text() as string
return jsonData
}
catch (error: any) {
console.error(`Error making request to ${url}: ${error.message}`)
throw error
}
}

// 检验配置文件的schema是否符合
async validateConfigByPath(path: string) {
if (!this.isJson(path))
return false

const config = await this.loadFile(path)
const config = await this.loadFileByPath(path)
return this.validateConfig(JSON.parse(config))
}

async loadConfig(path: string) {
const config = await this.loadFile(path)
const config = await this.loadFileByPath(path)
this.config = JSON.parse(config)
}

Expand Down

0 comments on commit b47b739

Please sign in to comment.