style-dictionary 3.8.0 → 4.0.0-prerelease.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -56
- package/bin/style-dictionary +53 -36
- package/examples/README.md +23 -22
- package/examples/advanced/assets-base64-embed/README.md +6 -3
- package/examples/advanced/auto-rebuild-watcher/README.md +1 -1
- package/examples/advanced/component-cti/README.md +9 -10
- package/examples/advanced/component-cti/config.js +30 -28
- package/examples/advanced/create-react-app/README.md +5 -7
- package/examples/advanced/create-react-app/src/App.js +11 -4
- package/examples/advanced/create-react-app/src/components/with-css-modules/ComponentWithCssModules.js +17 -7
- package/examples/advanced/create-react-app/src/components/with-sass/ComponentWithSass.js +17 -7
- package/examples/advanced/create-react-app/src/components/with-styled-components/ComponentWithStyledComponents.js +16 -7
- package/examples/advanced/create-react-app/src/serviceWorker.js +9 -13
- package/examples/advanced/create-react-native-app/__tests__/App.js +5 -5
- package/examples/advanced/create-react-native-app/babel.config.js +1 -1
- package/examples/advanced/create-react-native-app/index.js +2 -2
- package/examples/advanced/create-react-native-app/src/App.js +6 -6
- package/examples/advanced/create-react-native-app/src/style-dictionary-dist/variables.js +14 -4
- package/examples/advanced/custom-file-header/README.md +13 -13
- package/examples/advanced/custom-file-header/build.js +69 -69
- package/examples/advanced/custom-filters/README.md +1 -1
- package/examples/advanced/custom-filters/build.js +4 -7
- package/examples/advanced/custom-formats-with-templates/README.md +6 -6
- package/examples/advanced/custom-formats-with-templates/build.js +31 -28
- package/examples/advanced/custom-parser/README.md +9 -9
- package/examples/advanced/custom-parser/sd.config.js +16 -13
- package/examples/advanced/custom-transforms/README.md +6 -7
- package/examples/advanced/custom-transforms/build.js +53 -45
- package/examples/advanced/flutter/README.md +1 -1
- package/examples/advanced/font-face-rules/README.md +8 -6
- package/examples/advanced/font-face-rules/sd.config.js +49 -45
- package/examples/advanced/format-helpers/README.md +1 -1
- package/examples/advanced/format-helpers/sd.config.js +47 -41
- package/examples/advanced/matching-build-files/README.md +2 -2
- package/examples/advanced/matching-build-files/config.js +27 -27
- package/examples/advanced/matching-build-files/tokens/index.js +3 -4
- package/examples/advanced/multi-brand-multi-platform/README.md +7 -4
- package/examples/advanced/multi-brand-multi-platform/build.js +49 -41
- package/examples/advanced/node-modules-as-config-and-properties/README.md +4 -4
- package/examples/advanced/node-modules-as-config-and-properties/components/button/base.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/button/index.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/button/primary.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/button/secondary.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/index.js +3 -3
- package/examples/advanced/node-modules-as-config-and-properties/config.js +38 -30
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/background.js +4 -4
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/border.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/brand.js +12 -12
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/core.js +19 -19
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/font.js +6 -6
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/index.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/index.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/border.js +4 -4
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/font.js +7 -7
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/index.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/padding.js +6 -6
- package/examples/advanced/npm-module/README.md +2 -3
- package/examples/advanced/referencing_aliasing/README.md +6 -2
- package/examples/advanced/s3/README.md +2 -3
- package/examples/advanced/s3/upload.js +7 -9
- package/examples/advanced/tokens-deprecation/README.md +2 -4
- package/examples/advanced/tokens-deprecation/build.js +12 -9
- package/examples/advanced/transitive-transforms/README.md +10 -11
- package/examples/advanced/transitive-transforms/sd.config.js +13 -12
- package/examples/advanced/variables-in-outputs/README.md +7 -7
- package/examples/advanced/variables-in-outputs/sd.config.js +55 -46
- package/examples/advanced/yaml-tokens/README.md +2 -3
- package/examples/advanced/yaml-tokens/sd.config.js +22 -18
- package/examples/basic/README.md +8 -0
- package/examples/complete/README.md +2 -1
- package/fs.js +7 -0
- package/index-node.js +7 -0
- package/index.js +51 -120
- package/lib/buildAllPlatforms.js +3 -5
- package/lib/buildFile.js +86 -60
- package/lib/buildFiles.js +8 -7
- package/lib/buildPlatform.js +6 -9
- package/lib/cleanActions.js +2 -5
- package/lib/cleanAllPlatforms.js +2 -5
- package/lib/cleanDir.js +11 -17
- package/lib/cleanDirs.js +4 -7
- package/lib/cleanFile.js +4 -9
- package/lib/cleanFiles.js +4 -7
- package/lib/cleanPlatform.js +10 -13
- package/lib/common/actions.js +18 -18
- package/lib/common/filters.js +7 -7
- package/lib/common/formatHelpers/createPropertyFormatter.js +31 -13
- package/lib/common/formatHelpers/fileHeader.js +7 -13
- package/lib/common/formatHelpers/formattedVariables.js +24 -10
- package/lib/common/formatHelpers/getTypeScriptType.js +22 -20
- package/lib/common/formatHelpers/iconsWithPrefix.js +4 -5
- package/lib/common/formatHelpers/index.js +10 -16
- package/lib/common/formatHelpers/minifyDictionary.js +3 -5
- package/lib/common/formatHelpers/setComposeObjectProperties.js +8 -10
- package/lib/common/formatHelpers/setSwiftFileProperties.js +3 -5
- package/lib/common/formatHelpers/sortByName.js +3 -5
- package/lib/common/formatHelpers/sortByReference.js +5 -7
- package/lib/common/formats.js +266 -236
- package/lib/common/templates/android/{colors.template → colors.template.js} +3 -3
- package/lib/common/templates/android/{dimens.template → dimens.template.js} +2 -2
- package/lib/common/templates/android/{fontDimens.template → fontDimens.template.js} +2 -2
- package/lib/common/templates/android/{integers.template → integers.template.js} +2 -2
- package/lib/common/templates/android/{resources.template → resources.template.js} +3 -3
- package/lib/common/templates/android/{strings.template → strings.template.js} +2 -2
- package/lib/common/templates/compose/{object.kt.template → object.kt.template.js} +5 -5
- package/lib/common/templates/css/{fonts.css.template → fonts.css.template.js} +4 -4
- package/lib/common/templates/flutter/{class.dart.template → class.dart.template.js} +3 -3
- package/lib/common/templates/ios/{colors.h.template → colors.h.template.js} +3 -3
- package/lib/common/templates/ios/{colors.m.template → colors.m.template.js} +3 -3
- package/lib/common/templates/ios/{macros.template → macros.template.js} +2 -2
- package/lib/common/templates/ios/{plist.template → plist.template.js} +2 -2
- package/lib/common/templates/ios/{singleton.h.template → singleton.h.template.js} +2 -2
- package/lib/common/templates/ios/{singleton.m.template → singleton.m.template.js} +9 -9
- package/lib/common/templates/ios/{static.h.template → static.h.template.js} +2 -2
- package/lib/common/templates/ios/{static.m.template → static.m.template.js} +2 -2
- package/lib/common/templates/ios/{strings.h.template → strings.h.template.js} +2 -2
- package/lib/common/templates/ios/{strings.m.template → strings.m.template.js} +8 -8
- package/lib/common/templates/ios-swift/{any.swift.template → any.swift.template.js} +4 -4
- package/lib/common/templates/scss/{map-deep.template → map-deep.template.js} +10 -10
- package/lib/common/templates/scss/{map-flat.template → map-flat.template.js} +7 -7
- package/lib/common/templates/static-style-guide/{index.html.template → index.html.template.js} +3 -3
- package/lib/common/transformGroups.js +21 -55
- package/lib/common/transforms.js +156 -151
- package/lib/exportPlatform.js +14 -15
- package/lib/extend.js +41 -32
- package/lib/filterProperties.js +29 -27
- package/lib/performActions.js +2 -5
- package/lib/register/action.js +4 -8
- package/lib/register/fileHeader.js +3 -5
- package/lib/register/filter.js +5 -7
- package/lib/register/format.js +3 -5
- package/lib/register/parser.js +2 -4
- package/lib/register/transform.js +6 -12
- package/lib/register/transformGroup.js +10 -12
- package/lib/transform/config.js +27 -33
- package/lib/transform/object.js +24 -15
- package/lib/transform/property.js +11 -11
- package/lib/transform/propertySetup.js +8 -14
- package/lib/utils/combineJSON.js +18 -25
- package/lib/utils/convertToBase64.js +4 -7
- package/lib/utils/createDictionary.js +7 -11
- package/lib/utils/createFormatArgs.js +7 -9
- package/lib/utils/deepExtend.js +23 -22
- package/lib/utils/es6_.js +101 -115
- package/lib/utils/flattenProperties.js +6 -9
- package/lib/utils/groupMessages.js +35 -33
- package/lib/utils/jsonc.js +4 -4
- package/lib/utils/references/createReferenceRegex.js +9 -10
- package/lib/utils/references/defaults.js +2 -4
- package/lib/utils/references/getName.js +2 -5
- package/lib/utils/references/getPathFromName.js +2 -5
- package/lib/utils/references/getReferences.js +6 -8
- package/lib/utils/references/resolveReference.js +3 -6
- package/lib/utils/references/usesReference.js +2 -4
- package/lib/utils/resolveObject.js +28 -30
- package/package.json +47 -24
- package/types/DesignToken.d.ts +3 -8
- package/types/Dictionary.d.ts +1 -1
- package/types/index.d.ts +37 -32
- package/types/index.test-d.ts +53 -57
- package/lib/register/template.js +0 -57
package/README.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://www.npmjs.com/package/style-dictionary)
|
|
12
12
|
|
|
13
13
|
# Style Dictionary
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
> _Style once, use everywhere._
|
|
15
16
|
|
|
16
17
|
A Style Dictionary uses design tokens to define styles once and use those styles on any platform or language. It provides a single place to create and edit your styles, and exports these tokens to all the places you need - iOS, Android, CSS, JS, HTML, sketch files, style documentation, etc. It is available as a CLI through npm, but can also be used like any normal node module if you want to extend its functionality.
|
|
17
18
|
|
|
@@ -20,56 +21,67 @@ When you are managing user experiences, it can be quite challenging to keep styl
|
|
|
20
21
|
For detailed usage head to https://amzn.github.io/style-dictionary
|
|
21
22
|
|
|
22
23
|
## Watch the Demo on YouTube
|
|
24
|
+
|
|
23
25
|
[](http://youtu.be/1HREvonfqhY)
|
|
24
26
|
|
|
25
27
|
## Experiment in the playground
|
|
28
|
+
|
|
26
29
|
Try the browser-based Style Dictionary playground: [https://www.style-dictionary-play.dev/](https://www.style-dictionary-play.dev/), built by the folks at [\<div\>RIOTS](https://divriots.com/).
|
|
27
30
|
|
|
28
31
|
## Contents
|
|
29
|
-
* [Installation](#installation)
|
|
30
|
-
* [Usage](#usage)
|
|
31
|
-
* [Example](#example)
|
|
32
|
-
* [Quick Start](#quick-start)
|
|
33
|
-
* [Design Tokens](#design-tokens)
|
|
34
|
-
* [Extending](#extending)
|
|
35
|
-
* [Contributing](#contributing)
|
|
36
|
-
* [License](#license)
|
|
37
32
|
|
|
33
|
+
- [Installation](#installation)
|
|
34
|
+
- [Usage](#usage)
|
|
35
|
+
- [Example](#example)
|
|
36
|
+
- [Quick Start](#quick-start)
|
|
37
|
+
- [Design Tokens](#design-tokens)
|
|
38
|
+
- [Extending](#extending)
|
|
39
|
+
- [Contributing](#contributing)
|
|
40
|
+
- [License](#license)
|
|
38
41
|
|
|
39
42
|
## Installation
|
|
40
|
-
|
|
43
|
+
|
|
44
|
+
_Note that you must have node (and npm) installed._
|
|
41
45
|
|
|
42
46
|
If you want to use the CLI, you can install it globally via npm:
|
|
47
|
+
|
|
43
48
|
```bash
|
|
44
49
|
$ npm install -g style-dictionary
|
|
45
50
|
```
|
|
46
51
|
|
|
47
52
|
Or you can install it like a normal npm dependency. This is a build tool and you are most likely going to want to save it as a dev dependency:
|
|
53
|
+
|
|
48
54
|
```bash
|
|
49
55
|
$ npm install -D style-dictionary
|
|
50
56
|
```
|
|
51
57
|
|
|
52
58
|
If you want to install it with yarn:
|
|
59
|
+
|
|
53
60
|
```bash
|
|
54
61
|
$ yarn add style-dictionary --dev
|
|
55
62
|
```
|
|
56
63
|
|
|
57
64
|
## Usage
|
|
65
|
+
|
|
58
66
|
### CLI
|
|
67
|
+
|
|
59
68
|
```bash
|
|
60
69
|
$ style-dictionary build
|
|
61
70
|
```
|
|
71
|
+
|
|
62
72
|
Call this in the root directory of your project. The only thing needed is a `config.json` file. There are also arguments:
|
|
63
73
|
|
|
64
|
-
| Flag
|
|
65
|
-
|
|
|
66
|
-
| --config \[path\]
|
|
67
|
-
| --platform \[platform\] | -p
|
|
68
|
-
| --help
|
|
69
|
-
| --version
|
|
74
|
+
| Flag | Short Flag | Description |
|
|
75
|
+
| ----------------------- | ---------- | ---------------------------------------------------------- |
|
|
76
|
+
| --config \[path\] | -c | Set the config file to use. Must be a .json file |
|
|
77
|
+
| --platform \[platform\] | -p | Only build a specific platform defined in the config file. |
|
|
78
|
+
| --help | -h | Display help content |
|
|
79
|
+
| --version | -v | Display the version |
|
|
70
80
|
|
|
71
81
|
### Node
|
|
82
|
+
|
|
72
83
|
You can also use the style dictionary build system in node if you want to [extend](#extending) the functionality or use it in another build system like Grunt or Gulp.
|
|
84
|
+
|
|
73
85
|
```javascript
|
|
74
86
|
const StyleDictionary = require('style-dictionary').extend('config.json');
|
|
75
87
|
|
|
@@ -77,6 +89,7 @@ StyleDictionary.buildAllPlatforms();
|
|
|
77
89
|
```
|
|
78
90
|
|
|
79
91
|
The `.extend()` method is an overloaded method that can also take an object with the configuration in the same format as a config.json file.
|
|
92
|
+
|
|
80
93
|
```javascript
|
|
81
94
|
const StyleDictionary = require('style-dictionary').extend({
|
|
82
95
|
source: ['tokens/**/*.json'],
|
|
@@ -84,19 +97,22 @@ const StyleDictionary = require('style-dictionary').extend({
|
|
|
84
97
|
scss: {
|
|
85
98
|
transformGroup: 'scss',
|
|
86
99
|
buildPath: 'build/',
|
|
87
|
-
files: [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
files: [
|
|
101
|
+
{
|
|
102
|
+
destination: 'variables.scss',
|
|
103
|
+
format: 'scss/variables',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
92
107
|
// ...
|
|
93
|
-
}
|
|
108
|
+
},
|
|
94
109
|
});
|
|
95
110
|
|
|
96
111
|
StyleDictionary.buildAllPlatforms();
|
|
97
112
|
```
|
|
98
113
|
|
|
99
114
|
## Example
|
|
115
|
+
|
|
100
116
|
[Take a look at some of our examples](examples/)
|
|
101
117
|
|
|
102
118
|
A style dictionary is a collection of design tokens, key/value pairs that describe stylistic attributes like colors, sizes, icons, motion, etc. A style dictionary defines these design tokens in JSON or Javascript files, and can also include static assets like images and fonts. Here is a basic example of what the package structure can look like:
|
|
@@ -115,6 +131,7 @@ A style dictionary is a collection of design tokens, key/value pairs that descri
|
|
|
115
131
|
```
|
|
116
132
|
|
|
117
133
|
### config.json
|
|
134
|
+
|
|
118
135
|
This tells the style dictionary build system how and what to build. The default file path is `config.json` or `config.js` in the root of the project, but you can name it whatever you want by passing in the `--config` flag to the [CLI](https://amzn.github.io/style-dictionary/#/using_the_cli).
|
|
119
136
|
|
|
120
137
|
```json
|
|
@@ -124,36 +141,40 @@ This tells the style dictionary build system how and what to build. The default
|
|
|
124
141
|
"scss": {
|
|
125
142
|
"transformGroup": "scss",
|
|
126
143
|
"buildPath": "build/",
|
|
127
|
-
"files": [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
"files": [
|
|
145
|
+
{
|
|
146
|
+
"destination": "scss/_variables.scss",
|
|
147
|
+
"format": "scss/variables"
|
|
148
|
+
}
|
|
149
|
+
]
|
|
131
150
|
},
|
|
132
151
|
"android": {
|
|
133
152
|
"transformGroup": "android",
|
|
134
153
|
"buildPath": "build/android/",
|
|
135
|
-
"files": [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
"files": [
|
|
155
|
+
{
|
|
156
|
+
"destination": "font_dimens.xml",
|
|
157
|
+
"format": "android/fontDimens"
|
|
158
|
+
}
|
|
159
|
+
]
|
|
139
160
|
}
|
|
140
161
|
}
|
|
141
162
|
}
|
|
142
163
|
```
|
|
143
164
|
|
|
144
|
-
| Attribute
|
|
145
|
-
|
|
|
146
|
-
| source
|
|
147
|
-
| include
|
|
148
|
-
| platforms
|
|
149
|
-
| platform.transformGroup
|
|
150
|
-
| platform.transforms
|
|
151
|
-
| platform.buildPath
|
|
152
|
-
| platform.files
|
|
153
|
-
| platform.file.destination
|
|
154
|
-
| platform.file.format
|
|
155
|
-
| platform.file.options
|
|
156
|
-
| platform.file.options.showFileHeader | Boolean
|
|
165
|
+
| Attribute | Type | Description |
|
|
166
|
+
| :----------------------------------- | :---------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
167
|
+
| source | Array | An array of file path [globs](https://github.com/isaacs/node-glob) to design token files. Style Dictionary will do a deep merge of all of the token files, allowing you to organize your files files however you want. |
|
|
168
|
+
| include | Array | An array of file path [globs](https://github.com/isaacs/node-glob) to design token files that contain default styles. The Style Dictionary uses this as a base collection of tokens. The tokens found using the "source" attribute will overwrite tokens found using include. |
|
|
169
|
+
| platforms | Object | Sets of platform files to be built. |
|
|
170
|
+
| platform.transformGroup | String (optional) | Apply a group of transforms to the tokens, must either define this or `transforms`. |
|
|
171
|
+
| platform.transforms | Array (optional) | Transforms to apply sequentially to all tokens. Can be a built-in one or you can create your own. |
|
|
172
|
+
| platform.buildPath | String (optional) | Base path to build the files, must end with a trailing slash. |
|
|
173
|
+
| platform.files | Array (optional) | Files to be generated for this platform. |
|
|
174
|
+
| platform.file.destination | String (optional) | Location to build the file, will be appended to the buildPath. |
|
|
175
|
+
| platform.file.format | String (optional) | Format used to generate the file. Can be a built-in one or you can create your own. [More on formats](https://amzn.github.io/style-dictionary/#/formats) |
|
|
176
|
+
| platform.file.options | Object (optional) | A set of extra options associated with the file. |
|
|
177
|
+
| 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". |
|
|
157
178
|
|
|
158
179
|
### Design Tokens
|
|
159
180
|
|
|
@@ -161,10 +182,10 @@ This tells the style dictionary build system how and what to build. The default
|
|
|
161
182
|
{
|
|
162
183
|
"size": {
|
|
163
184
|
"font": {
|
|
164
|
-
"small"
|
|
185
|
+
"small": { "value": "10px" },
|
|
165
186
|
"medium": { "value": "16px" },
|
|
166
|
-
"large"
|
|
167
|
-
"base"
|
|
187
|
+
"large": { "value": "24px" },
|
|
188
|
+
"base": { "value": "{size.font.medium.value}" }
|
|
168
189
|
}
|
|
169
190
|
}
|
|
170
191
|
}
|
|
@@ -195,7 +216,6 @@ float const SizeFontLarge = 24.00f;
|
|
|
195
216
|
float const SizeFontBase = 16.00f;
|
|
196
217
|
```
|
|
197
218
|
|
|
198
|
-
|
|
199
219
|
## Quick Start
|
|
200
220
|
|
|
201
221
|
The style dictionary framework comes with some example code to get you started. Install the node module globally, create a directory and `cd` into it.
|
|
@@ -220,7 +240,6 @@ $ style-dictionary build
|
|
|
220
240
|
|
|
221
241
|
Take a look at the documentation for the example code.
|
|
222
242
|
|
|
223
|
-
|
|
224
243
|
## Design Tokens
|
|
225
244
|
|
|
226
245
|
A design token is an attribute to describe something visually. It is atomic (it cannot be broken down further). Design tokens have a name, a value, and optional attributes or metadata. The name of a token can be anything, but we have a proposed naming structure that we find works really well in the next section.
|
|
@@ -233,7 +252,7 @@ While not exactly necessary, we feel this classification structure of design tok
|
|
|
233
252
|
{
|
|
234
253
|
"size": {
|
|
235
254
|
"font": {
|
|
236
|
-
"base":
|
|
255
|
+
"base": { "value": "16" },
|
|
237
256
|
"large": { "value": "20" }
|
|
238
257
|
}
|
|
239
258
|
}
|
|
@@ -254,7 +273,7 @@ You can also add a _comment_ to a design token:
|
|
|
254
273
|
{
|
|
255
274
|
"size": {
|
|
256
275
|
"font": {
|
|
257
|
-
"base":
|
|
276
|
+
"base": {
|
|
258
277
|
"value": "16",
|
|
259
278
|
"comment": "the base size of the font"
|
|
260
279
|
},
|
|
@@ -267,8 +286,7 @@ You can also add a _comment_ to a design token:
|
|
|
267
286
|
}
|
|
268
287
|
```
|
|
269
288
|
|
|
270
|
-
The comment
|
|
271
|
-
|
|
289
|
+
The comment will appear in the output files, where relevant or the output format supports comments.
|
|
272
290
|
|
|
273
291
|
## Extending
|
|
274
292
|
|
|
@@ -280,12 +298,12 @@ const StyleDictionary = require('style-dictionary').extend('config.json');
|
|
|
280
298
|
StyleDictionary.registerTransform({
|
|
281
299
|
name: 'time/seconds',
|
|
282
300
|
type: 'value',
|
|
283
|
-
matcher: function(token) {
|
|
301
|
+
matcher: function (token) {
|
|
284
302
|
return token.attributes.category === 'time';
|
|
285
303
|
},
|
|
286
|
-
transformer: function(token) {
|
|
304
|
+
transformer: function (token) {
|
|
287
305
|
return (parseInt(token.original.value) / 1000).toString() + 's';
|
|
288
|
-
}
|
|
306
|
+
},
|
|
289
307
|
});
|
|
290
308
|
|
|
291
309
|
StyleDictionary.buildAllPlatforms();
|
|
@@ -303,7 +321,6 @@ The mascot for Style Dictionary is ["Pascal"](https://github.com/amzn/style-dict
|
|
|
303
321
|
|
|
304
322
|
Please help make this framework better. For more information take a look at [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
305
323
|
|
|
306
|
-
|
|
307
324
|
## License
|
|
308
325
|
|
|
309
326
|
[Apache 2.0](LICENSE)
|
package/bin/style-dictionary
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import JSON5 from 'json5';
|
|
6
|
+
import program from 'commander';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import node_fs from 'node:fs';
|
|
10
|
+
// usually also node:fs in this context, but can be customized by user
|
|
11
|
+
import { fs } from '../fs.js';
|
|
12
|
+
import StyleDictionary from '../index.js';
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
|
|
16
|
+
const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
11
17
|
|
|
12
18
|
function collect(val, arr) {
|
|
13
19
|
arr.push(val);
|
|
@@ -15,16 +21,14 @@ function collect(val, arr) {
|
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
function getConfigPath(options) {
|
|
18
|
-
|
|
24
|
+
let configPath = options.config;
|
|
19
25
|
|
|
20
|
-
if(!configPath) {
|
|
21
|
-
if(fs.existsSync('./config.json')) {
|
|
26
|
+
if (!configPath) {
|
|
27
|
+
if (fs.existsSync('./config.json')) {
|
|
22
28
|
configPath = './config.json';
|
|
23
|
-
}
|
|
24
|
-
else if(fs.existsSync('./config.js')) {
|
|
29
|
+
} else if (fs.existsSync('./config.js')) {
|
|
25
30
|
configPath = './config.js';
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
31
|
+
} else {
|
|
28
32
|
console.error('Build failed; unable to find config file.');
|
|
29
33
|
process.exit(1);
|
|
30
34
|
}
|
|
@@ -33,75 +37,88 @@ function getConfigPath(options) {
|
|
|
33
37
|
return configPath;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
program
|
|
37
|
-
.version(pkg.version)
|
|
38
|
-
.description(pkg.description)
|
|
39
|
-
.usage('[command] [options]');
|
|
40
|
-
|
|
40
|
+
program.version(pkg.version).description(pkg.description).usage('[command] [options]');
|
|
41
41
|
|
|
42
42
|
program
|
|
43
43
|
.command('build')
|
|
44
44
|
.description('Builds a style dictionary package from the current directory.')
|
|
45
45
|
.option('-c, --config <path>', 'set config path. defaults to ./config.json')
|
|
46
|
-
.option(
|
|
46
|
+
.option(
|
|
47
|
+
'-p, --platform [platform]',
|
|
48
|
+
'only build specific platforms. Must be defined in the config',
|
|
49
|
+
collect,
|
|
50
|
+
[],
|
|
51
|
+
)
|
|
47
52
|
.action(styleDictionaryBuild);
|
|
48
53
|
|
|
49
54
|
program
|
|
50
55
|
.command('clean')
|
|
51
|
-
.description(
|
|
56
|
+
.description(
|
|
57
|
+
'Removes files specified in the config of the style dictionary package of the current directory.',
|
|
58
|
+
)
|
|
52
59
|
.option('-c, --config <path>', 'set config path. defaults to ./config.json')
|
|
53
|
-
.option(
|
|
60
|
+
.option(
|
|
61
|
+
'-p, --platform [platform]',
|
|
62
|
+
'only clean specific platform(s). Must be defined in the config',
|
|
63
|
+
collect,
|
|
64
|
+
[],
|
|
65
|
+
)
|
|
54
66
|
.action(styleDictionaryClean);
|
|
55
67
|
|
|
56
68
|
program
|
|
57
69
|
.command('init <type>')
|
|
58
70
|
.description('Generates a starter style dictionary')
|
|
59
|
-
.action(function(type){
|
|
60
|
-
|
|
71
|
+
.action(function (type) {
|
|
72
|
+
const types = ['basic', 'complete'];
|
|
61
73
|
if (types.indexOf(type) < 0) {
|
|
62
74
|
console.error('Please supply 1 type of project from: ' + types.join(', '));
|
|
63
75
|
process.exit(1);
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
console.log('Copying starter files...\n');
|
|
67
|
-
|
|
79
|
+
node_fs.copySync(path.join(__dirname, '..', 'examples', type), process.cwd());
|
|
68
80
|
console.log('Source style dictionary starter files created!\n');
|
|
69
|
-
console.log(
|
|
81
|
+
console.log(
|
|
82
|
+
'Running `style-dictionary build` for the first time to generate build artifacts.\n',
|
|
83
|
+
);
|
|
70
84
|
styleDictionaryBuild();
|
|
71
85
|
});
|
|
72
86
|
|
|
73
87
|
// error on unknown commands
|
|
74
88
|
program.on('command:*', function () {
|
|
75
|
-
console.error(
|
|
89
|
+
console.error(
|
|
90
|
+
'Invalid command: %s\nSee --help for a list of available commands.',
|
|
91
|
+
process.argv.slice(2).join(' '),
|
|
92
|
+
);
|
|
76
93
|
process.exit(1);
|
|
77
94
|
});
|
|
78
95
|
|
|
79
|
-
function styleDictionaryBuild(options) {
|
|
96
|
+
async function styleDictionaryBuild(options) {
|
|
80
97
|
options = options || {};
|
|
81
|
-
|
|
98
|
+
const configPath = getConfigPath(options);
|
|
82
99
|
|
|
83
100
|
// Create a style dictionary object with the config
|
|
84
|
-
|
|
101
|
+
const styleDictionary = await StyleDictionary.extend(configPath);
|
|
85
102
|
|
|
86
103
|
if (options.platform && options.platform.length > 0) {
|
|
87
|
-
options.platform.forEach(function(platform) {
|
|
88
|
-
styleDictionary.buildPlatform(
|
|
104
|
+
options.platform.forEach(function (platform) {
|
|
105
|
+
styleDictionary.buildPlatform(platform);
|
|
89
106
|
});
|
|
90
107
|
} else {
|
|
91
108
|
styleDictionary.buildAllPlatforms();
|
|
92
109
|
}
|
|
93
110
|
}
|
|
94
111
|
|
|
95
|
-
function styleDictionaryClean(options) {
|
|
112
|
+
async function styleDictionaryClean(options) {
|
|
96
113
|
options = options || {};
|
|
97
|
-
|
|
114
|
+
const configPath = getConfigPath(options);
|
|
98
115
|
|
|
99
116
|
// Create a style dictionary object with the config
|
|
100
|
-
|
|
117
|
+
const styleDictionary = await StyleDictionary.extend(configPath);
|
|
101
118
|
|
|
102
119
|
if (options.platform && options.platform.length > 0) {
|
|
103
|
-
options.platform.forEach(function(platform) {
|
|
104
|
-
styleDictionary.cleanPlatform(
|
|
120
|
+
options.platform.forEach(function (platform) {
|
|
121
|
+
styleDictionary.cleanPlatform(platform);
|
|
105
122
|
});
|
|
106
123
|
} else {
|
|
107
124
|
styleDictionary.cleanAllPlatforms();
|
package/examples/README.md
CHANGED
|
@@ -13,42 +13,43 @@ $ style-dictionary init [example]
|
|
|
13
13
|
Where `[example]` is one of: `basic`, `complete`.
|
|
14
14
|
|
|
15
15
|
## Basic
|
|
16
|
+
|
|
16
17
|
[View on Github](https://github.com/amzn/style-dictionary/tree/main/examples/basic)
|
|
17
18
|
|
|
18
19
|
This example code is bare-bones to show you what this framework can do. Use this if you want to play around with what the Style Dictionary can do.
|
|
19
20
|
|
|
20
|
-
|
|
21
21
|
## Complete
|
|
22
|
+
|
|
22
23
|
[View on Github](https://github.com/amzn/style-dictionary/tree/main/examples/complete)
|
|
23
24
|
|
|
24
25
|
This is a more complete package and should have everything you need to get started. This package can be consumed as a Cocoapod on iOS, as a node module for web, and as a local library for Android.
|
|
25
26
|
|
|
26
27
|
## Advanced
|
|
28
|
+
|
|
27
29
|
[View the folder](https://github.com/amzn/style-dictionary/tree/main/examples/advanced)
|
|
28
30
|
|
|
29
31
|
If you want to look at more advanced examples of possible applications and customizations of Style Dictionary, the [`examples/advanced`](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/) folder on GitHub contains these extra folders:
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
- [**assets-base64-embed**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/assets-base64-embed) shows how it's possible to embed and distribute assets – like images, icons and fonts – directly as design tokens.
|
|
34
|
+
- [**auto-rebuild-watcher**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/auto-rebuild-watcher) shows how to setup a "watcher" that auto-rebuilds the tokens every time there is a change in the tokens.
|
|
35
|
+
- [**component-cti**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/component-cti) shows how to write component tokens and still use the CTI structure.
|
|
36
|
+
- [**create-react-app**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/create-react-app) shows how to integrate Style Dictionary into a React application.
|
|
37
|
+
- [**create-react-native-app**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/create-react-native-app) shows how to integrate Style Dictionary into a React Native application.
|
|
38
|
+
- [**custom-file-header**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/custom-file-header) shows how to define custom file headers and use them in output files.
|
|
39
|
+
- [**custom-formats-with-templates**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/custom-formats-with-templates) shows how to generate custom output formats using templates, useful when you need to distribute your design tokens into your own pipelines or scripts.
|
|
40
|
+
- [**custom-parser**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/custom-parser) shows how to use custom parsers for token files.
|
|
41
|
+
- [**custom-transforms**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/custom-transforms) shows how to use custom transforms (and transformGroups) to apply custom "transformations" to the design tokens.
|
|
42
|
+
- [**flutter**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/flutter) shows how to integrate with Flutter applications.
|
|
43
|
+
- [**matching-build-files**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/matching-build-files) shows how to output files 1-to-1 with source files.
|
|
44
|
+
- [**multi-brand-multi-platform**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/multi-brand-multi-platform) shows how to set up Style Dictionary to support a multi-brand (for brand theming) and multi-platform (web, iOS, Android) solution, with token values depending on brand and platforms.
|
|
45
|
+
- [**node-modules-as-config-and-properties**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/node-modules-as-config-and-properties) shows how to use Javascript rather than JSON for configuration and token files.
|
|
46
|
+
- [**npm-module**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/npm-module) shows how to set up a style dictionary as an npm module, either to publish to a local npm service or to publish externally.
|
|
47
|
+
- [**referencing_aliasing**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/referencing_aliasing) shows how to use referencing (or "aliasing") to reference a value -or an attribute– of a token and assign it to the value –or attribute– of another token.
|
|
48
|
+
- [**s3**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/s3) shows how to set up a style dictionary to build files for different platforms (web, iOS, Android) and upload those build artifacts, together with a group of assets, to an S3 bucket.
|
|
49
|
+
- [**tokens-deprecation**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/tokens-deprecation) shows one way to deprecate tokens by adding metadata to tokens and using custom formats to output comments in the generated files.
|
|
50
|
+
- [**transitive-transforms**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/transitive-transforms) shows how to use transitive transforms to transform references
|
|
51
|
+
- [**variables-in-outputs**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/variables-in-outputs) shows you how to use the `outputReferences` option to generate files variable references in them.
|
|
52
|
+
- [**yaml-tokens**](https://github.com/amzn/style-dictionary/tree/main/examples/advanced/yaml-tokens) shows how to use a custom parser to define your source files in YAML rather than JSON.
|
|
52
53
|
|
|
53
54
|
---
|
|
54
55
|
|
|
@@ -6,7 +6,7 @@ This means that you can centralize all your "core" design values in one single p
|
|
|
6
6
|
|
|
7
7
|
#### Running the example
|
|
8
8
|
|
|
9
|
-
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use
|
|
9
|
+
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use _yarn_, update the commands accordingly).
|
|
10
10
|
|
|
11
11
|
At this point, run `npm run build`. This command will generate the files in the `build` folder.
|
|
12
12
|
|
|
@@ -25,11 +25,13 @@ will be rendered as:
|
|
|
25
25
|
```
|
|
26
26
|
<img src="data:image/png;base64,PHN2ZyB4bWxucz0iaHR0..." />
|
|
27
27
|
```
|
|
28
|
+
|
|
28
29
|
and in **Sass** this code:
|
|
29
30
|
|
|
30
31
|
```
|
|
31
32
|
background-image: url('data:image/png;base64,$asset-image-logo');
|
|
32
33
|
```
|
|
34
|
+
|
|
33
35
|
will be rendered as:
|
|
34
36
|
|
|
35
37
|
```
|
|
@@ -38,7 +40,7 @@ background-image: url('data:image/png;base64,PHN2ZyB4bWxucz0iaHR0...');
|
|
|
38
40
|
|
|
39
41
|
#### What to look at
|
|
40
42
|
|
|
41
|
-
Open the `config.json` file and see how all the "assets/embed
|
|
43
|
+
Open the `config.json` file and see how all the "assets/embed/\*" platform blocks are configured:
|
|
42
44
|
|
|
43
45
|
```
|
|
44
46
|
"assets/embed/json": {
|
|
@@ -54,7 +56,7 @@ Open the `config.json` file and see how all the "assets/embed/*" platform blocks
|
|
|
54
56
|
...
|
|
55
57
|
```
|
|
56
58
|
|
|
57
|
-
Here there are **three specific transforms**:
|
|
59
|
+
Here there are **three specific transforms**: _attribute/cti_ to assign the Category/Type/Item attributes to the tokens, _name/cti/kebab_ to assign them the correct name, and finally _asset/base64_ to take the path declared in the "value" of the tokens, convert the file at that path in base64 format, and assign the output of the base64 conversion to the "value" of the token.
|
|
58
60
|
|
|
59
61
|
If you take for example the file `assets/icons.json` you will see this declaration:
|
|
60
62
|
|
|
@@ -64,6 +66,7 @@ If you take for example the file `assets/icons.json` you will see this declarati
|
|
|
64
66
|
"alert-circle": { "value": "assets/icons/alert-circle.svg" }
|
|
65
67
|
|
|
66
68
|
```
|
|
69
|
+
|
|
67
70
|
where the value of the `alert-circle` token is a path that points to the `alert-circle.svg` file in the `assets/icons/` folder.
|
|
68
71
|
|
|
69
72
|
Now, `build` the dictionary and open the generated file `build/scss/assets_icons.scss`, and you will see this result:
|
|
@@ -6,7 +6,7 @@ This is quite handy when there are continuous changes to the token values (e.g.
|
|
|
6
6
|
|
|
7
7
|
#### Running the example
|
|
8
8
|
|
|
9
|
-
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use
|
|
9
|
+
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use _yarn_, update the commands accordingly).
|
|
10
10
|
|
|
11
11
|
At this point, if you want to build once the tokens you can run `npm run build`. This command will generate the files in the `build` folder.
|
|
12
12
|
|
|
@@ -5,7 +5,7 @@ This example will show you one way to define component tokens in a simple way wh
|
|
|
5
5
|
```json
|
|
6
6
|
{
|
|
7
7
|
"size": {
|
|
8
|
-
"padding"
|
|
8
|
+
"padding": {
|
|
9
9
|
"button": { "value": "{size.padding.base.value}" }
|
|
10
10
|
},
|
|
11
11
|
"font": {
|
|
@@ -39,12 +39,12 @@ Instead, when defining component tokens it makes more sense to structure them mo
|
|
|
39
39
|
"button": {
|
|
40
40
|
"padding": { "value": "{size.padding.medium.value}" },
|
|
41
41
|
"font-size": { "value": 2 },
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
"primary": {
|
|
44
44
|
"background-color": { "value": "hsl(10, 80, 50)" },
|
|
45
45
|
"color": { "value": "{color.font.inverse.value}" }
|
|
46
46
|
},
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
"secondary": {
|
|
49
49
|
"background-color": { "value": "{color.background.primary.value}" },
|
|
50
50
|
"color": { "value": "{color.font.link.value}" }
|
|
@@ -56,14 +56,13 @@ Instead, when defining component tokens it makes more sense to structure them mo
|
|
|
56
56
|
|
|
57
57
|
### Running the example
|
|
58
58
|
|
|
59
|
-
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use
|
|
59
|
+
First of all, set up the required dependencies running the command `npm install` in your local CLI environment (if you prefer to use _yarn_, update the commands accordingly).
|
|
60
60
|
|
|
61
61
|
At this point, if you want to build the tokens run `npm run build`. This command will generate the files in the `build` folder.
|
|
62
62
|
|
|
63
|
-
|
|
64
63
|
### How does it work
|
|
65
64
|
|
|
66
|
-
All of the built-in transforms target tokens using the CTI attributes. The built-in [`attribute/cti`](https://amzn.github.io/style-dictionary/#/transforms?id=attributecti) transform adds the CTI attributes to each token based on the object path of the token. In this example we override the default behavior of the [`attribute/cti`](https://amzn.github.io/style-dictionary/#/transforms?id=attributecti) transform to apply CTI attributes based on token's key, or last part of the object path to generate the equivalent category and type. This way we can correctly map a token with an object path of `component.button.background-color` to a category of `color` and type of `background`.
|
|
65
|
+
All of the built-in transforms target tokens using the CTI attributes. The built-in [`attribute/cti`](https://amzn.github.io/style-dictionary/#/transforms?id=attributecti) transform adds the CTI attributes to each token based on the object path of the token. In this example we override the default behavior of the [`attribute/cti`](https://amzn.github.io/style-dictionary/#/transforms?id=attributecti) transform to apply CTI attributes based on token's key, or last part of the object path to generate the equivalent category and type. This way we can correctly map a token with an object path of `component.button.background-color` to a category of `color` and type of `background`.
|
|
67
66
|
|
|
68
67
|
Style Dictionary allows for extensibility through [monkey patching](https://en.wikipedia.org/wiki/Monkey_patch). This allows you to override the default behavior of the Style Dictionary library, and any built-in transforms and formats. You can override built-in transforms and formats by adding ones with the same name. Also, all of the built-in transforms, transformGroups, and formats are available by accessing them in the Style Dictionary library under the attributes `transform`, `transformGroup`, and `format` respectively. For example:
|
|
69
68
|
|
|
@@ -83,7 +82,7 @@ For example, if the key of the token (the last part of the object path) is "back
|
|
|
83
82
|
|
|
84
83
|
### What to look at
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
- `config.js`:
|
|
86
|
+
- `propertiesToCTI`: A plain object where we map the CSS property name to the proper category and type.
|
|
87
|
+
- `CTITransform`: A transform object that defines a transformer method, which will override the default `attribute/cti` transform. This is similar to creating a child class with some custom logic and then calling `super`. In the transformer function it first looks at the top-level namespace, the first item in the object path, and if it is 'component' we run our custom logic using the `propertiesToCTI` map. If it is not 'component', use the built-in `attribute/cti`.
|
|
88
|
+
- `tokens/component/button.json`: Take a look at how it defines the component tokens and uses the last part of the object path as the CSS property. Notice how we can define token values in here that are not references, but they still get transformed properly: font-size uses 'rem' and background-color uses hex in the output.
|