0.0.2-alpha.82 • Published 3 years ago

@telus-uds/tools-palette-schema v0.0.2-alpha.82

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

palette-schema

Validates palettes and builds them into artifacts that can be consumed by various platforms

Usage

CLI

The easiest way to build a palette is with the CLI command:

  1. Install:

    npm install --save-dev @telus-uds/tools-palette-schema
  2. Add a npm run script to your package.json:

    {
      // ...
      scripts: {
        "build": "tools-palette-schema build [PATH_TO_YOUR_PALETTE.JSON]"
      }
    }
  3. Build the palette:

    npm run build

CLI Options

$ tools-palette-schema build --help

build.js build [palette]

builds the palette

Positionals:
  palette  palette JSON file to build          [default: "./build/palette.json"]

Options:
      --help      Show help                                            [boolean]
      --version   Show version number                                  [boolean]
  -p, --platform  platforms to build, all if omitted                     [array]
  -c, --config    override style-dictionary config file

By default, all platforms are included in the build. To specify certain platforms, use the --platform option:

tools-palette-schema build --platform ios --platform android

To specify a different palette JSON file:

tools-palette-schema build ./path/to/palette.json

To override the default style-dictionary config (can be javascript or json):

tools-palette-schema build --config ./path/to/config.js

API

The package can also be imported directly in node.js:

const {build, validate, config} = require('@telus-uds/tools-palette-schema')

build({palettePath: 'path/to/palette.json})

The API exports the following function and objects:

build({configPath, platforms, palettePath})

Validates and builds a palette JSON file.

optiondescription
configPathpath to the style-dictionary config file, uses default config if not set
platformsarray of platforms to build (as defined in the config), builds all platforms if not set
palettePathpath to the palette json file, defaults to ./build/palette.json

validate(palette)

Validates a palette object synchronously and returns a boolean indicating if the palette is valid. The errors property of the function is assigned the errors (or null if there were none) from the last validation attempt. Refer to the ajv docs.

parameterdescription
palettepalette object

config

Default style-dictionary config. This may be useful for overriding certain config values for a custom build.

Tests

The package contains several unit tests:

npm test