-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create type for storing theme colors * feat: include color and @types/color, and simiplify theme schema * feat: set theme's default colors to white * feat: set FORCE_COLOR to 0||3 to follow the NO_COLOR manifest * feat: create DEFAULT_THEME to store default colors * revert: remove NO_COLOR manifest * feat: add new theme variables to style $, flag, and flag options * feat: add color to section headers * feat: configure default colors * feat: add colors for bin, command summary and version * feat: topics, commands, bin, version, sections, dollar sign are colorized * feat: configure default colors * feat: add feature flag to enabled/disable theme * feat: add colorize function to simplify the way colors are added to strings * feat: change all chalk.hex calls to colorize * feat: configure OCLIF_ENABLE_THEME to have precence over PJSON prop * feat: all theme colors are optional * fix: error TS2322: Type 'string' is not assignable to type 'boolean' * fix: error TS2345: arg of type 'Color<ColorParam>|undefined' not assignable to 'Color<ColorParam>' * fix: runtime error TypeError: color.hex is not a function * fix: this.pjson.oclif.enableTheme was not being evaluated when OCLIF_ENABLE_THEME was unset * chore(deps): update yarn.lock * refactor: simplified code removing OCLIF_ENABLE_THEME constant * fix: command summary was not changing its color when running the root command * feat: theme is now read from ~/config/<CLI>/theme.json if one exists * fix: add colors to other ARGUMENTS, EXAMPLES, DESCRIPTION, FLAGS DESCRIPTIONS sections * feat: add color token for aliases * fix(test): change template strings to avoid expected results printing bin twice * fix(test): add a missing parenthesis back so that all options are wraped by () * fix(test): remove single quotes wraping default flag values * feat: add test:debug script to ease debuging * refactor: add a constant with all possible THEME_KEYS * test: add tests to prove parsing untyped json object with color strings work * chore(package): add new scripts to ease development while writing tests * revert: remove theme from PJSON because a theme will be loaded from config_dir/<CLI>/theme.json * feat: add scopedEnvVarBoolean because scopedEnvVarTrue does not consider unset env vars * feat(test): add tests to prove the behavior that enables theme * refactor: replace all scopedEnvVarTrue by scopedEnvVarBoolean, which considers unset env variables * test: add tests to prove the enableTheme behavior * refactor: simplify parseTheme method * chore(package): remove localhost:4873 from lock file * revert: rever scopedEnvVarBoolean back to scopedEnvVarTrue * test: add tests to prove when this.theme is set * feat: ensure colorize returns string only * test: add tests to prove colorize works as expected * revert: rollback scopedEnvVarTrue as it was before * refactor: move parseTheme to src/util/util.js * refactor: make Theme type dinamically based on the values of THEME_KEYS at runtime * fix: err TS1259: Module /@types/color/index can only be default-imported using 'esModuleInterop' * revert: remove enableTheme from pjson because we don't want to cli devs to force users to use theme * revert: remove undefined as a return type for scopedEnvVarTrue * refactor: remove config.enableTheme Co-authored-by: Allan Oricil <55927613+AllanOricil@users.noreply.github.com>
- Loading branch information
1 parent
23fdcf9
commit da2bd5b
Showing
21 changed files
with
758 additions
and
1,086 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import chalk from 'chalk' | ||
import * as Color from 'color' | ||
|
||
import {STANDARD_CHALK, StandardChalk, Theme} from '../interfaces/theme' | ||
|
||
function isStandardChalk(color: any): color is StandardChalk { | ||
return STANDARD_CHALK.includes(color) | ||
} | ||
|
||
/** | ||
* Add color to text. | ||
* @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a chalk color (e.g. `red`) | ||
* @param text string to colorize | ||
* @returns colorized string | ||
*/ | ||
export function colorize(color: string | StandardChalk | undefined, text: string): string { | ||
if (isStandardChalk(color)) return chalk[color](text) | ||
|
||
return color ? chalk.hex(color)(text) : text | ||
} | ||
|
||
export function parseTheme(theme: Record<string, string>): Theme { | ||
return Object.fromEntries( | ||
Object.entries(theme) | ||
.map(([key, value]) => [key, getColor(value)]) | ||
.filter(([_, value]) => value), | ||
) | ||
} | ||
|
||
export function getColor(color: string): string | ||
export function getColor(color: StandardChalk): StandardChalk | ||
export function getColor(color: string | StandardChalk): string | StandardChalk | undefined { | ||
try { | ||
// eslint-disable-next-line new-cap | ||
return isStandardChalk(color) ? color : new Color.default(color).hex() | ||
} catch {} | ||
} |
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
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.