-
Notifications
You must be signed in to change notification settings - Fork 70
feat(eds-color-palette-generator): add CLI tool to generate color palettes #4033
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
feat(eds-color-palette-generator): add CLI tool to generate color palettes #4033
Conversation
|
When the tool is ready we should add it as a dependency to the eds-tokens package, create a palette-config.json with the existing colours defined in the palette.ts defined in eds-color-palette-generator and a script running the generate-colors cli in eds-tokens package.json. "colors:generate": "generate-colors". Can you look at this @copilot ? |
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
Done in commit dee131e. The integration includes:
The script can now be run with: cd packages/eds-tokens
pnpm colors:generateThis generates |
|
I would like to extend the palette-config.json to include the colorFormat that support HEX or OKLCH. This has a type defined ColorFormat and is used as a parameter to the generateColorScale function named format. This should be an optional configuration and HEX should be the default output for now, but please test both variants creating snapshots with OKLCH and HEX values. I would also like to define the default output file for dark to be Color Dark.Mode 1.json and light to be Color Light.Mode 1, but this should also be optional to override in the palette-config. It would also be great if you could evaluate the suggested changeset for security improvements and include them when is best practise. Can you look at this @copilot ? |
- Add colorFormat option (HEX or OKLCH) with HEX as default - Add configurable outputFileLight and outputFileDark options - Change default output filenames to "Color Light.Mode 1.json" and "Color Dark.Mode 1.json" - Update tests with separate snapshots for HEX and OKLCH formats - Add test for custom output filenames - Update documentation with new configuration options - Regenerate example files with new defaults (HEX format) Co-authored-by: torleifhalseth <2523381+torleifhalseth@users.noreply.github.com>
packages/eds-color-palette-generator/src/cli/generate-colors.test.ts
Dismissed
Show dismissed
Hide dismissed
packages/eds-color-palette-generator/src/cli/generate-colors.test.ts
Dismissed
Show dismissed
Hide dismissed
packages/eds-color-palette-generator/src/cli/generate-colors.test.ts
Dismissed
Show dismissed
Hide dismissed
packages/eds-color-palette-generator/src/cli/generate-colors.test.ts
Dismissed
Show dismissed
Hide dismissed
Done in commit c5879f4. Implemented changes:
Configuration example: {
"colors": [...],
"colorFormat": "HEX",
"outputFileLight": "Color Light.Mode 1.json",
"outputFileDark": "Color Dark.Mode 1.json"
}The example files have been regenerated with the new defaults (HEX format and new filenames). Note: Regarding security improvements, the current implementation follows best practices:
If there were specific security concerns in a changeset you're referring to, please share it and I'll review them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new CLI tool to the @equinor/eds-color-palette-generator package that enables users to generate color palettes for light and dark modes from a JSON configuration file. The implementation leverages existing color generation utilities while maintaining consistency with the EDS design system.
Key Changes:
- Added a
generate-colorsCLI command that reads configuration files and outputs W3C Design Token format files - Integrated the CLI tool into the
@equinor/eds-tokenspackage workflow for generating core color tokens - Updated HEX color formatting to ensure consistent 6-digit output format
Reviewed Changes
Copilot reviewed 17 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/eds-color-palette-generator/src/cli/generate-colors.ts |
Main CLI implementation with configuration parsing and token generation |
packages/eds-color-palette-generator/src/cli/generate-colors.test.ts |
Comprehensive test suite with snapshot testing for different formats |
packages/eds-color-palette-generator/src/utils/color.ts |
Enhanced HEX formatting to ensure full 6-digit format |
packages/eds-tokens/palette-config.json |
Configuration file with 7 existing EDS colors |
packages/eds-tokens/package.json |
Added CLI dependency and generation script |
packages/eds-tokens/tokens/GnovDpL3UV6X51Ot7Kv6Im/Color *.json |
Updated color token files with reordered color definitions |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
packages/eds-tokens/tokens/GnovDpL3UV6X51Ot7Kv6Im/🌗 Color scheme.Light.json
Outdated
Show resolved
Hide resolved
packages/eds-tokens/tokens/GnovDpL3UV6X51Ot7Kv6Im/🌗 Color scheme.Dark.json
Outdated
Show resolved
Hide resolved
pomfrida
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Overview
This PR adds a new
generate-colorsCLI tool to the@equinor/eds-color-palette-generatorpackage that allows generating color palettes for light and dark modes from a configuration file.What's New
CLI Tool
The new
generate-colorscommand reads apalette-config.jsonfile and generates W3C Design Token format files for light and dark modes:This generates:
Color Light.Mode 1.json- Color tokens for light mode (default filename)Color Dark.Mode 1.json- Color tokens for dark mode (default filename)Configuration Format
The CLI uses a minimal configuration format focused on color definitions:
{ "colors": [ { "name": "Moss Green", "value": "#007079" }, { "name": "Gray", "value": "#4A4A4A" }, { "name": "Blue", "value": "#0084C4" } ] }Optional configuration parameters:
{ "colors": [...], "colorFormat": "HEX", "outputFileLight": "Color Light.Mode 1.json", "outputFileDark": "Color Dark.Mode 1.json", "meanLight": 0.6, "stdDevLight": 2, "meanDark": 0.7, "stdDevDark": 2 }Optional fields:
colorFormat: Output format -"HEX"or"OKLCH"(default:"HEX")outputFileLight: Custom filename for light mode tokens (default:"Color Light.Mode 1.json")outputFileDark: Custom filename for dark mode tokens (default:"Color Dark.Mode 1.json")meanLight,stdDevLight,meanDark,stdDevDark: Gaussian distribution parameters for chroma controlOutput Format
The generated tokens follow the W3C Design Tokens Community Group specification and include all 15 semantic color steps defined in the EDS palette configuration:
bg-canvas,bg-surfacebg-fill-muted-default,bg-fill-muted-hover,bg-fill-muted-activeborder-subtle,border-medium,border-strongbg-fill-emphasis-default,bg-fill-emphasis-hover,bg-fill-emphasis-activetext-subtle,text-strong,text-subtle-on-emphasis,text-strong-on-emphasisHEX Format (default):
{ "Light": { "Moss Green": { "bg-canvas": { "$type": "color", "$value": "#eaf8fa", "$description": "", "$extensions": { ... } }, ... } } }OKLCH Format:
{ "Light": { "Moss Green": { "bg-canvas": { "$type": "color", "$value": "oklch(0.970 0.015 204.6)", "$description": "", "$extensions": { ... } }, ... } } }Implementation Details
Uses Existing Functions
The CLI leverages existing color generation utilities:
generateColorScale()fromutils/color.tsfor generating color scalesgetLightnessValues()fromconfig/helpers.tsfor extracting lightness valuesPALETTE_STEPSfromconfig/config.tsfor semantic step definitionsThis ensures consistency with the web-based palette generator while maintaining DRY principles.
Build System
Following the pattern established by the
@equinor/eds-tokens-buildpackage:binentry inpackage.jsonfor thegenerate-colorscommandbuild:cliscript for building the CLI toolTesting
Comprehensive test suite with snapshot testing:
Documentation
src/cli/README.md- Detailed CLI documentation with usage examples for both HEX and OKLCH formatsREADME.mdwith CLI informationexamples/directoryIntegration with eds-tokens Package
The CLI tool has been integrated into the
@equinor/eds-tokenspackage:@equinor/eds-color-palette-generatoras a devDependencypalette-config.jsonwith the 7 existing EDS colors (Moss Green, Gray, North sea, Green, Blue, Orange, Red)colors:generatescript that runsgenerate-colors palette-config.json output.gitignoreto exclude generated output directoryThe tool can now be used in the eds-tokens package:
cd packages/eds-tokens pnpm colors:generateFiles Changed
Added - eds-color-palette-generator
src/cli/generate-colors.ts- CLI implementationsrc/cli/generate-colors.test.ts- Test suitesrc/cli/README.md- CLI documentationsrc/cli/__snapshots__/generate-colors.test.ts.snap- Test snapshotsvite.config.ts- Build configurationexamples/palette-config.json- Example configurationexamples/Color Light.Mode 1.json- Example light mode output (HEX format)examples/Color Dark.Mode 1.json- Example dark mode output (HEX format)Modified - eds-color-palette-generator
package.json- Added bin entry, build:cli script, vite dependenciesREADME.md- Added CLI documentation section.gitignore- Added dist/ and output/ directoriesAdded - eds-tokens
palette-config.json- Configuration with existing EDS colorsModified - eds-tokens
package.json- Added eds-color-palette-generator dependency and colors:generate script.gitignore- Added /output directoryVerification
✅ All tests pass (61/61)
✅ Linting passes with no errors
✅ CLI produces valid W3C Design Token format
✅ Output is deterministic
✅ Follows TypeScript coding standards
✅ Successfully integrated with eds-tokens package
✅ Both HEX and OKLCH formats tested with snapshots
Fixes #4032
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.