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.
Files changed (145) hide show
  1. package/README.md +8 -5
  2. package/bin/style-dictionary.d.ts +8 -0
  3. package/bin/style-dictionary.js +38 -10
  4. package/examples/advanced/assets-base64-embed/package.json +1 -1
  5. package/examples/advanced/create-react-app/package.json +1 -1
  6. package/examples/advanced/create-react-native-app/package.json +1 -1
  7. package/examples/advanced/create-react-native-app/src/App.js +0 -1
  8. package/examples/advanced/custom-parser/package.json +1 -1
  9. package/examples/advanced/custom-parser/sd.config.js +3 -2
  10. package/examples/advanced/custom-transforms/README.md +1 -1
  11. package/examples/advanced/custom-transforms/build.js +11 -8
  12. package/examples/advanced/custom-transforms/package.json +1 -1
  13. package/examples/advanced/font-face-rules/package.json +1 -1
  14. package/examples/advanced/font-face-rules/sd.config.js +2 -1
  15. package/examples/advanced/format-helpers/package.json +1 -1
  16. package/examples/advanced/format-helpers/sd.config.js +3 -2
  17. package/examples/advanced/matching-build-files/config.js +15 -10
  18. package/examples/advanced/matching-build-files/package.json +1 -1
  19. package/examples/advanced/multi-brand-multi-platform/build.js +10 -7
  20. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  21. package/examples/advanced/node-modules-as-config-and-properties/config.js +17 -12
  22. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  23. package/examples/advanced/npm-module/package.json +1 -1
  24. package/examples/advanced/referencing_aliasing/package.json +1 -1
  25. package/examples/advanced/s3/package.json +1 -1
  26. package/examples/advanced/tailwind-preset/README.md +94 -0
  27. package/examples/advanced/tailwind-preset/config/filter.js +3 -0
  28. package/examples/advanced/tailwind-preset/config/filter.test.js +12 -0
  29. package/examples/advanced/tailwind-preset/config/format.js +60 -0
  30. package/examples/advanced/tailwind-preset/config/transform.js +21 -0
  31. package/examples/advanced/tailwind-preset/config/transform.test.js +37 -0
  32. package/examples/advanced/tailwind-preset/config.js +55 -0
  33. package/examples/advanced/tailwind-preset/demo/index.html +27 -0
  34. package/examples/advanced/tailwind-preset/demo/input.css +3 -0
  35. package/examples/advanced/tailwind-preset/package.json +18 -0
  36. package/examples/advanced/tailwind-preset/tailwind.config.js +11 -0
  37. package/examples/advanced/tailwind-preset/tokens/tokens.json +49 -0
  38. package/examples/advanced/tokens-deprecation/build.js +2 -1
  39. package/examples/advanced/tokens-deprecation/package.json +1 -1
  40. package/examples/advanced/transitive-transforms/package.json +1 -1
  41. package/examples/advanced/transitive-transforms/sd.config.js +12 -9
  42. package/examples/advanced/variables-in-outputs/package.json +1 -1
  43. package/examples/advanced/variables-in-outputs/sd.config.js +10 -5
  44. package/examples/advanced/yaml-tokens/package.json +1 -1
  45. package/examples/advanced/yaml-tokens/sd.config.js +3 -2
  46. package/lib/Register.d.ts +2 -2
  47. package/lib/Register.js +6 -3
  48. package/lib/StyleDictionary.d.ts +20 -18
  49. package/lib/StyleDictionary.js +89 -71
  50. package/lib/cleanActions.d.ts +1 -1
  51. package/lib/cleanDir.d.ts +1 -1
  52. package/lib/cleanDir.js +2 -1
  53. package/lib/cleanDirs.d.ts +1 -1
  54. package/lib/cleanFile.d.ts +1 -6
  55. package/lib/cleanFile.js +5 -2
  56. package/lib/cleanFiles.d.ts +1 -1
  57. package/lib/common/actions.d.ts +20 -1
  58. package/lib/common/actions.js +8 -4
  59. package/lib/common/filters.d.ts +7 -1
  60. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
  61. package/lib/common/formatHelpers/createPropertyFormatter.js +26 -19
  62. package/lib/common/formatHelpers/fileHeader.d.ts +1 -1
  63. package/lib/common/formatHelpers/fileHeader.js +4 -2
  64. package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
  65. package/lib/common/formatHelpers/formattedVariables.js +3 -1
  66. package/lib/common/formatHelpers/getTypeScriptType.d.ts +2 -2
  67. package/lib/common/formatHelpers/minifyDictionary.d.ts +1 -1
  68. package/lib/common/formatHelpers/setComposeObjectProperties.d.ts +1 -1
  69. package/lib/common/formatHelpers/setSwiftFileProperties.d.ts +1 -1
  70. package/lib/common/formatHelpers/sortByReference.d.ts +1 -1
  71. package/lib/common/formats.js +235 -162
  72. package/lib/common/templates/compose/object.kt.template.js +8 -4
  73. package/lib/common/templates/css/fonts.css.template.js +2 -2
  74. package/lib/common/templates/scss/map-flat.template.js +4 -3
  75. package/lib/common/transformGroups.d.ts +209 -1
  76. package/lib/common/transformGroups.js +139 -93
  77. package/lib/common/transforms.d.ts +961 -1
  78. package/lib/common/transforms.js +113 -111
  79. package/lib/enums/actions.d.ts +4 -0
  80. package/lib/enums/actions.js +4 -0
  81. package/lib/enums/commentPositions.d.ts +4 -0
  82. package/lib/enums/commentPositions.js +4 -0
  83. package/lib/enums/commentStyles.d.ts +5 -0
  84. package/lib/enums/commentStyles.js +5 -0
  85. package/lib/enums/fileHeaderCommentStyles.d.ts +5 -0
  86. package/lib/enums/fileHeaderCommentStyles.js +5 -0
  87. package/lib/enums/formats.d.ts +46 -0
  88. package/lib/enums/formats.js +50 -0
  89. package/lib/enums/index.d.ts +12 -0
  90. package/lib/enums/index.js +12 -0
  91. package/lib/enums/logBrokenReferenceLevels.d.ts +5 -0
  92. package/lib/enums/logBrokenReferenceLevels.js +4 -0
  93. package/lib/enums/logVerbosityLevels.d.ts +6 -0
  94. package/lib/enums/logVerbosityLevels.js +5 -0
  95. package/lib/enums/logWarningLevels.d.ts +5 -0
  96. package/lib/enums/logWarningLevels.js +5 -0
  97. package/lib/enums/propertyFormatNames.d.ts +6 -0
  98. package/lib/enums/propertyFormatNames.js +6 -0
  99. package/lib/enums/transformGroups.d.ts +17 -0
  100. package/lib/enums/transformGroups.js +17 -0
  101. package/lib/enums/transformTypes.d.ts +5 -0
  102. package/lib/enums/transformTypes.js +5 -0
  103. package/lib/enums/transforms.d.ts +57 -0
  104. package/lib/enums/transforms.js +57 -0
  105. package/lib/filterTokens.d.ts +1 -1
  106. package/lib/filterTokens.js +5 -0
  107. package/lib/fs.d.ts +1 -1
  108. package/lib/fs.js +1 -1
  109. package/lib/performActions.d.ts +1 -1
  110. package/lib/resolve.d.ts +1 -1
  111. package/lib/resolve.js +4 -3
  112. package/lib/transform/config.js +3 -2
  113. package/lib/transform/object.d.ts +1 -1
  114. package/lib/transform/token.d.ts +1 -9
  115. package/lib/transform/token.js +10 -3
  116. package/lib/utils/cleanActions.d.ts +1 -1
  117. package/lib/utils/combineJSON.d.ts +1 -1
  118. package/lib/utils/combineJSON.js +12 -32
  119. package/lib/utils/convertToBase64.d.ts +1 -1
  120. package/lib/utils/convertToDTCG.d.ts +3 -3
  121. package/lib/utils/convertTokenData.d.ts +30 -0
  122. package/lib/utils/convertTokenData.js +123 -0
  123. package/lib/utils/deepExtend.d.ts +1 -1
  124. package/lib/utils/deepmerge.d.ts +1 -1
  125. package/lib/utils/expandObjectTokens.d.ts +2 -2
  126. package/lib/utils/expandObjectTokens.js +1 -1
  127. package/lib/utils/flattenTokens.d.ts +9 -5
  128. package/lib/utils/flattenTokens.js +28 -16
  129. package/lib/utils/index.d.ts +2 -1
  130. package/lib/utils/index.js +3 -0
  131. package/lib/utils/loadFile.d.ts +13 -0
  132. package/lib/utils/loadFile.js +89 -0
  133. package/lib/utils/preprocess.d.ts +1 -1
  134. package/lib/utils/references/defaults.d.ts +5 -1
  135. package/lib/utils/references/getName.d.ts +1 -1
  136. package/lib/utils/references/getReferences.d.ts +1 -1
  137. package/lib/utils/references/outputReferencesTransformed.js +1 -1
  138. package/lib/utils/references/resolveReferences.d.ts +2 -2
  139. package/lib/utils/references/usesReferences.d.ts +1 -1
  140. package/package.json +27 -16
  141. package/types/Config.d.ts +9 -3
  142. package/types/DesignToken.d.ts +6 -0
  143. package/types/File.d.ts +6 -2
  144. package/types/Format.d.ts +4 -1
  145. 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
- [![Watch the video](/docs/assets/fake_player.png)](http://youtu.be/1HREvonfqhY)
25
+ [![Watch the video](/docs/src/assets/fake_player.png)](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: 'scss',
100
+ transformGroup: transformGroups.scss,
99
101
  buildPath: 'build/',
100
102
  files: [
101
103
  {
102
104
  destination: 'variables.scss',
103
- format: 'scss/variables',
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: 'time/seconds',
300
- type: 'value',
302
+ name: transforms.timeSeconds,
303
+ type: transformTypes.value,
301
304
  filter: function (token) {
302
305
  return token.type === 'time';
303
306
  },
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ export type BuildOptions = {
3
+ config?: string;
4
+ platform?: string[];
5
+ verbose?: boolean;
6
+ warn?: boolean;
7
+ silent?: boolean;
8
+ };
@@ -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 program from 'commander';
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 ? 'verbose' : 'silent';
137
+ verbosity = options.verbose ? verbose : silent;
116
138
  }
117
139
  if (options.warn === false) {
118
- warnings = 'disabled';
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
- return Promise.all(options.platforms.map((platform) => sd.buildPlatform(platform)));
154
+ await Promise.all(options.platform.map((platform) => sd.buildPlatform(platform)));
130
155
  } else {
131
- return sd.buildAllPlatforms();
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
- return Promise.all(options.platforms.map((platform) => sd.cleanPlatform(platform)));
169
+ await Promise.all(options.platform.map((platform) => sd.cleanPlatform(platform)));
142
170
  } else {
143
- return sd.cleanAllPlatforms();
171
+ await sd.cleanAllPlatforms();
144
172
  }
145
173
  }
146
174
 
@@ -12,6 +12,6 @@
12
12
  "author": "",
13
13
  "license": "Apache-2.0",
14
14
  "devDependencies": {
15
- "style-dictionary": "^4.2.0"
15
+ "style-dictionary": "^4.3.1"
16
16
  }
17
17
  }
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "eslint-config-react-app": "^7.0.1",
15
- "style-dictionary": "^4.2.0"
15
+ "style-dictionary": "^4.3.1"
16
16
  },
17
17
  "resolutions": {
18
18
  "immer": "8.0.1",
@@ -29,7 +29,7 @@
29
29
  "eslint-config-react-app": "^7.0.1",
30
30
  "jest": "~25.2.6",
31
31
  "react-test-renderer": "~16.13.1",
32
- "style-dictionary": "^4.2.0"
32
+ "style-dictionary": "^4.3.1"
33
33
  },
34
34
  "jest": {
35
35
  "preset": "react-native"
@@ -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
  );
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^4.2.0"
13
+ "style-dictionary": "^4.3.1"
14
14
  }
15
15
  }
@@ -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: 'css',
54
+ transformGroup: transformGroups.css,
54
55
  buildPath: 'build/',
55
56
  files: [
56
57
  {
57
58
  destination: 'variables.css',
58
- format: 'css/variables',
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: 'value',
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: 'size/px', // notice: the name is an override of an existing predefined method (yes, you can do it)
14
- type: 'value',
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: 'value',
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: 'value',
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: 'value',
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: 'name',
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: ['attribute/cti', 'name/constant', 'size/px', 'color/css', 'time/seconds', 'ratio/%'],
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['scss'].concat(['size/px', 'ratio/%']),
88
+ transforms: StyleDictionary.transformGroup[transformGroups.scss].concat([sizePx, 'ratio/%']),
86
89
  });
87
90
 
88
91
  StyleDictionary.registerTransformGroup({
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^4.2.0"
19
+ "style-dictionary": "^4.3.1"
20
20
  }
21
21
  }
@@ -9,6 +9,6 @@
9
9
  },
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "^4.2.0"
12
+ "style-dictionary": "^4.3.1"
13
13
  }
14
14
  }
@@ -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: 'attribute',
8
+ type: transformTypes.attribute,
8
9
  transform: (prop) => ({
9
10
  category: prop.path[0],
10
11
  type: prop.path[1],
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "^4.2.0"
13
+ "style-dictionary": "^4.3.1"
14
14
  }
15
15
  }
@@ -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: 'short' })) +
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: 'scss',
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: ['attribute/cti', 'name/camel', 'size/px', 'color/hex'],
14
+ transforms: [attributeCti, nameCamel, sizePx, colorHex],
10
15
  files: tokens.map((tokenSet) => ({
11
16
  destination: `${tokenSet}.js`,
12
- format: 'javascript/es6',
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: ['attribute/cti', 'name/camel', 'size/px', 'color/hex'],
27
+ transforms: [attributeCti, nameCamel, sizePx, colorHex],
23
28
  files: [
24
29
  {
25
30
  destination: `index.js`,
26
- format: 'javascript/es6',
31
+ format: javascriptEs6,
27
32
  },
28
33
  ],
29
34
  },
30
35
  'cjs/category': {
31
36
  buildPath: 'build/js/cjs/',
32
- transforms: ['attribute/cti', 'name/camel', 'size/px', 'color/hex'],
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: ['attribute/cti', 'name/camel', 'size/px', 'color/hex'],
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: 'scss',
61
+ transformGroup: scss,
57
62
  buildPath: `build/scss/`,
58
63
  files: [
59
64
  {
60
65
  destination: `tokens.scss`,
61
- format: 'scss/variables',
66
+ format: scssVariables,
62
67
  },
63
68
  ],
64
69
  },
65
70
  // Web output in scss partialformat
66
71
  'scss/category': {
67
- transformGroup: 'scss',
72
+ transformGroup: scss,
68
73
  buildPath: `build/scss/`,
69
74
  files: tokens.map((tokenSet) => ({
70
75
  destination: `_${tokenSet}.scss`,
71
- format: 'scss/variables',
76
+ format: scssVariables,
72
77
  filter: {
73
78
  attributes: {
74
79
  category: tokenSet,
@@ -17,6 +17,6 @@
17
17
  "author": "Kelly Harrop <kn.harrop@gmail.com>",
18
18
  "license": "Apache-2.0",
19
19
  "devDependencies": {
20
- "style-dictionary": "^4.2.0"
20
+ "style-dictionary": "^4.3.1"
21
21
  }
22
22
  }
@@ -1,7 +1,10 @@
1
1
  import StyleDictionary from 'style-dictionary';
2
+ import { formats, transformGroups } from 'style-dictionary/enums';
2
3
 
3
- // HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
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: 'web',
17
+ transformGroup: web,
15
18
  buildPath: `build/web/${brand}/`,
16
19
  files: [
17
20
  {
18
21
  destination: 'tokens.scss',
19
- format: 'scss/variables',
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: 'android/colors',
32
+ format: androidColors,
30
33
  },
31
34
  {
32
35
  destination: 'tokens.dimens.xml',
33
- format: 'android/dimens',
36
+ format: androidDimens,
34
37
  },
35
38
  {
36
39
  destination: 'tokens.font_dimens.xml',
37
- format: 'android/fontDimens',
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: 'ios/macros',
50
+ format: iosMacros,
48
51
  },
49
52
  ],
50
53
  },
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^4.2.0"
19
+ "style-dictionary": "^4.3.1"
20
20
  }
21
21
  }
@@ -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: 'value',
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: 'name',
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: ['attribute/cti', 'myTransform', 'myRegisteredTransform', 'color/hex'],
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: 'css',
78
+ transformGroup: css,
74
79
  buildPath: buildPath,
75
80
  files: [
76
81
  {
77
82
  destination: 'variables.css',
78
- format: 'css/variables',
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.transformGroups.scss.concat('color/rgb'),
90
+ transforms: StyleDictionary.hooks.scss.concat(colorRgb),
86
91
  buildPath: buildPath,
87
92
  files: [
88
93
  {
89
94
  destination: 'variables.scss',
90
- format: 'scss/variables',
95
+ format: scssVariables,
91
96
  },
92
97
  ],
93
98
  },
94
99
 
95
100
  js: {
96
- transforms: StyleDictionary.hooks.transformGroups.js.concat('myRegisteredTransform'),
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: 'javascript/es6',
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: 'js',
117
+ transformGroup: js,
113
118
  buildPath: buildPath,
114
119
  files: [
115
120
  {
116
121
  destination: 'tokens.json',
117
- format: 'json',
122
+ format: json,
118
123
  },
119
124
  ],
120
125
  },
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/dbanksdesign/style-dictionary-node#readme",
22
22
  "devDependencies": {
23
- "style-dictionary": "^4.2.0",
23
+ "style-dictionary": "^4.3.1",
24
24
  "tinycolor2": "^1.4.1"
25
25
  }
26
26
  }
@@ -17,6 +17,6 @@
17
17
  "author": "",
18
18
  "license": "Apache-2.0",
19
19
  "devDependencies": {
20
- "style-dictionary": "^4.2.0"
20
+ "style-dictionary": "^4.3.1"
21
21
  }
22
22
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "^4.2.0"
19
+ "style-dictionary": "^4.3.1"
20
20
  }
21
21
  }