style-dictionary 4.2.0 → 4.3.1
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 +8 -5
- package/bin/style-dictionary.d.ts +8 -0
- package/bin/style-dictionary.js +38 -10
- package/examples/advanced/assets-base64-embed/package.json +1 -1
- package/examples/advanced/create-react-app/package.json +1 -1
- package/examples/advanced/create-react-native-app/package.json +1 -1
- package/examples/advanced/create-react-native-app/src/App.js +0 -1
- package/examples/advanced/custom-parser/package.json +1 -1
- package/examples/advanced/custom-parser/sd.config.js +3 -2
- package/examples/advanced/custom-transforms/README.md +1 -1
- package/examples/advanced/custom-transforms/build.js +11 -8
- package/examples/advanced/custom-transforms/package.json +1 -1
- package/examples/advanced/font-face-rules/package.json +1 -1
- package/examples/advanced/font-face-rules/sd.config.js +2 -1
- package/examples/advanced/format-helpers/package.json +1 -1
- package/examples/advanced/format-helpers/sd.config.js +3 -2
- package/examples/advanced/matching-build-files/config.js +15 -10
- package/examples/advanced/matching-build-files/package.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/build.js +10 -7
- package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/config.js +17 -12
- package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
- package/examples/advanced/npm-module/package.json +1 -1
- package/examples/advanced/referencing_aliasing/package.json +1 -1
- package/examples/advanced/s3/package.json +1 -1
- package/examples/advanced/tailwind-preset/README.md +94 -0
- package/examples/advanced/tailwind-preset/config/filter.js +3 -0
- package/examples/advanced/tailwind-preset/config/filter.test.js +12 -0
- package/examples/advanced/tailwind-preset/config/format.js +60 -0
- package/examples/advanced/tailwind-preset/config/transform.js +21 -0
- package/examples/advanced/tailwind-preset/config/transform.test.js +37 -0
- package/examples/advanced/tailwind-preset/config.js +55 -0
- package/examples/advanced/tailwind-preset/demo/index.html +27 -0
- package/examples/advanced/tailwind-preset/demo/input.css +3 -0
- package/examples/advanced/tailwind-preset/package.json +18 -0
- package/examples/advanced/tailwind-preset/tailwind.config.js +11 -0
- package/examples/advanced/tailwind-preset/tokens/tokens.json +49 -0
- package/examples/advanced/tokens-deprecation/build.js +2 -1
- package/examples/advanced/tokens-deprecation/package.json +1 -1
- package/examples/advanced/transitive-transforms/package.json +1 -1
- package/examples/advanced/transitive-transforms/sd.config.js +12 -9
- package/examples/advanced/variables-in-outputs/package.json +1 -1
- package/examples/advanced/variables-in-outputs/sd.config.js +10 -5
- package/examples/advanced/yaml-tokens/package.json +1 -1
- package/examples/advanced/yaml-tokens/sd.config.js +3 -2
- package/lib/Register.d.ts +2 -2
- package/lib/Register.js +6 -3
- package/lib/StyleDictionary.d.ts +20 -18
- package/lib/StyleDictionary.js +89 -71
- package/lib/cleanActions.d.ts +1 -1
- package/lib/cleanDir.d.ts +1 -1
- package/lib/cleanDir.js +2 -1
- package/lib/cleanDirs.d.ts +1 -1
- package/lib/cleanFile.d.ts +1 -6
- package/lib/cleanFile.js +5 -2
- package/lib/cleanFiles.d.ts +1 -1
- package/lib/common/actions.d.ts +20 -1
- package/lib/common/actions.js +8 -4
- package/lib/common/filters.d.ts +7 -1
- package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
- package/lib/common/formatHelpers/createPropertyFormatter.js +26 -19
- package/lib/common/formatHelpers/fileHeader.d.ts +1 -1
- package/lib/common/formatHelpers/fileHeader.js +4 -2
- package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
- package/lib/common/formatHelpers/formattedVariables.js +3 -1
- package/lib/common/formatHelpers/getTypeScriptType.d.ts +2 -2
- package/lib/common/formatHelpers/minifyDictionary.d.ts +1 -1
- package/lib/common/formatHelpers/setComposeObjectProperties.d.ts +1 -1
- package/lib/common/formatHelpers/setSwiftFileProperties.d.ts +1 -1
- package/lib/common/formatHelpers/sortByReference.d.ts +1 -1
- package/lib/common/formats.js +235 -162
- package/lib/common/templates/compose/object.kt.template.js +8 -4
- package/lib/common/templates/css/fonts.css.template.js +2 -2
- package/lib/common/templates/scss/map-flat.template.js +4 -3
- package/lib/common/transformGroups.d.ts +209 -1
- package/lib/common/transformGroups.js +139 -93
- package/lib/common/transforms.d.ts +961 -1
- package/lib/common/transforms.js +113 -111
- package/lib/enums/actions.d.ts +4 -0
- package/lib/enums/actions.js +4 -0
- package/lib/enums/commentPositions.d.ts +4 -0
- package/lib/enums/commentPositions.js +4 -0
- package/lib/enums/commentStyles.d.ts +5 -0
- package/lib/enums/commentStyles.js +5 -0
- package/lib/enums/fileHeaderCommentStyles.d.ts +5 -0
- package/lib/enums/fileHeaderCommentStyles.js +5 -0
- package/lib/enums/formats.d.ts +46 -0
- package/lib/enums/formats.js +50 -0
- package/lib/enums/index.d.ts +12 -0
- package/lib/enums/index.js +12 -0
- package/lib/enums/logBrokenReferenceLevels.d.ts +5 -0
- package/lib/enums/logBrokenReferenceLevels.js +4 -0
- package/lib/enums/logVerbosityLevels.d.ts +6 -0
- package/lib/enums/logVerbosityLevels.js +5 -0
- package/lib/enums/logWarningLevels.d.ts +5 -0
- package/lib/enums/logWarningLevels.js +5 -0
- package/lib/enums/propertyFormatNames.d.ts +6 -0
- package/lib/enums/propertyFormatNames.js +6 -0
- package/lib/enums/transformGroups.d.ts +17 -0
- package/lib/enums/transformGroups.js +17 -0
- package/lib/enums/transformTypes.d.ts +5 -0
- package/lib/enums/transformTypes.js +5 -0
- package/lib/enums/transforms.d.ts +57 -0
- package/lib/enums/transforms.js +57 -0
- package/lib/filterTokens.d.ts +1 -1
- package/lib/filterTokens.js +5 -0
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +1 -1
- package/lib/performActions.d.ts +1 -1
- package/lib/resolve.d.ts +1 -1
- package/lib/resolve.js +4 -3
- package/lib/transform/config.js +3 -2
- package/lib/transform/object.d.ts +1 -1
- package/lib/transform/token.d.ts +1 -9
- package/lib/transform/token.js +10 -3
- package/lib/utils/cleanActions.d.ts +1 -1
- package/lib/utils/combineJSON.d.ts +1 -1
- package/lib/utils/combineJSON.js +12 -32
- package/lib/utils/convertToBase64.d.ts +1 -1
- package/lib/utils/convertToDTCG.d.ts +3 -3
- package/lib/utils/convertTokenData.d.ts +30 -0
- package/lib/utils/convertTokenData.js +123 -0
- package/lib/utils/deepExtend.d.ts +1 -1
- package/lib/utils/deepmerge.d.ts +1 -1
- package/lib/utils/expandObjectTokens.d.ts +2 -2
- package/lib/utils/expandObjectTokens.js +1 -1
- package/lib/utils/flattenTokens.d.ts +9 -5
- package/lib/utils/flattenTokens.js +28 -16
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +3 -0
- package/lib/utils/loadFile.d.ts +13 -0
- package/lib/utils/loadFile.js +89 -0
- package/lib/utils/preprocess.d.ts +1 -1
- package/lib/utils/references/defaults.d.ts +5 -1
- package/lib/utils/references/getName.d.ts +1 -1
- package/lib/utils/references/getReferences.d.ts +1 -1
- package/lib/utils/references/outputReferencesTransformed.js +1 -1
- package/lib/utils/references/resolveReferences.d.ts +2 -2
- package/lib/utils/references/usesReferences.d.ts +1 -1
- package/package.json +27 -16
- package/types/Config.d.ts +9 -3
- package/types/DesignToken.d.ts +6 -0
- package/types/File.d.ts +6 -2
- package/types/Format.d.ts +4 -1
- package/types/Transform.d.ts +4 -3
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ For detailed usage head to https://amzn.github.io/style-dictionary
|
|
|
22
22
|
|
|
23
23
|
## Watch the Demo on YouTube
|
|
24
24
|
|
|
25
|
-
[](http://youtu.be/1HREvonfqhY)
|
|
25
|
+
[](http://youtu.be/1HREvonfqhY)
|
|
26
26
|
|
|
27
27
|
## Experiment in the playground
|
|
28
28
|
|
|
@@ -91,16 +91,18 @@ StyleDictionary.buildAllPlatforms();
|
|
|
91
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
92
|
|
|
93
93
|
```javascript
|
|
94
|
+
import { formats, transformGroups } from 'style-dictionary/enums';
|
|
95
|
+
|
|
94
96
|
const StyleDictionary = require('style-dictionary').extend({
|
|
95
97
|
source: ['tokens/**/*.json'],
|
|
96
98
|
platforms: {
|
|
97
99
|
scss: {
|
|
98
|
-
transformGroup:
|
|
100
|
+
transformGroup: transformGroups.scss,
|
|
99
101
|
buildPath: 'build/',
|
|
100
102
|
files: [
|
|
101
103
|
{
|
|
102
104
|
destination: 'variables.scss',
|
|
103
|
-
format:
|
|
105
|
+
format: formats.scssVariables,
|
|
104
106
|
},
|
|
105
107
|
],
|
|
106
108
|
},
|
|
@@ -294,10 +296,11 @@ The style dictionary build system is made to be extended. We don't know exactly
|
|
|
294
296
|
|
|
295
297
|
```javascript
|
|
296
298
|
const StyleDictionary = require('style-dictionary').extend('config.json');
|
|
299
|
+
import { transforms, transformTypes } from 'style-dictionary/enums';
|
|
297
300
|
|
|
298
301
|
StyleDictionary.registerTransform({
|
|
299
|
-
name:
|
|
300
|
-
type:
|
|
302
|
+
name: transforms.timeSeconds,
|
|
303
|
+
type: transformTypes.value,
|
|
301
304
|
filter: function (token) {
|
|
302
305
|
return token.type === 'time';
|
|
303
306
|
},
|
package/bin/style-dictionary.js
CHANGED
|
@@ -6,20 +6,39 @@ import path from 'node:path';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import node_fs from 'node:fs';
|
|
8
8
|
import JSON5 from 'json5';
|
|
9
|
-
import
|
|
9
|
+
import { Command } from 'commander';
|
|
10
10
|
// usually also node:fs in this context, but can be customized by user
|
|
11
11
|
import { fs } from 'style-dictionary/fs';
|
|
12
12
|
import StyleDictionary from 'style-dictionary';
|
|
13
|
-
|
|
13
|
+
import { logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* config?: string;
|
|
18
|
+
* platform?: string[];
|
|
19
|
+
* verbose?: boolean;
|
|
20
|
+
* warn?: boolean;
|
|
21
|
+
* silent?: boolean;
|
|
22
|
+
* }} BuildOptions
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const program = new Command();
|
|
14
26
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
|
|
27
|
+
const { silent, verbose } = logVerbosityLevels;
|
|
16
28
|
const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
17
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} val
|
|
32
|
+
* @param {string[]} arr
|
|
33
|
+
*/
|
|
18
34
|
function collect(val, arr) {
|
|
19
35
|
arr.push(val);
|
|
20
36
|
return arr;
|
|
21
37
|
}
|
|
22
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {BuildOptions} options
|
|
41
|
+
*/
|
|
23
42
|
function getConfigPath(options) {
|
|
24
43
|
let configPath = options.config;
|
|
25
44
|
|
|
@@ -95,7 +114,6 @@ program
|
|
|
95
114
|
console.log(
|
|
96
115
|
'Running `style-dictionary build` for the first time to generate build artifacts.\n',
|
|
97
116
|
);
|
|
98
|
-
/* eslint-disable no-console */
|
|
99
117
|
styleDictionaryBuild();
|
|
100
118
|
});
|
|
101
119
|
|
|
@@ -108,39 +126,49 @@ program.on('command:*', function () {
|
|
|
108
126
|
process.exit(1);
|
|
109
127
|
});
|
|
110
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} configPath
|
|
131
|
+
* @param {BuildOptions} options
|
|
132
|
+
*/
|
|
111
133
|
function getSD(configPath, options) {
|
|
112
134
|
let verbosity;
|
|
113
135
|
let warnings;
|
|
114
136
|
if (options.verbose || options.silent) {
|
|
115
|
-
verbosity = options.verbose ?
|
|
137
|
+
verbosity = options.verbose ? verbose : silent;
|
|
116
138
|
}
|
|
117
139
|
if (options.warn === false) {
|
|
118
|
-
warnings =
|
|
140
|
+
warnings = logWarningLevels.disabled;
|
|
119
141
|
}
|
|
120
142
|
return new StyleDictionary(configPath, { verbosity, warnings });
|
|
121
143
|
}
|
|
122
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @param {BuildOptions} [options]
|
|
147
|
+
*/
|
|
123
148
|
async function styleDictionaryBuild(options) {
|
|
124
149
|
options = options || {};
|
|
125
150
|
const configPath = getConfigPath(options);
|
|
126
151
|
const sd = getSD(configPath, options);
|
|
127
152
|
|
|
128
153
|
if (options.platform && options.platform.length > 0) {
|
|
129
|
-
|
|
154
|
+
await Promise.all(options.platform.map((platform) => sd.buildPlatform(platform)));
|
|
130
155
|
} else {
|
|
131
|
-
|
|
156
|
+
await sd.buildAllPlatforms();
|
|
132
157
|
}
|
|
133
158
|
}
|
|
134
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @param {BuildOptions} [options]
|
|
162
|
+
*/
|
|
135
163
|
async function styleDictionaryClean(options) {
|
|
136
164
|
options = options || {};
|
|
137
165
|
const configPath = getConfigPath(options);
|
|
138
166
|
const sd = getSD(configPath, options);
|
|
139
167
|
|
|
140
168
|
if (options.platform && options.platform.length > 0) {
|
|
141
|
-
|
|
169
|
+
await Promise.all(options.platform.map((platform) => sd.cleanPlatform(platform)));
|
|
142
170
|
} else {
|
|
143
|
-
|
|
171
|
+
await sd.cleanAllPlatforms();
|
|
144
172
|
}
|
|
145
173
|
}
|
|
146
174
|
|
|
@@ -8,7 +8,6 @@ export default function App() {
|
|
|
8
8
|
<View style={styles.container}>
|
|
9
9
|
<Text style={styles.title}>Testing! Testing!</Text>
|
|
10
10
|
<Text style={styles.p}>All done!</Text>
|
|
11
|
-
{/* eslint-disable-next-line react/style-prop-object */}
|
|
12
11
|
<StatusBar style="auto" />
|
|
13
12
|
</View>
|
|
14
13
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
|
+
import { formats, transformGroups } from 'style-dictionary/enums';
|
|
2
3
|
|
|
3
4
|
// You can use the .registerParser() method like this
|
|
4
5
|
StyleDictionary.registerParser({
|
|
@@ -50,12 +51,12 @@ export default {
|
|
|
50
51
|
source: [`tokens/**/*.json`],
|
|
51
52
|
platforms: {
|
|
52
53
|
css: {
|
|
53
|
-
transformGroup:
|
|
54
|
+
transformGroup: transformGroups.css,
|
|
54
55
|
buildPath: 'build/',
|
|
55
56
|
files: [
|
|
56
57
|
{
|
|
57
58
|
destination: 'variables.css',
|
|
58
|
-
format:
|
|
59
|
+
format: formats.cssVariables,
|
|
59
60
|
},
|
|
60
61
|
],
|
|
61
62
|
},
|
|
@@ -24,7 +24,7 @@ To declare a custom **transform**, you have to call the `registerTransform` meth
|
|
|
24
24
|
```js
|
|
25
25
|
StyleDictionary.registerTransform({
|
|
26
26
|
name: 'ratio/%',
|
|
27
|
-
type:
|
|
27
|
+
type: transformTypes.value,
|
|
28
28
|
filter: function (token) {
|
|
29
29
|
return token.group === 'ratio';
|
|
30
30
|
},
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
+
import { transforms, transformGroups, transformTypes } from 'style-dictionary/enums';
|
|
4
5
|
|
|
5
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const { attributeCti, nameConstant, sizePx, colorCss, timeSeconds } = transforms;
|
|
8
|
+
const { value: transformTypeValue, name } = transformTypes;
|
|
6
9
|
|
|
7
10
|
console.log('Build started...');
|
|
8
11
|
console.log('\n==============================================');
|
|
@@ -10,8 +13,8 @@ console.log('\n==============================================');
|
|
|
10
13
|
// REGISTER THE CUSTOM TRANSFORMS
|
|
11
14
|
|
|
12
15
|
StyleDictionary.registerTransform({
|
|
13
|
-
name:
|
|
14
|
-
type:
|
|
16
|
+
name: sizePx, // notice: the name is an override of an existing predefined method (yes, you can do it)
|
|
17
|
+
type: transformTypeValue,
|
|
15
18
|
filter: function (token) {
|
|
16
19
|
// this is an example of a possible filter (based on the "cti" values) to show how a "filter" works
|
|
17
20
|
return token.type === 'fontSize' || token.type === 'dimension';
|
|
@@ -23,7 +26,7 @@ StyleDictionary.registerTransform({
|
|
|
23
26
|
|
|
24
27
|
StyleDictionary.registerTransform({
|
|
25
28
|
name: 'ratio/%',
|
|
26
|
-
type:
|
|
29
|
+
type: transformTypeValue,
|
|
27
30
|
filter: function (token) {
|
|
28
31
|
// here we are using a custom attribute, declared in the token, to match the values where apply the transform
|
|
29
32
|
return token.type === 'ratio';
|
|
@@ -35,7 +38,7 @@ StyleDictionary.registerTransform({
|
|
|
35
38
|
|
|
36
39
|
StyleDictionary.registerTransform({
|
|
37
40
|
name: 'hexRGB/hexARGB',
|
|
38
|
-
type:
|
|
41
|
+
type: transformTypeValue,
|
|
39
42
|
filter: function (token) {
|
|
40
43
|
return token.type === 'color';
|
|
41
44
|
},
|
|
@@ -47,7 +50,7 @@ StyleDictionary.registerTransform({
|
|
|
47
50
|
|
|
48
51
|
StyleDictionary.registerTransform({
|
|
49
52
|
name: 'unitless/sp',
|
|
50
|
-
type:
|
|
53
|
+
type: transformTypeValue,
|
|
51
54
|
filter: function (token) {
|
|
52
55
|
return token.type === 'fontSize';
|
|
53
56
|
},
|
|
@@ -60,7 +63,7 @@ StyleDictionary.registerTransform({
|
|
|
60
63
|
StyleDictionary.registerTransform({
|
|
61
64
|
// this is a silly example, to show how you can apply transform to names
|
|
62
65
|
name: 'name/squiggle',
|
|
63
|
-
type:
|
|
66
|
+
type: name,
|
|
64
67
|
// notice: if you don't specify a filter, the transformation will be applied to all the tokens
|
|
65
68
|
transform: function (token) {
|
|
66
69
|
return token.path.join('~');
|
|
@@ -75,14 +78,14 @@ StyleDictionary.registerTransform({
|
|
|
75
78
|
StyleDictionary.registerTransformGroup({
|
|
76
79
|
name: 'custom/web',
|
|
77
80
|
// notice: here the "size/px" transform is not the pre-defined one, but the custom one we have declared above
|
|
78
|
-
transforms: [
|
|
81
|
+
transforms: [attributeCti, nameConstant, sizePx, colorCss, timeSeconds, 'ratio/%'],
|
|
79
82
|
});
|
|
80
83
|
|
|
81
84
|
StyleDictionary.registerTransformGroup({
|
|
82
85
|
name: 'custom/scss',
|
|
83
86
|
// this is to show one possibility for adding a few transforms to a pre-defined group
|
|
84
87
|
// (however, we suggest to use the previous approach, which is more explicit and clear)
|
|
85
|
-
transforms: StyleDictionary.transformGroup[
|
|
88
|
+
transforms: StyleDictionary.transformGroup[transformGroups.scss].concat([sizePx, 'ratio/%']),
|
|
86
89
|
});
|
|
87
90
|
|
|
88
91
|
StyleDictionary.registerTransformGroup({
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
|
+
import { transformTypes } from 'style-dictionary/enums';
|
|
2
3
|
|
|
3
4
|
// Register an "attribute" transform to codify the font's details
|
|
4
5
|
// as named attributes.
|
|
5
6
|
StyleDictionary.registerTransform({
|
|
6
7
|
name: 'attribute/font',
|
|
7
|
-
type:
|
|
8
|
+
type: transformTypes.attribute,
|
|
8
9
|
transform: (prop) => ({
|
|
9
10
|
category: prop.path[0],
|
|
10
11
|
type: prop.path[1],
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
formattedVariables,
|
|
5
5
|
sortByReference,
|
|
6
6
|
} from 'style-dictionary/utils';
|
|
7
|
+
import { commentStyles, transformGroups } from 'style-dictionary/enums';
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
hooks: {
|
|
@@ -29,7 +30,7 @@ export default {
|
|
|
29
30
|
// proper style. If the file has a custom file header defined, or
|
|
30
31
|
// showFileHeader option, it will honor those.
|
|
31
32
|
return (
|
|
32
|
-
(await fileHeader({ file, commentStyle:
|
|
33
|
+
(await fileHeader({ file, commentStyle: commentStyles.short })) +
|
|
33
34
|
dictionary.allTokens
|
|
34
35
|
// sortByReference returns a function that can be used as to sort
|
|
35
36
|
// an array. This will sort the array so that references always
|
|
@@ -76,7 +77,7 @@ export default {
|
|
|
76
77
|
source: ['tokens/**/*'],
|
|
77
78
|
platforms: {
|
|
78
79
|
scss: {
|
|
79
|
-
transformGroup:
|
|
80
|
+
transformGroup: transformGroups.scss,
|
|
80
81
|
buildPath: 'build/',
|
|
81
82
|
files: [
|
|
82
83
|
{
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
|
+
import { formats, transforms, transformGroups } from 'style-dictionary/enums';
|
|
2
3
|
import tokens from './tokens/index.js';
|
|
3
4
|
|
|
5
|
+
const { javascriptEs6, scssVariables } = formats;
|
|
6
|
+
const { attributeCti, nameCamel, sizePx, colorHex } = transforms;
|
|
7
|
+
const { scss } = transformGroups;
|
|
8
|
+
|
|
4
9
|
export default {
|
|
5
10
|
source: ['tokens/**/*.json'],
|
|
6
11
|
platforms: {
|
|
7
12
|
'esm/category': {
|
|
8
13
|
buildPath: 'build/js/esm/',
|
|
9
|
-
transforms: [
|
|
14
|
+
transforms: [attributeCti, nameCamel, sizePx, colorHex],
|
|
10
15
|
files: tokens.map((tokenSet) => ({
|
|
11
16
|
destination: `${tokenSet}.js`,
|
|
12
|
-
format:
|
|
17
|
+
format: javascriptEs6,
|
|
13
18
|
filter: {
|
|
14
19
|
attributes: {
|
|
15
20
|
category: tokenSet,
|
|
@@ -19,17 +24,17 @@ export default {
|
|
|
19
24
|
},
|
|
20
25
|
'esm/index': {
|
|
21
26
|
buildPath: 'build/js/esm/',
|
|
22
|
-
transforms: [
|
|
27
|
+
transforms: [attributeCti, nameCamel, sizePx, colorHex],
|
|
23
28
|
files: [
|
|
24
29
|
{
|
|
25
30
|
destination: `index.js`,
|
|
26
|
-
format:
|
|
31
|
+
format: javascriptEs6,
|
|
27
32
|
},
|
|
28
33
|
],
|
|
29
34
|
},
|
|
30
35
|
'cjs/category': {
|
|
31
36
|
buildPath: 'build/js/cjs/',
|
|
32
|
-
transforms: [
|
|
37
|
+
transforms: [attributeCti, nameCamel, sizePx, colorHex],
|
|
33
38
|
files: tokens.map((tokenSet) => ({
|
|
34
39
|
destination: `${tokenSet}.js`,
|
|
35
40
|
format: 'custom/cjsmodule',
|
|
@@ -42,7 +47,7 @@ export default {
|
|
|
42
47
|
},
|
|
43
48
|
'cjs/index': {
|
|
44
49
|
buildPath: 'build/js/cjs/',
|
|
45
|
-
transforms: [
|
|
50
|
+
transforms: [attributeCti, nameCamel, sizePx, colorHex],
|
|
46
51
|
files: [
|
|
47
52
|
{
|
|
48
53
|
destination: `index.js`,
|
|
@@ -53,22 +58,22 @@ export default {
|
|
|
53
58
|
|
|
54
59
|
// Web output in scss format
|
|
55
60
|
scss: {
|
|
56
|
-
transformGroup:
|
|
61
|
+
transformGroup: scss,
|
|
57
62
|
buildPath: `build/scss/`,
|
|
58
63
|
files: [
|
|
59
64
|
{
|
|
60
65
|
destination: `tokens.scss`,
|
|
61
|
-
format:
|
|
66
|
+
format: scssVariables,
|
|
62
67
|
},
|
|
63
68
|
],
|
|
64
69
|
},
|
|
65
70
|
// Web output in scss partialformat
|
|
66
71
|
'scss/category': {
|
|
67
|
-
transformGroup:
|
|
72
|
+
transformGroup: scss,
|
|
68
73
|
buildPath: `build/scss/`,
|
|
69
74
|
files: tokens.map((tokenSet) => ({
|
|
70
75
|
destination: `_${tokenSet}.scss`,
|
|
71
|
-
format:
|
|
76
|
+
format: scssVariables,
|
|
72
77
|
filter: {
|
|
73
78
|
attributes: {
|
|
74
79
|
category: tokenSet,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
|
+
import { formats, transformGroups } from 'style-dictionary/enums';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const { androidColors, androidDimens, androidFontDimens, iosMacros, scssVariables } = formats;
|
|
5
|
+
const { web } = transformGroups;
|
|
4
6
|
|
|
7
|
+
// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
|
|
5
8
|
function getStyleDictionaryConfig(brand, platform) {
|
|
6
9
|
return {
|
|
7
10
|
source: [
|
|
@@ -11,12 +14,12 @@ function getStyleDictionaryConfig(brand, platform) {
|
|
|
11
14
|
],
|
|
12
15
|
platforms: {
|
|
13
16
|
web: {
|
|
14
|
-
transformGroup:
|
|
17
|
+
transformGroup: web,
|
|
15
18
|
buildPath: `build/web/${brand}/`,
|
|
16
19
|
files: [
|
|
17
20
|
{
|
|
18
21
|
destination: 'tokens.scss',
|
|
19
|
-
format:
|
|
22
|
+
format: scssVariables,
|
|
20
23
|
},
|
|
21
24
|
],
|
|
22
25
|
},
|
|
@@ -26,15 +29,15 @@ function getStyleDictionaryConfig(brand, platform) {
|
|
|
26
29
|
files: [
|
|
27
30
|
{
|
|
28
31
|
destination: 'tokens.colors.xml',
|
|
29
|
-
format:
|
|
32
|
+
format: androidColors,
|
|
30
33
|
},
|
|
31
34
|
{
|
|
32
35
|
destination: 'tokens.dimens.xml',
|
|
33
|
-
format:
|
|
36
|
+
format: androidDimens,
|
|
34
37
|
},
|
|
35
38
|
{
|
|
36
39
|
destination: 'tokens.font_dimens.xml',
|
|
37
|
-
format:
|
|
40
|
+
format: androidFontDimens,
|
|
38
41
|
},
|
|
39
42
|
],
|
|
40
43
|
},
|
|
@@ -44,7 +47,7 @@ function getStyleDictionaryConfig(brand, platform) {
|
|
|
44
47
|
files: [
|
|
45
48
|
{
|
|
46
49
|
destination: 'tokens.h',
|
|
47
|
-
format:
|
|
50
|
+
format: iosMacros,
|
|
48
51
|
},
|
|
49
52
|
],
|
|
50
53
|
},
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import StyleDictionary from 'style-dictionary';
|
|
2
|
+
import { formats, transforms, transformGroups, transformTypes } from 'style-dictionary/enums';
|
|
3
|
+
import tokens from './tokens.js';
|
|
2
4
|
// Rather than have Style Dictionary handle the merging of token files,
|
|
3
5
|
// you could use node module export/require to do it yourself. This will
|
|
4
6
|
// allow you to not have to copy object namespaces like you normally would.
|
|
5
7
|
// Take a look at any of the .js files in components/ or tokens/
|
|
6
|
-
import tokens from './tokens.js';
|
|
7
8
|
|
|
9
|
+
const { cssVariables, scssVariables, javascriptEs6, json } = formats;
|
|
10
|
+
const { css, js } = transformGroups;
|
|
11
|
+
const { attributeCti, colorHex, colorRgb } = transforms;
|
|
12
|
+
const { value: transformTypeValue, name } = transformTypes;
|
|
8
13
|
const buildPath = 'build/';
|
|
9
14
|
|
|
10
15
|
// You can still add custom transforms and formats like you
|
|
11
16
|
// normally would and reference them in the config below.
|
|
12
17
|
StyleDictionary.registerTransform({
|
|
13
18
|
name: 'myRegisteredTransform',
|
|
14
|
-
type:
|
|
19
|
+
type: transformTypeValue,
|
|
15
20
|
filter: (token) => token.attributes.category === 'size',
|
|
16
21
|
transform: (token) => `${parseInt(token.value) * 16}px`,
|
|
17
22
|
});
|
|
@@ -39,7 +44,7 @@ export default {
|
|
|
39
44
|
transforms: {
|
|
40
45
|
// Now we can use the transform 'myTransform' below
|
|
41
46
|
myTransform: {
|
|
42
|
-
type:
|
|
47
|
+
type: name,
|
|
43
48
|
transform: (token) => token.path.join('_').toUpperCase(),
|
|
44
49
|
},
|
|
45
50
|
},
|
|
@@ -58,7 +63,7 @@ export default {
|
|
|
58
63
|
platforms: {
|
|
59
64
|
custom: {
|
|
60
65
|
// Using the custom transforms we defined above
|
|
61
|
-
transforms: [
|
|
66
|
+
transforms: [attributeCti, 'myTransform', 'myRegisteredTransform', colorHex],
|
|
62
67
|
buildPath: buildPath,
|
|
63
68
|
files: [
|
|
64
69
|
{
|
|
@@ -70,30 +75,30 @@ export default {
|
|
|
70
75
|
},
|
|
71
76
|
|
|
72
77
|
css: {
|
|
73
|
-
transformGroup:
|
|
78
|
+
transformGroup: css,
|
|
74
79
|
buildPath: buildPath,
|
|
75
80
|
files: [
|
|
76
81
|
{
|
|
77
82
|
destination: 'variables.css',
|
|
78
|
-
format:
|
|
83
|
+
format: cssVariables,
|
|
79
84
|
},
|
|
80
85
|
],
|
|
81
86
|
},
|
|
82
87
|
|
|
83
88
|
scss: {
|
|
84
89
|
// This works, we can create new transform arrays on the fly and edit built-ins
|
|
85
|
-
transforms: StyleDictionary.hooks.
|
|
90
|
+
transforms: StyleDictionary.hooks.scss.concat(colorRgb),
|
|
86
91
|
buildPath: buildPath,
|
|
87
92
|
files: [
|
|
88
93
|
{
|
|
89
94
|
destination: 'variables.scss',
|
|
90
|
-
format:
|
|
95
|
+
format: scssVariables,
|
|
91
96
|
},
|
|
92
97
|
],
|
|
93
98
|
},
|
|
94
99
|
|
|
95
100
|
js: {
|
|
96
|
-
transforms: StyleDictionary.hooks.
|
|
101
|
+
transforms: StyleDictionary.hooks.js.concat('myRegisteredTransform'),
|
|
97
102
|
buildPath: buildPath,
|
|
98
103
|
// If you want to get super fancy, you can use node modules
|
|
99
104
|
// to create a tokens object first, and then you can
|
|
@@ -101,7 +106,7 @@ export default {
|
|
|
101
106
|
// output 1 file per color namespace.
|
|
102
107
|
files: Object.keys(tokens.color).map((colorType) => ({
|
|
103
108
|
destination: `${colorType}.js`,
|
|
104
|
-
format:
|
|
109
|
+
format: javascriptEs6,
|
|
105
110
|
// Filters can be functions that return a boolean
|
|
106
111
|
filter: (token) => token.attributes.type === colorType,
|
|
107
112
|
})),
|
|
@@ -109,12 +114,12 @@ export default {
|
|
|
109
114
|
|
|
110
115
|
// You can still use built-in transformGroups and formats like before
|
|
111
116
|
json: {
|
|
112
|
-
transformGroup:
|
|
117
|
+
transformGroup: js,
|
|
113
118
|
buildPath: buildPath,
|
|
114
119
|
files: [
|
|
115
120
|
{
|
|
116
121
|
destination: 'tokens.json',
|
|
117
|
-
format:
|
|
122
|
+
format: json,
|
|
118
123
|
},
|
|
119
124
|
],
|
|
120
125
|
},
|