Skip to content

Commit

Permalink
refactor: remove config.enableTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOricil committed Nov 9, 2023
1 parent caaa353 commit 00a6ccd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 51 deletions.
12 changes: 6 additions & 6 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class Config implements IConfig {
public dataDir!: string
public debug = 0
public dirname!: string
public enableTheme: boolean = false
public errlog!: string
public flexibleTaxonomy!: boolean
public home!: string
Expand All @@ -92,7 +91,7 @@ export class Config implements IConfig {
public plugins: Map<string, IPlugin> = new Map()
public root!: string
public shell!: string
public theme!: Theme
public theme?: Theme
public topicSeparator: ' ' | ':' = ':'
public userAgent!: string
public userPJSON?: PJSON.User
Expand Down Expand Up @@ -328,10 +327,11 @@ export class Config implements IConfig {

this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry

const themeFilePath = resolve(this.configDir, 'theme.json')
const theme = this.scopedEnvVarTrue('DISABLE_THEME') ? undefined : await safeReadJson(themeFilePath)
this.enableTheme = Boolean(theme)
if (this.enableTheme) this.theme = parseTheme(theme as Record<string, string>)
if (!this.scopedEnvVarTrue('DISABLE_THEME')) {
const themeFilePath = resolve(this.configDir, 'theme.json')
const theme = await safeReadJson<Record<string, string>>(themeFilePath)
this.theme = theme ? parseTheme(theme) : undefined
}

this.pjson.oclif.update = this.pjson.oclif.update || {}
this.pjson.oclif.update.node = this.pjson.oclif.update.node || {}
Expand Down
3 changes: 1 addition & 2 deletions src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export interface Config {
* base dirname to use in cacheDir/configDir/dataDir
*/
readonly dirname: string
enableTheme: boolean
/**
* points to a file that should be appended to for error logs
*
Expand Down Expand Up @@ -145,7 +144,7 @@ export interface Config {
* active shell
*/
readonly shell: string
readonly theme: Theme
readonly theme?: Theme
topicSeparator: ' ' | ':'
readonly topics: Topic[]
/**
Expand Down
42 changes: 13 additions & 29 deletions test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,62 +404,46 @@ describe('Config', () => {
)
})

describe('enableTheme', () => {
describe('theme', () => {
testConfig({pjson, env: {FOO_DISABLE_THEME: 'true'}}, {bin: 'red'}).it(
'should be false when DISABLE_THEME is true and theme.json exists',
'should not be set when DISABLE_THEME is true and theme.json exists',
(config) => {
expect(config).to.have.property('enableTheme', false)
expect(config).to.have.property('theme', undefined)
},
)

testConfig({pjson, env: {FOO_DISABLE_THEME: 'false'}}, {bin: 'red'}).it(
'should be true when DISABLE_THEME is false and theme.json exists',
'should be set when DISABLE_THEME is false and theme.json exists',
(config) => {
expect(config).to.have.property('enableTheme', true)
expect(config).to.nested.include({'theme.bin.color[0]': 255})
},
)

testConfig({pjson, env: {}}, {bin: 'red'}).it(
'should be true when DISABLE_THEME is unset and theme.json exists',
'should be set when DISABLE_THEME is unset and theme.json exists',
(config) => {
expect(config).to.have.property('enableTheme', true)
expect(config).to.nested.include({'theme.bin.color[0]': 255})
},
)

testConfig({pjson, env: {FOO_DISABLE_THEME: 'true'}}).it(
'should be false when DISABLE_THEME is true and theme.json does not exist',
'should not be set when DISABLE_THEME is true and theme.json does not exist',
(config) => {
expect(config).to.have.property('enableTheme', false)
expect(config).to.have.property('theme', undefined)
},
)

testConfig({pjson, env: {FOO_DISABLE_THEME: 'false'}}).it(
'should be false when DISABLE_THEME is false and theme.json does not exist',
'should not be set when DISABLE_THEME is false and theme.json does not exist',
(config) => {
expect(config).to.have.property('enableTheme', false)
expect(config).to.have.property('theme', undefined)
},
)

testConfig({pjson, env: {}}).it(
'should be false when DISABLE_THEME is unset and theme.json does not exist',
(config) => {
expect(config).to.have.property('enableTheme', false)
},
)
})

describe('theme', () => {
testConfig({pjson, env: {FOO_DISABLE_THEME: 'false'}}, {bin: 'red'}).it(
'should be set if this.enableTheme is true',
(config) => {
expect(config.theme).to.be.not.undefined
},
)

testConfig({pjson, env: {FOO_DISABLE_THEME: 'true'}}, {bin: 'red'}).it(
'should not be set if this.enableTheme is false',
'should not be set when DISABLE_THEME is unset and theme.json does not exist',
(config) => {
expect(config.theme).to.be.undefined
expect(config).to.have.property('theme', undefined)
},
)
})
Expand Down
14 changes: 0 additions & 14 deletions test/interfaces/config.test.ts

This file was deleted.

0 comments on commit 00a6ccd

Please sign in to comment.