style-dictionary 4.0.0-prerelease.13 → 4.0.0-prerelease.14

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 (104) hide show
  1. package/examples/advanced/assets-base64-embed/package.json +1 -1
  2. package/examples/advanced/auto-rebuild-watcher/package.json +1 -1
  3. package/examples/advanced/component-cti/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/custom-file-header/package.json +1 -1
  7. package/examples/advanced/custom-filters/package.json +1 -1
  8. package/examples/advanced/custom-formats-with-templates/package.json +1 -1
  9. package/examples/advanced/custom-parser/package.json +1 -1
  10. package/examples/advanced/custom-transforms/package.json +1 -1
  11. package/examples/advanced/font-face-rules/package.json +1 -1
  12. package/examples/advanced/format-helpers/package.json +1 -1
  13. package/examples/advanced/matching-build-files/package.json +1 -1
  14. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  15. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  16. package/examples/advanced/npm-module/package.json +1 -1
  17. package/examples/advanced/referencing_aliasing/package.json +1 -1
  18. package/examples/advanced/s3/package.json +1 -1
  19. package/examples/advanced/tokens-deprecation/package.json +1 -1
  20. package/examples/advanced/transitive-transforms/package.json +1 -1
  21. package/examples/advanced/variables-in-outputs/package.json +1 -1
  22. package/examples/advanced/yaml-tokens/package.json +1 -1
  23. package/lib/StyleDictionary.js +45 -11
  24. package/lib/buildFile.d.ts +4 -1
  25. package/lib/buildFile.js +6 -3
  26. package/lib/buildFiles.d.ts +7 -4
  27. package/lib/buildFiles.js +6 -4
  28. package/lib/cleanActions.d.ts +7 -4
  29. package/lib/cleanActions.js +6 -4
  30. package/lib/common/actions.js +2 -2
  31. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
  32. package/lib/common/formatHelpers/createPropertyFormatter.js +7 -8
  33. package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
  34. package/lib/common/formatHelpers/formattedVariables.js +3 -0
  35. package/lib/common/formatHelpers/getTypeScriptType.d.ts +4 -2
  36. package/lib/common/formatHelpers/getTypeScriptType.js +3 -2
  37. package/lib/common/formatHelpers/iconsWithPrefix.d.ts +4 -1
  38. package/lib/common/formatHelpers/iconsWithPrefix.js +6 -3
  39. package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -1
  40. package/lib/common/formatHelpers/minifyDictionary.js +5 -4
  41. package/lib/common/formatHelpers/sortByReference.js +3 -3
  42. package/lib/common/formats.js +48 -41
  43. package/lib/common/templates/android/colors.template.d.ts +1 -1
  44. package/lib/common/templates/android/colors.template.js +1 -1
  45. package/lib/common/templates/android/dimens.template.d.ts +1 -1
  46. package/lib/common/templates/android/dimens.template.js +1 -1
  47. package/lib/common/templates/android/fontDimens.template.d.ts +1 -1
  48. package/lib/common/templates/android/fontDimens.template.js +1 -1
  49. package/lib/common/templates/android/integers.template.d.ts +1 -1
  50. package/lib/common/templates/android/integers.template.js +1 -1
  51. package/lib/common/templates/android/resources.template.d.ts +2 -0
  52. package/lib/common/templates/android/resources.template.js +4 -2
  53. package/lib/common/templates/android/strings.template.d.ts +1 -1
  54. package/lib/common/templates/android/strings.template.js +1 -1
  55. package/lib/common/templates/ios/colors.m.template.d.ts +1 -1
  56. package/lib/common/templates/ios/colors.m.template.js +1 -1
  57. package/lib/common/templates/ios/macros.template.d.ts +1 -1
  58. package/lib/common/templates/ios/macros.template.js +1 -1
  59. package/lib/common/templates/ios/plist.template.d.ts +1 -1
  60. package/lib/common/templates/ios/plist.template.js +5 -5
  61. package/lib/common/templates/ios/singleton.m.template.d.ts +1 -1
  62. package/lib/common/templates/ios/singleton.m.template.js +2 -2
  63. package/lib/common/templates/ios/static.m.template.d.ts +1 -1
  64. package/lib/common/templates/ios/static.m.template.js +1 -1
  65. package/lib/common/templates/ios/strings.m.template.d.ts +1 -1
  66. package/lib/common/templates/ios/strings.m.template.js +2 -2
  67. package/lib/common/templates/scss/map-deep.template.d.ts +1 -1
  68. package/lib/common/templates/scss/map-deep.template.js +1 -1
  69. package/lib/common/templates/scss/map-flat.template.d.ts +1 -1
  70. package/lib/common/templates/scss/map-flat.template.js +1 -1
  71. package/lib/common/templates/static-style-guide/index.html.template.d.ts +1 -1
  72. package/lib/common/templates/static-style-guide/index.html.template.js +2 -2
  73. package/lib/common/transforms.d.ts +2 -1
  74. package/lib/common/transforms.js +125 -119
  75. package/lib/filterTokens.d.ts +3 -1
  76. package/lib/filterTokens.js +8 -5
  77. package/lib/fs.js +1 -0
  78. package/lib/performActions.d.ts +7 -4
  79. package/lib/performActions.js +6 -4
  80. package/lib/transform/object.d.ts +5 -2
  81. package/lib/transform/object.js +8 -4
  82. package/lib/transform/token.d.ts +5 -2
  83. package/lib/transform/token.js +14 -12
  84. package/lib/utils/combineJSON.d.ts +6 -2
  85. package/lib/utils/combineJSON.js +9 -3
  86. package/lib/utils/createFormatArgs.d.ts +5 -1
  87. package/lib/utils/createFormatArgs.js +9 -4
  88. package/lib/utils/detectDtcgSyntax.d.ts +8 -0
  89. package/lib/utils/detectDtcgSyntax.js +26 -0
  90. package/lib/utils/flattenTokens.d.ts +2 -7
  91. package/lib/utils/flattenTokens.js +21 -14
  92. package/lib/utils/index.d.ts +2 -2
  93. package/lib/utils/index.js +2 -2
  94. package/lib/utils/preprocess.d.ts +3 -1
  95. package/lib/utils/preprocess.js +17 -15
  96. package/lib/utils/references/getReferences.d.ts +7 -9
  97. package/lib/utils/references/getReferences.js +6 -5
  98. package/lib/utils/references/resolveReferences.d.ts +6 -6
  99. package/lib/utils/references/resolveReferences.js +10 -11
  100. package/package.json +1 -1
  101. package/types/Action.d.ts +3 -3
  102. package/types/Config.d.ts +9 -2
  103. package/types/Format.d.ts +2 -2
  104. package/types/Transform.d.ts +2 -2
@@ -11,6 +11,6 @@
11
11
  "author": "",
12
12
  "license": "Apache-2.0",
13
13
  "devDependencies": {
14
- "style-dictionary": "4.0.0-prerelease.13"
14
+ "style-dictionary": "4.0.0-prerelease.14"
15
15
  }
16
16
  }
@@ -17,6 +17,6 @@
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
19
  "chokidar-cli": "^1.2.0",
20
- "style-dictionary": "4.0.0-prerelease.13"
20
+ "style-dictionary": "4.0.0-prerelease.14"
21
21
  }
22
22
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "eslint-config-react-app": "^7.0.1",
14
- "style-dictionary": "4.0.0-prerelease.13"
14
+ "style-dictionary": "4.0.0-prerelease.14"
15
15
  },
16
16
  "resolutions": {
17
17
  "immer": "8.0.1",
@@ -28,7 +28,7 @@
28
28
  "eslint-config-react-app": "^7.0.1",
29
29
  "jest": "~25.2.6",
30
30
  "react-test-renderer": "~16.13.1",
31
- "style-dictionary": "4.0.0-prerelease.13"
31
+ "style-dictionary": "4.0.0-prerelease.14"
32
32
  },
33
33
  "jest": {
34
34
  "preset": "react-native"
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "ISC",
12
12
  "devDependencies": {
13
- "style-dictionary": "4.0.0-prerelease.13"
13
+ "style-dictionary": "4.0.0-prerelease.14"
14
14
  }
15
15
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -18,6 +18,6 @@
18
18
  "handlebars": "^4.7.7",
19
19
  "lodash": "^4.17.21",
20
20
  "pug": "^3.0.2",
21
- "style-dictionary": "4.0.0-prerelease.13"
21
+ "style-dictionary": "4.0.0-prerelease.14"
22
22
  }
23
23
  }
@@ -9,6 +9,6 @@
9
9
  "author": "",
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "4.0.0-prerelease.13"
12
+ "style-dictionary": "4.0.0-prerelease.14"
13
13
  }
14
14
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -8,6 +8,6 @@
8
8
  },
9
9
  "license": "Apache-2.0",
10
10
  "devDependencies": {
11
- "style-dictionary": "4.0.0-prerelease.13"
11
+ "style-dictionary": "4.0.0-prerelease.14"
12
12
  }
13
13
  }
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "Apache-2.0",
12
12
  "devDependencies": {
13
- "style-dictionary": "4.0.0-prerelease.13"
13
+ "style-dictionary": "4.0.0-prerelease.14"
14
14
  }
15
15
  }
@@ -16,6 +16,6 @@
16
16
  "author": "Kelly Harrop <kn.harrop@gmail.com>",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "4.0.0-prerelease.13"
19
+ "style-dictionary": "4.0.0-prerelease.14"
20
20
  }
21
21
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/dbanksdesign/style-dictionary-node#readme",
21
21
  "devDependencies": {
22
- "style-dictionary": "4.0.0-prerelease.13",
22
+ "style-dictionary": "4.0.0-prerelease.14",
23
23
  "tinycolor2": "^1.4.1"
24
24
  }
25
25
  }
@@ -16,6 +16,6 @@
16
16
  "author": "",
17
17
  "license": "Apache-2.0",
18
18
  "devDependencies": {
19
- "style-dictionary": "4.0.0-prerelease.13"
19
+ "style-dictionary": "4.0.0-prerelease.14"
20
20
  }
21
21
  }
@@ -15,6 +15,6 @@
15
15
  "author": "",
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -15,6 +15,6 @@
15
15
  "devDependencies": {
16
16
  "aws-sdk": "^2.7.21",
17
17
  "fs-extra": "^1.0.0",
18
- "style-dictionary": "4.0.0-prerelease.13"
18
+ "style-dictionary": "4.0.0-prerelease.14"
19
19
  }
20
20
  }
@@ -16,6 +16,6 @@
16
16
  "license": "Apache-2.0",
17
17
  "devDependencies": {
18
18
  "lodash": "^4.17.11",
19
- "style-dictionary": "4.0.0-prerelease.13"
19
+ "style-dictionary": "4.0.0-prerelease.14"
20
20
  }
21
21
  }
@@ -11,6 +11,6 @@
11
11
  "license": "ISC",
12
12
  "devDependencies": {
13
13
  "chroma-js": "^2.1.0",
14
- "style-dictionary": "4.0.0-prerelease.13"
14
+ "style-dictionary": "4.0.0-prerelease.14"
15
15
  }
16
16
  }
@@ -10,6 +10,6 @@
10
10
  "author": "",
11
11
  "license": "MIT",
12
12
  "devDependencies": {
13
- "style-dictionary": "4.0.0-prerelease.13"
13
+ "style-dictionary": "4.0.0-prerelease.14"
14
14
  }
15
15
  }
@@ -9,7 +9,7 @@
9
9
  "author": "",
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "style-dictionary": "4.0.0-prerelease.13",
12
+ "style-dictionary": "4.0.0-prerelease.14",
13
13
  "yaml": "^1.10.0"
14
14
  }
15
15
  }
@@ -25,6 +25,8 @@ import deepExtend from './utils/deepExtend.js';
25
25
  import resolveObject from './utils/resolveObject.js';
26
26
  import getName from './utils/references/getName.js';
27
27
  import GroupMessages from './utils/groupMessages.js';
28
+ import flattenTokens from './utils/flattenTokens.js';
29
+ import { detectDtcgSyntax } from './utils/detectDtcgSyntax.js';
28
30
  import { preprocess } from './utils/preprocess.js';
29
31
 
30
32
  import transformObject from './transform/object.js';
@@ -34,7 +36,6 @@ import buildFiles from './buildFiles.js';
34
36
  import cleanFiles from './cleanFiles.js';
35
37
  import cleanDirs from './cleanDirs.js';
36
38
  import cleanActions from './cleanActions.js';
37
- import flattenTokens from './utils/flattenTokens.js';
38
39
 
39
40
  /**
40
41
  * @typedef {import('../types/Config.d.ts').Config} Config
@@ -65,7 +66,7 @@ export default class StyleDictionary extends Register {
65
66
  // Placeholder is transformed on prepublish -> see scripts/inject-version.js
66
67
  // Another option might be import pkg from './package.json' with { "type": "json" } which would work in both browser and node, but support is not there yet.
67
68
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
68
- static VERSION = '4.0.0-prerelease.13';
69
+ static VERSION = '4.0.0-prerelease.14';
69
70
  static formatHelpers = formatHelpers;
70
71
 
71
72
  /** @returns {Config} */
@@ -147,6 +148,7 @@ export default class StyleDictionary extends Register {
147
148
  let includeTokens = {};
148
149
  /** @type {Tokens} */
149
150
  let sourceTokens = {};
151
+
150
152
  // Overloaded method, can accept a string as a path that points to a JS or
151
153
  // JSON file or a plain object. Potentially refactor.
152
154
  if (typeof config === 'string') {
@@ -176,9 +178,12 @@ export default class StyleDictionary extends Register {
176
178
  });
177
179
  this.options = options;
178
180
 
179
- // Creating a new object and copying over the options
180
- // Also keeping an options object in case
181
+ let { usesDtcg } = this.options;
181
182
 
183
+ // Try to detect DTCG if not specified by user in options
184
+ if (Object.entries(this.tokens).length > 0 && usesDtcg === undefined) {
185
+ usesDtcg = detectDtcgSyntax(this.tokens);
186
+ }
182
187
  // grab the inline tokens, ones either defined in the configuration object
183
188
  // or that already exist from extending another style dictionary instance
184
189
  // with `tokens` keys
@@ -188,14 +193,28 @@ export default class StyleDictionary extends Register {
188
193
  if (this.options.include) {
189
194
  if (!Array.isArray(this.options.include)) throw new Error('include must be an array');
190
195
 
191
- includeTokens = await combineJSON(this.options.include, true, undefined, false, this.parsers);
196
+ const result = await combineJSON(
197
+ this.options.include,
198
+ true,
199
+ undefined,
200
+ false,
201
+ this.parsers,
202
+ this.options.usesDtcg,
203
+ );
204
+
205
+ includeTokens = result.tokens;
206
+ // If it wasn't known yet whether DTCG is used, combineJSON util will have auto-detected it
207
+ if (usesDtcg === undefined) {
208
+ usesDtcg = result.usesDtcg;
209
+ }
192
210
  }
193
211
 
194
212
  // Update tokens with current package's source
195
213
  // These highest precedence
196
214
  if (this.options.source) {
197
215
  if (!Array.isArray(this.options.source)) throw new Error('source must be an array');
198
- sourceTokens = await combineJSON(
216
+
217
+ const result = await combineJSON(
199
218
  this.options.source,
200
219
  true,
201
220
  /** @param {Token} prop */
@@ -209,8 +228,15 @@ export default class StyleDictionary extends Register {
209
228
  },
210
229
  true,
211
230
  this.parsers,
231
+ this.options.usesDtcg,
212
232
  );
213
233
 
234
+ sourceTokens = result.tokens;
235
+ // If it wasn't known yet whether DTCG is used, combineJSON util will have auto-detected it
236
+ if (usesDtcg === undefined) {
237
+ usesDtcg = result.usesDtcg;
238
+ }
239
+
214
240
  if (GroupMessages.count(PROPERTY_VALUE_COLLISIONS) > 0) {
215
241
  const collisions = GroupMessages.flush(PROPERTY_VALUE_COLLISIONS).join('\n');
216
242
  const warn = `\n${PROPERTY_VALUE_COLLISIONS}:\n${collisions}\n\n`;
@@ -226,6 +252,7 @@ export default class StyleDictionary extends Register {
226
252
  // Merge inline, include, and source tokens
227
253
  const unprocessedTokens = deepExtend([{}, inlineTokens, includeTokens, sourceTokens]);
228
254
  this.tokens = await preprocess(unprocessedTokens, this.preprocessors);
255
+ this.options = { ...this.options, usesDtcg };
229
256
  this.hasInitializedResolve(null);
230
257
 
231
258
  // For chaining
@@ -306,7 +333,12 @@ export default class StyleDictionary extends Register {
306
333
  // values like "1px solid {color.border.base}" we want to
307
334
  // transform the original value (color.border.base) before
308
335
  // replacing that value in the string.
309
- const transformed = transformObject(exportableResult, platformConfig, transformationContext);
336
+ const transformed = transformObject(
337
+ exportableResult,
338
+ platformConfig,
339
+ this.options,
340
+ transformationContext,
341
+ );
310
342
 
311
343
  // referenced values, that have not (yet) been transformed should be excluded from resolving
312
344
  const ignorePathsToResolve = deferredPropValueTransforms.map((p) => getName([p, 'value']));
@@ -365,7 +397,9 @@ export default class StyleDictionary extends Register {
365
397
  // transform the original value (color.border.base) before
366
398
  // replacing that value in the string.
367
399
  const tokens = await this.exportPlatform(platform);
368
- this.allTokens = /** @type {TransformedToken[]} */ (flattenTokens(tokens));
400
+ this.allTokens = /** @type {TransformedToken[]} */ (
401
+ flattenTokens(tokens, this.options.usesDtcg)
402
+ );
369
403
  // This is the dictionary object we pass to the file
370
404
  // building and action methods.
371
405
  return { dictionary: { tokens, allTokens: this.allTokens }, platformConfig };
@@ -377,8 +411,8 @@ export default class StyleDictionary extends Register {
377
411
  */
378
412
  async buildPlatform(platform) {
379
413
  const { dictionary, platformConfig } = await this.getPlatform(platform);
380
- buildFiles(dictionary, platformConfig);
381
- performActions(dictionary, platformConfig);
414
+ buildFiles(dictionary, platformConfig, this.options);
415
+ performActions(dictionary, platformConfig, this.options);
382
416
  // For chaining
383
417
  return this;
384
418
  }
@@ -400,7 +434,7 @@ export default class StyleDictionary extends Register {
400
434
  const { dictionary, platformConfig } = await this.getPlatform(platform);
401
435
  // We clean files first, then actions, ...and then directories?
402
436
  cleanFiles(platformConfig);
403
- cleanActions(dictionary, platformConfig);
437
+ cleanActions(dictionary, platformConfig, this.options);
404
438
  cleanDirs(platformConfig);
405
439
  // For chaining
406
440
  return this;
@@ -2,6 +2,7 @@
2
2
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
3
3
  * @typedef {import('../types/DesignToken.d.ts').TransformedToken} TransformedToken
4
4
  * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
5
+ * @typedef {import('../types/Config.d.ts').Config} Config
5
6
  * @typedef {import('../types/File.d.ts').File} File
6
7
  */
7
8
  /**
@@ -11,9 +12,11 @@
11
12
  * @param {File} file
12
13
  * @param {PlatformConfig} platform
13
14
  * @param {Dictionary} dictionary
15
+ * @param {Config} options
14
16
  */
15
- export default function buildFile(file: File, platform: import("../types/Config.d.ts").PlatformConfig | undefined, dictionary: Dictionary): null | undefined;
17
+ export default function buildFile(file: File, platform: import("../types/Config.d.ts").PlatformConfig | undefined, dictionary: Dictionary, options: Config): null | undefined;
16
18
  export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
17
19
  export type TransformedToken = import('../types/DesignToken.d.ts').TransformedToken;
18
20
  export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
21
+ export type Config = import('../types/Config.d.ts').Config;
19
22
  export type File = import('../types/File.d.ts').File;
package/lib/buildFile.js CHANGED
@@ -23,6 +23,7 @@ import createFormatArgs from './utils/createFormatArgs.js';
23
23
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
24
24
  * @typedef {import('../types/DesignToken.d.ts').TransformedToken} TransformedToken
25
25
  * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
26
+ * @typedef {import('../types/Config.d.ts').Config} Config
26
27
  * @typedef {import('../types/File.d.ts').File} File
27
28
  */
28
29
 
@@ -33,8 +34,9 @@ import createFormatArgs from './utils/createFormatArgs.js';
33
34
  * @param {File} file
34
35
  * @param {PlatformConfig} platform
35
36
  * @param {Dictionary} dictionary
37
+ * @param {Config} options
36
38
  */
37
- export default function buildFile(file, platform = {}, dictionary) {
39
+ export default function buildFile(file, platform = {}, dictionary, options) {
38
40
  const { destination, filter } = file || {};
39
41
  let { format } = file || {};
40
42
 
@@ -56,7 +58,7 @@ export default function buildFile(file, platform = {}, dictionary) {
56
58
  const dir = dirname(fullDestination);
57
59
  if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
58
60
 
59
- const filteredTokens = filterTokens(dictionary, filter);
61
+ const filteredTokens = filterTokens(dictionary, filter, options);
60
62
  const filteredDictionary = Object.assign({}, dictionary, {
61
63
  tokens: filteredTokens.tokens,
62
64
  allTokens: filteredTokens.allTokens,
@@ -98,7 +100,7 @@ export default function buildFile(file, platform = {}, dictionary) {
98
100
  let collisions = nameCollisionObj[tokenName]
99
101
  .map((token) => {
100
102
  let tokenPathText = chalk.rgb(255, 69, 0)(token.path.join('.'));
101
- let valueText = chalk.rgb(255, 140, 0)(token.$value ?? token.value);
103
+ let valueText = chalk.rgb(255, 140, 0)(options.usesDtcg ? token.$value : token.value);
102
104
  return tokenPathText + ' ' + valueText;
103
105
  })
104
106
  .join('\n ');
@@ -118,6 +120,7 @@ export default function buildFile(file, platform = {}, dictionary) {
118
120
  createFormatArgs({
119
121
  dictionary: filteredDictionary,
120
122
  platform,
123
+ options,
121
124
  file,
122
125
  }),
123
126
  ),
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
3
- * @typedef {import('../types/Config.d.ts').PlatformConfig} Config
3
+ * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
4
+ * @typedef {import('../types/Config.d.ts').Config} Config
4
5
  */
5
6
  /**
6
7
  * Takes a platform config object and a dictionary
@@ -9,8 +10,10 @@
9
10
  * point.
10
11
  * @memberOf StyleDictionary
11
12
  * @param {Dictionary} dictionary
12
- * @param {Config} platform
13
+ * @param {PlatformConfig} platform
14
+ * @param {Config} options
13
15
  */
14
- export default function buildFiles(dictionary: Dictionary, platform: Config): void;
16
+ export default function buildFiles(dictionary: Dictionary, platform: PlatformConfig, options: Config): void;
15
17
  export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
16
- export type Config = import('../types/Config.d.ts').PlatformConfig;
18
+ export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
19
+ export type Config = import('../types/Config.d.ts').Config;
package/lib/buildFiles.js CHANGED
@@ -15,7 +15,8 @@ import buildFile from './buildFile.js';
15
15
 
16
16
  /**
17
17
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
18
- * @typedef {import('../types/Config.d.ts').PlatformConfig} Config
18
+ * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
19
+ * @typedef {import('../types/Config.d.ts').Config} Config
19
20
  */
20
21
 
21
22
  /**
@@ -25,9 +26,10 @@ import buildFile from './buildFile.js';
25
26
  * point.
26
27
  * @memberOf StyleDictionary
27
28
  * @param {Dictionary} dictionary
28
- * @param {Config} platform
29
+ * @param {PlatformConfig} platform
30
+ * @param {Config} options
29
31
  */
30
- export default function buildFiles(dictionary, platform) {
32
+ export default function buildFiles(dictionary, platform, options) {
31
33
  if (
32
34
  platform.buildPath &&
33
35
  platform.buildPath.slice(-1) !== '/' &&
@@ -38,7 +40,7 @@ export default function buildFiles(dictionary, platform) {
38
40
 
39
41
  platform.files?.forEach(function (file) {
40
42
  if (file.format) {
41
- buildFile(file, platform, dictionary);
43
+ buildFile(file, platform, dictionary, options);
42
44
  } else {
43
45
  throw new Error('Please supply a format');
44
46
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
3
- * @typedef {import('../types/Config.d.ts').PlatformConfig} Config
3
+ * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
4
+ * @typedef {import('../types/Config.d.ts').Config} Config
4
5
  */
5
6
  /**
6
7
  * Performs the undo of any actions defined in a platform. Pretty
@@ -10,8 +11,10 @@
10
11
  * @private
11
12
  * @memberof module:style-dictionary
12
13
  * @param {Dictionary} dictionary
13
- * @param {Config} platform
14
+ * @param {PlatformConfig} platform
15
+ * @param {Config} options
14
16
  */
15
- export default function cleanActions(dictionary: Dictionary, platform: Config): void;
17
+ export default function cleanActions(dictionary: Dictionary, platform: PlatformConfig, options: Config): void;
16
18
  export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
17
- export type Config = import('../types/Config.d.ts').PlatformConfig;
19
+ export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
20
+ export type Config = import('../types/Config.d.ts').Config;
@@ -13,7 +13,8 @@
13
13
 
14
14
  /**
15
15
  * @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
16
- * @typedef {import('../types/Config.d.ts').PlatformConfig} Config
16
+ * @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
17
+ * @typedef {import('../types/Config.d.ts').Config} Config
17
18
  */
18
19
 
19
20
  /**
@@ -24,14 +25,15 @@
24
25
  * @private
25
26
  * @memberof module:style-dictionary
26
27
  * @param {Dictionary} dictionary
27
- * @param {Config} platform
28
+ * @param {PlatformConfig} platform
29
+ * @param {Config} options
28
30
  */
29
- export default function cleanActions(dictionary, platform) {
31
+ export default function cleanActions(dictionary, platform, options) {
30
32
  if (platform.actions) {
31
33
  platform.actions.forEach(function (action) {
32
34
  // ensure we've augmented action with the do/undo functions and that undo exists
33
35
  if (typeof action !== 'string' && typeof action.undo === 'function') {
34
- action.undo(dictionary, platform);
36
+ action.undo(dictionary, platform, options);
35
37
  }
36
38
  });
37
39
  }
@@ -31,7 +31,7 @@ export default {
31
31
  * @memberof Actions
32
32
  */
33
33
  'android/copyImages': {
34
- do: function (dictionary, config) {
34
+ do: function (dictionary, config, options) {
35
35
  const imagesDir = `${config.buildPath}android/main/res/drawable-`;
36
36
  /**
37
37
  * @param {Token} token
@@ -42,7 +42,7 @@ export default {
42
42
  const dir = `${imagesDir}${token.attributes.state}`;
43
43
  const path = `${dir}/${name}.png`;
44
44
  fs.mkdirSync(dir, { recursive: true });
45
- fs.copyFileSync(token.$value ?? token.value, path);
45
+ fs.copyFileSync(options.usesDtcg ? token.$value : token.value, path);
46
46
  }
47
47
  });
48
48
  },
@@ -27,15 +27,17 @@
27
27
  * @param {string} [options.format] - Available formats are: 'css', 'sass', 'less', and 'stylus'. If you want to customize the format and can't use one of those predefined formats, use the `formatting` option
28
28
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: prefix, indentation, separator, suffix, and commentStyle. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`
29
29
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
30
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
30
31
  * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
31
32
  */
32
- export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, }: {
33
+ export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, usesDtcg, }: {
33
34
  outputReferences?: boolean | undefined;
34
35
  outputReferenceFallbacks?: boolean | undefined;
35
36
  dictionary: Dictionary;
36
37
  format?: string | undefined;
37
38
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
38
39
  themeable?: boolean | undefined;
40
+ usesDtcg?: boolean | undefined;
39
41
  }): (token: import('../../../types/DesignToken.d.ts').TransformedToken) => string;
40
42
  export type Dictionary = import('../../../types/DesignToken.d.ts').Dictionary;
41
43
  export type Formatting = import('../../../types/File.d.ts').FormattingOptions;
@@ -10,7 +10,7 @@
10
10
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
11
  * and limitations under the License.
12
12
  */
13
- import getReferences from '../../utils/references/getReferences.js';
13
+ import { _getReferences } from '../../utils/references/getReferences.js';
14
14
  import usesReferences from '../../utils/references/usesReferences.js';
15
15
 
16
16
  /**
@@ -113,6 +113,7 @@ function addComment(to_ret_token, comment, options) {
113
113
  * @param {string} [options.format] - Available formats are: 'css', 'sass', 'less', and 'stylus'. If you want to customize the format and can't use one of those predefined formats, use the `formatting` option
114
114
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: prefix, indentation, separator, suffix, and commentStyle. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`
115
115
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
116
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
116
117
  * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
117
118
  */
118
119
  export default function createPropertyFormatter({
@@ -122,6 +123,7 @@ export default function createPropertyFormatter({
122
123
  format,
123
124
  formatting = {},
124
125
  themeable = false,
126
+ usesDtcg = false,
125
127
  }) {
126
128
  /** @type {Formatting} */
127
129
  const formatDefaults = {};
@@ -159,7 +161,7 @@ export default function createPropertyFormatter({
159
161
  const { tokens, unfilteredTokens } = dictionary;
160
162
  return function (token) {
161
163
  let to_ret_token = `${indentation}${prefix}${token.name}${separator} `;
162
- let value = token.$value ?? token.value;
164
+ let value = usesDtcg ? token.$value : token.value;
163
165
 
164
166
  /**
165
167
  * A single value can have multiple references either by interpolation:
@@ -176,7 +178,7 @@ export default function createPropertyFormatter({
176
178
  if (outputReferences && usesReferences(token.original.value)) {
177
179
  // Formats that use this function expect `value` to be a string
178
180
  // or else you will get '[object Object]' in the output
179
- const refs = getReferences(token.original.value, tokens, { unfilteredTokens }, []);
181
+ const refs = _getReferences(token.original.value, tokens, { unfilteredTokens }, []);
180
182
 
181
183
  // original can either be an object value, which requires transitive value transformation in web CSS formats
182
184
  // or a different (primitive) type, meaning it can be stringified.
@@ -198,11 +200,8 @@ export default function createPropertyFormatter({
198
200
  // because Style Dictionary resolved this in the resolution step.
199
201
  // Here we are undoing that by replacing the value with
200
202
  // the reference's name
201
- if (
202
- (Object.hasOwn(ref, 'value') || Object.hasOwn(ref, '$value')) &&
203
- Object.hasOwn(ref, 'name')
204
- ) {
205
- const refVal = ref.$value ?? ref.value;
203
+ if (Object.hasOwn(ref, `${usesDtcg ? '$' : ''}value`) && Object.hasOwn(ref, 'name')) {
204
+ const refVal = usesDtcg ? ref.$value : ref.value;
206
205
  const replaceFunc = function () {
207
206
  if (format === 'css') {
208
207
  if (outputReferenceFallbacks) {
@@ -9,6 +9,7 @@
9
9
  * @param {Boolean} [options.outputReferences] - Whether or not to output references
10
10
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers.createPropertyFormatter` and used for the `lineSeparator` between lines of code.
11
11
  * @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
12
+ * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
12
13
  * @returns {String}
13
14
  * @example
14
15
  * ```js
@@ -24,12 +25,13 @@
24
25
  * });
25
26
  * ```
26
27
  */
27
- export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, }: {
28
+ export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, usesDtcg, }: {
28
29
  format: string;
29
30
  dictionary: Dictionary;
30
31
  outputReferences?: boolean | undefined;
31
32
  formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
32
33
  themeable?: boolean | undefined;
34
+ usesDtcg?: boolean | undefined;
33
35
  }): string;
34
36
  export type Token = import('../../../types/DesignToken.d.ts').TransformedToken;
35
37
  export type Tokens = import('../../../types/DesignToken.d.ts').TransformedTokens;