style-dictionary 4.2.0 → 4.3.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.
Files changed (144) hide show
  1. package/README.md +8 -5
  2. package/bin/style-dictionary.js +4 -4
  3. package/examples/advanced/assets-base64-embed/package.json +1 -1
  4. package/examples/advanced/create-react-app/package.json +1 -1
  5. package/examples/advanced/create-react-native-app/package.json +1 -1
  6. package/examples/advanced/create-react-native-app/src/App.js +0 -1
  7. package/examples/advanced/custom-parser/package.json +1 -1
  8. package/examples/advanced/custom-parser/sd.config.js +3 -2
  9. package/examples/advanced/custom-transforms/README.md +1 -1
  10. package/examples/advanced/custom-transforms/build.js +11 -8
  11. package/examples/advanced/custom-transforms/package.json +1 -1
  12. package/examples/advanced/font-face-rules/package.json +1 -1
  13. package/examples/advanced/font-face-rules/sd.config.js +2 -1
  14. package/examples/advanced/format-helpers/package.json +1 -1
  15. package/examples/advanced/format-helpers/sd.config.js +3 -2
  16. package/examples/advanced/matching-build-files/config.js +15 -10
  17. package/examples/advanced/matching-build-files/package.json +1 -1
  18. package/examples/advanced/multi-brand-multi-platform/build.js +10 -7
  19. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  20. package/examples/advanced/node-modules-as-config-and-properties/config.js +17 -12
  21. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  22. package/examples/advanced/npm-module/package.json +1 -1
  23. package/examples/advanced/referencing_aliasing/package.json +1 -1
  24. package/examples/advanced/s3/package.json +1 -1
  25. package/examples/advanced/tailwind-preset/README.md +94 -0
  26. package/examples/advanced/tailwind-preset/config/filter.js +3 -0
  27. package/examples/advanced/tailwind-preset/config/filter.test.js +12 -0
  28. package/examples/advanced/tailwind-preset/config/format.js +60 -0
  29. package/examples/advanced/tailwind-preset/config/transform.js +21 -0
  30. package/examples/advanced/tailwind-preset/config/transform.test.js +37 -0
  31. package/examples/advanced/tailwind-preset/config.js +55 -0
  32. package/examples/advanced/tailwind-preset/demo/index.html +27 -0
  33. package/examples/advanced/tailwind-preset/demo/input.css +3 -0
  34. package/examples/advanced/tailwind-preset/package.json +18 -0
  35. package/examples/advanced/tailwind-preset/tailwind.config.js +11 -0
  36. package/examples/advanced/tailwind-preset/tokens/tokens.json +49 -0
  37. package/examples/advanced/tokens-deprecation/build.js +2 -1
  38. package/examples/advanced/tokens-deprecation/package.json +1 -1
  39. package/examples/advanced/transitive-transforms/package.json +1 -1
  40. package/examples/advanced/transitive-transforms/sd.config.js +12 -9
  41. package/examples/advanced/variables-in-outputs/package.json +1 -1
  42. package/examples/advanced/variables-in-outputs/sd.config.js +10 -5
  43. package/examples/advanced/yaml-tokens/package.json +1 -1
  44. package/examples/advanced/yaml-tokens/sd.config.js +3 -2
  45. package/lib/Register.d.ts +2 -2
  46. package/lib/Register.js +6 -3
  47. package/lib/StyleDictionary.d.ts +20 -18
  48. package/lib/StyleDictionary.js +89 -71
  49. package/lib/cleanActions.d.ts +1 -1
  50. package/lib/cleanDir.d.ts +1 -1
  51. package/lib/cleanDir.js +2 -1
  52. package/lib/cleanDirs.d.ts +1 -1
  53. package/lib/cleanFile.d.ts +1 -6
  54. package/lib/cleanFile.js +5 -2
  55. package/lib/cleanFiles.d.ts +1 -1
  56. package/lib/common/actions.d.ts +20 -1
  57. package/lib/common/actions.js +8 -4
  58. package/lib/common/filters.d.ts +7 -1
  59. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
  60. package/lib/common/formatHelpers/createPropertyFormatter.js +26 -19
  61. package/lib/common/formatHelpers/fileHeader.d.ts +1 -1
  62. package/lib/common/formatHelpers/fileHeader.js +4 -2
  63. package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
  64. package/lib/common/formatHelpers/formattedVariables.js +3 -1
  65. package/lib/common/formatHelpers/getTypeScriptType.d.ts +2 -2
  66. package/lib/common/formatHelpers/minifyDictionary.d.ts +1 -1
  67. package/lib/common/formatHelpers/setComposeObjectProperties.d.ts +1 -1
  68. package/lib/common/formatHelpers/setSwiftFileProperties.d.ts +1 -1
  69. package/lib/common/formatHelpers/sortByReference.d.ts +1 -1
  70. package/lib/common/formats.js +234 -162
  71. package/lib/common/templates/compose/object.kt.template.js +8 -4
  72. package/lib/common/templates/css/fonts.css.template.js +2 -2
  73. package/lib/common/templates/scss/map-flat.template.js +4 -3
  74. package/lib/common/transformGroups.d.ts +209 -1
  75. package/lib/common/transformGroups.js +139 -93
  76. package/lib/common/transforms.d.ts +961 -1
  77. package/lib/common/transforms.js +112 -110
  78. package/lib/enums/actions.d.ts +4 -0
  79. package/lib/enums/actions.js +4 -0
  80. package/lib/enums/commentPositions.d.ts +4 -0
  81. package/lib/enums/commentPositions.js +4 -0
  82. package/lib/enums/commentStyles.d.ts +5 -0
  83. package/lib/enums/commentStyles.js +5 -0
  84. package/lib/enums/fileHeaderCommentStyles.d.ts +5 -0
  85. package/lib/enums/fileHeaderCommentStyles.js +5 -0
  86. package/lib/enums/formats.d.ts +46 -0
  87. package/lib/enums/formats.js +50 -0
  88. package/lib/enums/index.d.ts +12 -0
  89. package/lib/enums/index.js +12 -0
  90. package/lib/enums/logBrokenReferenceLevels.d.ts +5 -0
  91. package/lib/enums/logBrokenReferenceLevels.js +4 -0
  92. package/lib/enums/logVerbosityLevels.d.ts +6 -0
  93. package/lib/enums/logVerbosityLevels.js +5 -0
  94. package/lib/enums/logWarningLevels.d.ts +5 -0
  95. package/lib/enums/logWarningLevels.js +5 -0
  96. package/lib/enums/propertyFormatNames.d.ts +6 -0
  97. package/lib/enums/propertyFormatNames.js +6 -0
  98. package/lib/enums/transformGroups.d.ts +17 -0
  99. package/lib/enums/transformGroups.js +17 -0
  100. package/lib/enums/transformTypes.d.ts +5 -0
  101. package/lib/enums/transformTypes.js +5 -0
  102. package/lib/enums/transforms.d.ts +57 -0
  103. package/lib/enums/transforms.js +57 -0
  104. package/lib/filterTokens.d.ts +1 -1
  105. package/lib/filterTokens.js +5 -0
  106. package/lib/fs.d.ts +1 -1
  107. package/lib/fs.js +1 -1
  108. package/lib/performActions.d.ts +1 -1
  109. package/lib/resolve.d.ts +1 -1
  110. package/lib/resolve.js +4 -3
  111. package/lib/transform/config.js +3 -2
  112. package/lib/transform/object.d.ts +1 -1
  113. package/lib/transform/token.d.ts +1 -9
  114. package/lib/transform/token.js +10 -3
  115. package/lib/utils/cleanActions.d.ts +1 -1
  116. package/lib/utils/combineJSON.d.ts +1 -1
  117. package/lib/utils/combineJSON.js +12 -32
  118. package/lib/utils/convertToBase64.d.ts +1 -1
  119. package/lib/utils/convertToDTCG.d.ts +3 -3
  120. package/lib/utils/convertTokenData.d.ts +30 -0
  121. package/lib/utils/convertTokenData.js +123 -0
  122. package/lib/utils/deepExtend.d.ts +1 -1
  123. package/lib/utils/deepmerge.d.ts +1 -1
  124. package/lib/utils/expandObjectTokens.d.ts +2 -2
  125. package/lib/utils/expandObjectTokens.js +1 -1
  126. package/lib/utils/flattenTokens.d.ts +9 -5
  127. package/lib/utils/flattenTokens.js +28 -16
  128. package/lib/utils/index.d.ts +2 -1
  129. package/lib/utils/index.js +3 -0
  130. package/lib/utils/loadFile.d.ts +13 -0
  131. package/lib/utils/loadFile.js +89 -0
  132. package/lib/utils/preprocess.d.ts +1 -1
  133. package/lib/utils/references/defaults.d.ts +5 -1
  134. package/lib/utils/references/getName.d.ts +1 -1
  135. package/lib/utils/references/getReferences.d.ts +1 -1
  136. package/lib/utils/references/outputReferencesTransformed.js +1 -1
  137. package/lib/utils/references/resolveReferences.d.ts +2 -2
  138. package/lib/utils/references/usesReferences.d.ts +1 -1
  139. package/package.json +26 -15
  140. package/types/Config.d.ts +9 -3
  141. package/types/DesignToken.d.ts +6 -0
  142. package/types/File.d.ts +6 -2
  143. package/types/Format.d.ts +4 -1
  144. 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
  },
@@ -10,9 +10,10 @@ import program 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
+ import { logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js';
13
14
 
14
15
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
-
16
+ const { silent, verbose } = logVerbosityLevels;
16
17
  const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
17
18
 
18
19
  function collect(val, arr) {
@@ -95,7 +96,6 @@ program
95
96
  console.log(
96
97
  'Running `style-dictionary build` for the first time to generate build artifacts.\n',
97
98
  );
98
- /* eslint-disable no-console */
99
99
  styleDictionaryBuild();
100
100
  });
101
101
 
@@ -112,10 +112,10 @@ function getSD(configPath, options) {
112
112
  let verbosity;
113
113
  let warnings;
114
114
  if (options.verbose || options.silent) {
115
- verbosity = options.verbose ? 'verbose' : 'silent';
115
+ verbosity = options.verbose ? verbose : silent;
116
116
  }
117
117
  if (options.warn === false) {
118
- warnings = 'disabled';
118
+ warnings = logWarningLevels.disabled;
119
119
  }
120
120
  return new StyleDictionary(configPath, { verbosity, warnings });
121
121
  }
@@ -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.0"
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.0"
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.0"
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.0"
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.0"
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.0"
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.0"
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.0"
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.0"
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.0",
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.0"
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.0"
20
20
  }
21
21
  }
@@ -16,6 +16,6 @@
16
16
  "devDependencies": {
17
17
  "aws-sdk": "^2.7.21",
18
18
  "fs-extra": "^1.0.0",
19
- "style-dictionary": "^4.2.0"
19
+ "style-dictionary": "^4.3.0"
20
20
  }
21
21
  }