-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New cut at documentation PR using current develop branch (#198)
* New cut at documentation PR using current develop branch * Apply @didoo's suggestions from code review Co-Authored-By: chazzmoney <[email protected]> * updates based on didoo's thoughts * Updating the architecture documentation page (#200) * updates per didoo and dbanks * typo * generation differences * minor fixes and updates * making sure sd init command documentation is correct, for now * updates for clarity around properties and references * fixing up another alias piece * Addressing some comments in architecture diagram (#204) * Final touches on build diagram and architecture (#206) * Final touches on build diagram and architecture * Updating build diagram * Updating build diagram
- Loading branch information
1 parent
5095ac4
commit 13479c4
Showing
22 changed files
with
522 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"color": { | ||
"base": { | ||
"red": { | ||
"primary": "#611D1C", | ||
"secondary": { | ||
"inverse": "#000000" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Architecture Overview | ||
|
||
This is how Style Dictionary works under the hood. | ||
|
||
![build structure](assets/build-diagram.png) | ||
|
||
Let's take a closer look into each of these steps. | ||
|
||
## 1. Parse the config | ||
|
||
Style Dictionary is a configuration based framework, you tell it what to do in a configuration file. Style Dictionary first parses this configuration to know what to do. | ||
|
||
## 2. Find all token files | ||
|
||
In your [config](config.md) file you define a `source`, which is an array of file paths. This tells Style Dictionary where to find your token files. You can have them anywhere and in any folder structure as long as you tell Style Dictionary where to find them. | ||
|
||
## 3. Deep merge token files | ||
|
||
Style Dictionary takes all the files it found and performs a deep merge. This allows you to split your token files in any way you like, without worrying about accidentally overriding groups of tokens. This gives Style Dictionary a single, complete token object to work from. | ||
|
||
## 4. Iterate over the platforms | ||
|
||
For each platform defined in your [config](config.md), Style Dictionary will do a few steps to get it ready to be consumed on that platform. Everything that happens in a platform is non-destructive so you don't need to worry about one platform affecting another. | ||
|
||
## 4a. Transform the tokens | ||
|
||
Style Dictionary now traverses over the whole token object and looks for design tokens. It does this by looking for anything with a `value` key. When it comes across a design token, it then performs all the [transforms](transforms.md) defined in your [config](config.md) in order. | ||
|
||
## 4b. Resolve aliases / references to other values | ||
|
||
After all the tokens have been transformed, it then does another pass over the token object looking for aliases, which look like `"{size.font.base.value}"`. When it finds these, it then replaces the reference with the transformed value. As we have a single complete token object, aliases can be in any token file and still work. | ||
|
||
## 4c. Format the tokens into files | ||
|
||
Now all the design tokens are ready to be written to a file. Style Dictionary takes the whole transformed and resolved token object and for each file defined in the platform it [formats](formats.md) the token object and write the output to a file. Internally, Style Dictionary creates a flat array of all the design tokens it finds in addition to the token object. This is how you can output a flat SCSS variables file. | ||
|
||
After Style Dictionary does steps 4-6 for each platform, now you have all your output files that are ready to consume in each platform and codebase. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Configuration | ||
|
||
Style dictionaries are configuration driven. Your config file defines what executes and what to output when the style dictionary builds. | ||
|
||
By default, Style Dictionary looks for a `config.json` file in the root of your package. You can also specify a custom location when you use the [CLI](using_the_cli.md). If you want a custom build system using the [npm module](using_the_npm_module.md), you can specify a custom location for a configuration file or use a plain Javascript object. | ||
|
||
## config.json | ||
Here is a quick example: | ||
```json | ||
{ | ||
"source": ["properties/**/*.json"], | ||
"platforms": { | ||
"scss": { | ||
"transformGroup": "scss", | ||
"prefix": "sd", | ||
"buildPath": "build/scss/", | ||
"files": [{ | ||
"destination": "_variables.scss", | ||
"format": "scss/variables" | ||
}], | ||
"actions": ["copy_assets"] | ||
}, | ||
"android": { | ||
"transforms": ["attribute/cti", "name/cti/snake", "color/hex", "size/remToSp", "size/remToDp"], | ||
"buildPath": "build/android/src/main/res/values/", | ||
"files": [{ | ||
"destination": "style_dictionary_colors.xml", | ||
"format": "android/colors" | ||
}] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
| Attribute | Type | Description | | ||
| :--- | :--- | :--- | | ||
| includes | Array[String] (optional) | An array of paths to Style Dictionary property files that contain default styles. The Style Dictionary uses this as a base collection of properties. The properties found using the "source" attribute will overwrite properties found using includes. | | ||
| source | Array[String] | An array of paths to JSON files that contain style properties. The Style Dictionary will do a deep merge of all of the JSON files so you can separate your properties into multiple files. | | ||
| platforms | Object | An object containing platform config objects that describe how the Style Dictionary should build for that platform. You can add any arbitrary attributes on this object that will get passed to formats and actions (more on these in a bit). This is useful for things like build paths, name prefixes, variable names, etc. | | ||
| platform.transforms | Array[String] (optional) | An array of [transforms](transforms.md) to be performed on the style properties object. These will transform the properties in a non-destructive way so each platform can transform the properties. Transforms to apply sequentially to all properties. Can be a built-in one or you can create your own. | | ||
| platform.transformGroup | String (optional) | A string that maps to an array of transforms. This makes it easier to reference transforms by grouping them together. You must either define this or `transforms`. | | ||
| platform.buildPath | String (optional) | Base path to build the files, must end with a trailing slash. | | ||
| platform.files | Array (optional) | Files to be generated for this platform. | | ||
| platform.file.destination | String (optional) | Location to build the file, will be appended to the buildPath. | | ||
| platform.file.format | String (optional) | [Format](formats.md) used to generate the file. Can be a built-in one or you can create your own. | | ||
| platform.file.filter | Function/Object (optional) | A function or object used to filter the properties that will be included in the file. If a function is provided, each property will be passed to the function and the result (true or false) will determine whether the property is included. If an object is provided, each property will be matched against the object using a partial deep comparison to determine whether the property is included. | | ||
| platform.file.options | Object (optional) | A set of extra options associated with the file. | | ||
| platform.file.options.showFileHeader | Boolean | If the generated file should have a "Do not edit + Timestamp" header (where the format supports it). By default is "true". | | ||
| platform.actions | Array[String] (optional) | [Actions](actions.md) to be performed after the files are built for that platform. Actions can be any arbitrary code you want to run like copying files, generating assets, etc. You can use pre-defined actions or create custom actions. | | ||
|
||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.