Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for cds.utils.colors #263

Merged
merged 8 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Added
- `cds.app` typed as express.js application
- `cds.cli` CLI arguments
- `cds.requires` types for MTX services.
- `cds.requires` types for MTX services
- `cds.utils.colors` types

### Changed
- Most `cds.requires` entries are now optionals.
Expand Down
53 changes: 53 additions & 0 deletions apis/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,57 @@ declare const utils: {
* @see https://cap.cloud.sap/docs/node.js/cds-utils#async-rm-path
*/
rm: (...path: string[]) => Promise<ReturnType<typeof fs.promises.rm>>,

/**
* @since 8.3.0
* @see https://cap.cloud.sap/docs/node.js/cds-utils#colors
*/
colors: {
enabled: boolean,
RESET: '\x1b[0m',
BOLD: '\x1b[1m' | '',
BRIGHT: '\x1b[1m' | '',
DIMMED: '\x1b[2m' | '',
ITALIC: '\x1b[3m' | '',
UNDER: '\x1b[4m' | '',
BLINK: '\x1b[5m' | '',
FLASH: '\x1b[6m' | '',
INVERT: '\x1b[7m' | '',
BLACK: '\x1b[30m' | '',
RED: '\x1b[31m' | '',
GREEN: '\x1b[32m' | '',
YELLOW: '\x1b[33m' | '',
BLUE: '\x1b[34m' | '',
PINK: '\x1b[35m' | '',
CYAN: '\x1b[36m' | '',
LIGHT_GRAY: '\x1b[37m' | '',
DEFAULT: '\x1b[39m' | '',
GRAY: '\x1b[90m' | '',
LIGHT_RED: '\x1b[91m' | '',
LIGHT_GREEN: '\x1b[92m' | '',
LIGHT_YELLOW: '\x1b[93m' | '',
LIGHT_BLUE: '\x1b[94m' | '',
LIGHT_PINK: '\x1b[95m' | '',
LIGHT_CYAN: '\x1b[96m' | '',
WHITE: '\x1b[97m' | '',
bg: {
BLACK: '\x1b[40m' | '',
RED: '\x1b[41m' | '',
GREEN: '\x1b[42m' | '',
YELLOW: '\x1b[43m' | '',
BLUE: '\x1b[44m' | '',
PINK: '\x1b[45m' | '',
CYAN: '\x1b[46m' | '',
WHITE: '\x1b[47m' | '',
DEFAULT: '\x1b[49m' | '',
LIGHT_GRAY: '\x1b[100m' | '',
LIGHT_RED: '\x1b[101m' | '',
LIGHT_GREEN: '\x1b[102m' | '',
LIGHT_YELLOW: '\x1b[103m' | '',
LIGHT_BLUE: '\x1b[104m' | '',
LIGHT_PINK: '\x1b[105m' | '',
LIGHT_CYAN: '\x1b[106m' | '',
LIGHT_WHITE: '\x1b[107m' | '',
},
},
}
12 changes: 12 additions & 0 deletions test/typescript/apis/project/cds-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ await rimraf('dist/db/data')
const { rm } = cds.utils
await rm('dist','db','data')
await rm('dist/db/data')

const { colors } = cds.utils
const {
enabled,
RESET, BOLD, BRIGHT, DIMMED, ITALIC, UNDER, BLINK, FLASH, INVERT,
BLACK, RED, GREEN, YELLOW, BLUE, PINK, CYAN, LIGHT_GRAY, DEFAULT, GRAY, LIGHT_RED, LIGHT_GREEN, LIGHT_YELLOW, LIGHT_BLUE, LIGHT_PINK, LIGHT_CYAN, WHITE,
bg
} = colors
enabled;
RESET; BOLD; BRIGHT; DIMMED; ITALIC; UNDER; BLINK; FLASH; INVERT;
BLACK; RED; GREEN; YELLOW; BLUE; PINK; CYAN; LIGHT_GRAY; DEFAULT; GRAY; LIGHT_RED; LIGHT_GREEN; LIGHT_YELLOW; LIGHT_BLUE; LIGHT_PINK; LIGHT_CYAN; WHITE;
bg.BLACK; bg.RED; bg.GREEN; bg.YELLOW; bg.BLUE; bg.PINK; bg.CYAN; bg.WHITE; bg.DEFAULT; bg.LIGHT_GRAY; bg.LIGHT_RED; bg.LIGHT_GREEN; bg.LIGHT_YELLOW; bg.LIGHT_BLUE; bg.LIGHT_PINK; bg.LIGHT_CYAN; bg.LIGHT_WHITE