mirror of
https://github.com/iflytek/skillhub.git
synced 2026-11-15 09:11:18 +00:00
Some checks are pending
Deploy Docs / build (push) Waiting to run
Deploy Docs / Deploy (push) Blocked by required conditions
Security / Dependency Review (push) Waiting to run
Security / CodeQL (java-kotlin) (push) Waiting to run
Security / CodeQL (javascript-typescript) (push) Waiting to run
Security / CodeQL (python) (push) Waiting to run
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
31 lines
901 B
TypeScript
31 lines
901 B
TypeScript
import { readFile, writeFile } from 'node:fs/promises'
|
|
import { dirname } from 'node:path'
|
|
import { joinPath, userStateDir, ensureDir, pathExists } from '../platform/paths'
|
|
|
|
export interface CliConfig extends Record<string, unknown> {
|
|
registry?: string
|
|
defaultAgent?: string
|
|
lastUpdateCheckAt?: string
|
|
}
|
|
|
|
export class ConfigStore {
|
|
readonly path: string
|
|
|
|
constructor(home?: string) {
|
|
this.path = joinPath(userStateDir(home), 'config.json')
|
|
}
|
|
|
|
async read(): Promise<CliConfig> {
|
|
if (!(await pathExists(this.path))) return {}
|
|
return JSON.parse(await readFile(this.path, 'utf-8')) as CliConfig
|
|
}
|
|
|
|
async write(config: CliConfig): Promise<void> {
|
|
await ensureDir(dirname(this.path))
|
|
await writeFile(this.path, JSON.stringify(config, null, 2))
|
|
}
|
|
|
|
async setRegistry(registry: string): Promise<void> {
|
|
await this.write({ ...(await this.read()), registry })
|
|
}
|
|
}
|