amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.86k stars 542 forks source link

for style-dictionary config, how to support more config levels than `include/source` #597

Closed uptonking closed 3 years ago

uptonking commented 3 years ago

@dbanksdesign

any good idea?

dbanksdesign commented 3 years ago

You should be able to put both bootstrap and bootswatch-flaty in the include paths array. Files found in include should not have any issues with conflicts. Those files will be deep-merged and won't throw any warnings or errors if there are conflicts (the later files defined in the include array will take precedence). Files found in source will take precedence over those in include. You will only get a collision warning if multiple files defined in source define the same tokens. Here is a tiny sample of that working:

// build.js
const StyleDictionary = require('style-dictionary');

StyleDictionary.extend({
  include: [
    `include1.json`,
    `include2.json`
  ],
  source: [
    `source.json`
  ],
  platforms: {
    css: {
      transformGroup: `css`,
      files: [{
        destination: `variables.css`,
        format: `css/variables`
      }]
    }
  }
}).buildAllPlatforms();

// include1.json
{
  "foo": { "value": "bar" }
}

// include2.json
{
  "foo": { "value": "foo" }
}

// source.json
{
  "foo": { "value": "boo" }
}

That should build fine and foo's value should be "boo".

Going off your example, you could have 3 directories: bootstrap, bootswatch-flaty, and bootswatch-flaty-dark and then run Style Dictionary 3 times with the include and source configuration like this:

// build.js
const StyleDictionary = require('style-dictionary');

// bootstrap
StyleDictionary.extend({
  source: [
    `bootstrap/**/*.json`
  ],
  platforms: {
    //...
  }
}).buildAllPlatforms();

// bootswatch-flaty
StyleDictionary.extend({
  include: [
    `bootstrap/**/*.json`
  ],
  source: [
    `bootswatch-flaty/**/*.json`
  ],
  platforms: {
    //...
  }
}).buildAllPlatforms();

// bootswatch-flaty-dark
StyleDictionary.extend({
  include: [
    `bootstrap/**/*.json`,
    `bootswatch-flaty/**/*.json`
  ],
  source: [
    `bootswatch-flaty-dark/**/*.json`
  ],
  platforms: {
    //...
  }
}).buildAllPlatforms();

Does that make sense?