-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use async and optimize error handling
- Loading branch information
1 parent
2b62a2f
commit 2c5aa1a
Showing
23 changed files
with
812 additions
and
733 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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import { readFile, writeFile } from 'fs/promises' | ||
import { appConfigPath } from '../utils/dirs' | ||
import yaml from 'yaml' | ||
import fs from 'fs' | ||
|
||
export let appConfig: IAppConfig // config.yaml | ||
let appConfig: IAppConfig // config.yaml | ||
|
||
export function getAppConfig(force = false): IAppConfig { | ||
export async function getAppConfig(force = false): Promise<IAppConfig> { | ||
if (force || !appConfig) { | ||
appConfig = yaml.parse(fs.readFileSync(appConfigPath(), 'utf-8')) | ||
const data = await readFile(appConfigPath(), 'utf-8') | ||
appConfig = yaml.parse(data) | ||
} | ||
return appConfig | ||
} | ||
|
||
export function setAppConfig(patch: Partial<IAppConfig>): void { | ||
export async function patchAppConfig(patch: Partial<IAppConfig>): Promise<void> { | ||
if (patch.sysProxy) { | ||
const oldSysProxy = appConfig.sysProxy || {} | ||
const newSysProxy = Object.assign(oldSysProxy, patch.sysProxy) | ||
patch.sysProxy = newSysProxy | ||
} | ||
appConfig = Object.assign(appConfig, patch) | ||
fs.writeFileSync(appConfigPath(), yaml.stringify(appConfig)) | ||
await writeFile(appConfigPath(), yaml.stringify(appConfig)) | ||
} |
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
Oops, something went wrong.