Skip to content

Commit

Permalink
fix: prefer user theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 29, 2024
1 parent ab502b4 commit 5eaed66
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class Config implements IConfig {
this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry

if (!this.scopedEnvVarTrue('DISABLE_THEME')) {
const {theme} = await this.loadTheme()
const {theme} = await this.loadThemes()
this.theme = theme
}

Expand Down Expand Up @@ -401,17 +401,30 @@ export class Config implements IConfig {
}
}

public async loadTheme(): Promise<{
file: string
public async loadThemes(): Promise<{
file: string | undefined
theme: Theme | undefined
}> {
const file = this.pjson.oclif.theme
const defaultThemeFile = this.pjson.oclif.theme
? resolve(this.root, this.pjson.oclif.theme)
: resolve(this.configDir, 'theme.json')
const themeRaw = await safeReadJson<Record<string, string>>(file)
: this.pjson.oclif.theme
const userThemeFile = resolve(this.configDir, 'theme.json')

const [defaultTheme, userTheme] = await Promise.all([
defaultThemeFile ? await safeReadJson<Record<string, string>>(defaultThemeFile) : undefined,
await safeReadJson<Record<string, string>>(userThemeFile),
])

if (userTheme) {
return {
file: userThemeFile,
theme: parseTheme(userTheme),
}
}

return {
file,
theme: themeRaw ? parseTheme(themeRaw) : undefined,
file: defaultThemeFile,
theme: parseTheme(defaultTheme ?? {}),
}
}

Expand Down

0 comments on commit 5eaed66

Please sign in to comment.