|
| 1 | +# Generate Colors CLI |
| 2 | + |
| 3 | +A CLI tool to generate color palettes for light and dark modes based on a configuration file. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +This tool is part of the `@equinor/eds-color-palette-generator` package. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +### Basic Usage |
| 12 | + |
| 13 | +```bash |
| 14 | +generate-colors [configPath] [outputDir] |
| 15 | +``` |
| 16 | + |
| 17 | +**Arguments:** |
| 18 | +- `configPath` (optional): Path to the palette configuration JSON file. Defaults to `palette-config.json` in the current directory. |
| 19 | +- `outputDir` (optional): Output directory for the generated token files. Defaults to `output/` in the current directory. |
| 20 | + |
| 21 | +**Example:** |
| 22 | + |
| 23 | +```bash |
| 24 | +generate-colors examples/palette-config.json output/ |
| 25 | +``` |
| 26 | + |
| 27 | +### Configuration File Format |
| 28 | + |
| 29 | +The configuration file should be a JSON file with the following structure: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "colors": [ |
| 34 | + { "name": "Moss Green", "value": "#007079" }, |
| 35 | + { "name": "Gray", "value": "#4A4A4A" }, |
| 36 | + { "name": "Blue", "value": "#0084C4" } |
| 37 | + ], |
| 38 | + "colorFormat": "HEX", |
| 39 | + "outputFileLight": "Color Light.Mode 1.json", |
| 40 | + "outputFileDark": "Color Dark.Mode 1.json", |
| 41 | + "meanLight": 0.6, |
| 42 | + "stdDevLight": 2, |
| 43 | + "meanDark": 0.7, |
| 44 | + "stdDevDark": 2 |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +**Required fields:** |
| 49 | +- `colors`: An array of color definitions, each with: |
| 50 | + - `name`: The name of the color |
| 51 | + - `value`: The hex color value |
| 52 | + |
| 53 | +**Optional fields:** |
| 54 | +- `colorFormat`: Output color format - either `"HEX"` or `"OKLCH"` (default: `"HEX"`) |
| 55 | +- `outputFileLight`: Custom filename for light mode tokens (default: `"Color Light.Mode 1.json"`) |
| 56 | +- `outputFileDark`: Custom filename for dark mode tokens (default: `"Color Dark.Mode 1.json"`) |
| 57 | +- `meanLight`: Mean value for the Gaussian distribution in light mode (default: 0.6) |
| 58 | +- `stdDevLight`: Standard deviation for the Gaussian distribution in light mode (default: 2) |
| 59 | +- `meanDark`: Mean value for the Gaussian distribution in dark mode (default: 0.7) |
| 60 | +- `stdDevDark`: Standard deviation for the Gaussian distribution in dark mode (default: 2) |
| 61 | + |
| 62 | +### Output |
| 63 | + |
| 64 | +The tool generates two files with configurable names: |
| 65 | +- Default: `Color Light.Mode 1.json` - Color tokens for light mode |
| 66 | +- Default: `Color Dark.Mode 1.json` - Color tokens for dark mode |
| 67 | + |
| 68 | +Both files follow the W3C Design Tokens Community Group format and include all the semantic color steps defined in the palette configuration. |
| 69 | + |
| 70 | +#### Output Formats |
| 71 | + |
| 72 | +**HEX Format (default):** |
| 73 | +```json |
| 74 | +{ |
| 75 | + "Light": { |
| 76 | + "Moss Green": { |
| 77 | + "1": { |
| 78 | + "$type": "color", |
| 79 | + "$value": "#f5fefe", |
| 80 | + ... |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +**OKLCH Format:** |
| 88 | +```json |
| 89 | +{ |
| 90 | + "Light": { |
| 91 | + "Moss Green": { |
| 92 | + "1": { |
| 93 | + "$type": "color", |
| 94 | + "$value": "oklch(0.970 0.015 204.6)", |
| 95 | + ... |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## Example |
| 103 | + |
| 104 | +See the `examples/` directory for a sample configuration file and generated output: |
| 105 | +- `examples/palette-config.json`: Sample configuration |
| 106 | +- `examples/color.tokens.light.json`: Generated light mode tokens |
| 107 | +- `examples/color.tokens.dark.json`: Generated dark mode tokens |
| 108 | + |
| 109 | +## How It Works |
| 110 | + |
| 111 | +The tool uses the existing `generateColorScale` function from the color utilities to create color scales for each color in the configuration. The lightness values and other configuration parameters are derived from the predefined `PALETTE_STEPS` configuration, ensuring consistency with the EDS color system. |
| 112 | + |
| 113 | +The Gaussian distribution parameters (`mean` and `stdDev`) control the chroma (saturation) of colors at different lightness levels, creating natural-looking color scales that maintain the hue while varying lightness and saturation. |
0 commit comments