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

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 (132) 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 +47 -13
  24. package/lib/buildFile.d.ts +4 -1
  25. package/lib/buildFile.js +15 -12
  26. package/lib/buildFiles.d.ts +7 -4
  27. package/lib/buildFiles.js +16 -10
  28. package/lib/cleanActions.d.ts +7 -4
  29. package/lib/cleanActions.js +12 -9
  30. package/lib/cleanDir.d.ts +1 -1
  31. package/lib/cleanDir.js +4 -3
  32. package/lib/cleanDirs.d.ts +1 -1
  33. package/lib/cleanDirs.js +12 -9
  34. package/lib/cleanFile.d.ts +1 -1
  35. package/lib/cleanFile.js +1 -1
  36. package/lib/cleanFiles.d.ts +1 -1
  37. package/lib/cleanFiles.js +12 -9
  38. package/lib/common/actions.js +28 -23
  39. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
  40. package/lib/common/formatHelpers/createPropertyFormatter.js +7 -8
  41. package/lib/common/formatHelpers/fileHeader.d.ts +2 -2
  42. package/lib/common/formatHelpers/fileHeader.js +5 -3
  43. package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
  44. package/lib/common/formatHelpers/formattedVariables.js +3 -0
  45. package/lib/common/formatHelpers/getTypeScriptType.d.ts +4 -2
  46. package/lib/common/formatHelpers/getTypeScriptType.js +3 -2
  47. package/lib/common/formatHelpers/iconsWithPrefix.d.ts +4 -1
  48. package/lib/common/formatHelpers/iconsWithPrefix.js +6 -3
  49. package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -1
  50. package/lib/common/formatHelpers/minifyDictionary.js +5 -4
  51. package/lib/common/formatHelpers/sortByReference.js +3 -3
  52. package/lib/common/formats.js +147 -130
  53. package/lib/common/templates/android/colors.template.d.ts +1 -1
  54. package/lib/common/templates/android/colors.template.js +2 -2
  55. package/lib/common/templates/android/dimens.template.d.ts +1 -1
  56. package/lib/common/templates/android/dimens.template.js +2 -2
  57. package/lib/common/templates/android/fontDimens.template.d.ts +1 -1
  58. package/lib/common/templates/android/fontDimens.template.js +2 -2
  59. package/lib/common/templates/android/integers.template.d.ts +1 -1
  60. package/lib/common/templates/android/integers.template.js +2 -2
  61. package/lib/common/templates/android/resources.template.d.ts +3 -1
  62. package/lib/common/templates/android/resources.template.js +6 -4
  63. package/lib/common/templates/android/strings.template.d.ts +1 -1
  64. package/lib/common/templates/android/strings.template.js +2 -2
  65. package/lib/common/templates/compose/object.kt.template.d.ts +1 -1
  66. package/lib/common/templates/compose/object.kt.template.js +1 -1
  67. package/lib/common/templates/flutter/class.dart.template.d.ts +1 -1
  68. package/lib/common/templates/flutter/class.dart.template.js +1 -1
  69. package/lib/common/templates/ios/colors.h.template.d.ts +1 -1
  70. package/lib/common/templates/ios/colors.h.template.js +1 -1
  71. package/lib/common/templates/ios/colors.m.template.d.ts +1 -1
  72. package/lib/common/templates/ios/colors.m.template.js +2 -2
  73. package/lib/common/templates/ios/macros.template.d.ts +1 -1
  74. package/lib/common/templates/ios/macros.template.js +2 -2
  75. package/lib/common/templates/ios/plist.template.d.ts +1 -1
  76. package/lib/common/templates/ios/plist.template.js +6 -6
  77. package/lib/common/templates/ios/singleton.h.template.d.ts +1 -1
  78. package/lib/common/templates/ios/singleton.h.template.js +1 -1
  79. package/lib/common/templates/ios/singleton.m.template.d.ts +1 -1
  80. package/lib/common/templates/ios/singleton.m.template.js +3 -3
  81. package/lib/common/templates/ios/static.h.template.d.ts +1 -1
  82. package/lib/common/templates/ios/static.h.template.js +1 -1
  83. package/lib/common/templates/ios/static.m.template.d.ts +1 -1
  84. package/lib/common/templates/ios/static.m.template.js +2 -2
  85. package/lib/common/templates/ios/strings.h.template.d.ts +1 -1
  86. package/lib/common/templates/ios/strings.h.template.js +1 -1
  87. package/lib/common/templates/ios/strings.m.template.d.ts +1 -1
  88. package/lib/common/templates/ios/strings.m.template.js +3 -3
  89. package/lib/common/templates/ios-swift/any.swift.template.d.ts +1 -1
  90. package/lib/common/templates/ios-swift/any.swift.template.js +1 -1
  91. package/lib/common/templates/scss/map-deep.template.d.ts +1 -1
  92. package/lib/common/templates/scss/map-deep.template.js +1 -1
  93. package/lib/common/templates/scss/map-flat.template.d.ts +1 -1
  94. package/lib/common/templates/scss/map-flat.template.js +2 -2
  95. package/lib/common/templates/static-style-guide/index.html.template.d.ts +1 -1
  96. package/lib/common/templates/static-style-guide/index.html.template.js +2 -2
  97. package/lib/common/transforms.d.ts +2 -1
  98. package/lib/common/transforms.js +125 -119
  99. package/lib/filterTokens.d.ts +4 -2
  100. package/lib/filterTokens.js +29 -10
  101. package/lib/fs.js +1 -0
  102. package/lib/performActions.d.ts +7 -5
  103. package/lib/performActions.js +12 -10
  104. package/lib/transform/object.d.ts +7 -4
  105. package/lib/transform/object.js +11 -7
  106. package/lib/transform/token.d.ts +6 -3
  107. package/lib/transform/token.js +16 -14
  108. package/lib/utils/combineJSON.d.ts +6 -2
  109. package/lib/utils/combineJSON.js +9 -3
  110. package/lib/utils/createFormatArgs.d.ts +5 -1
  111. package/lib/utils/createFormatArgs.js +9 -4
  112. package/lib/utils/detectDtcgSyntax.d.ts +8 -0
  113. package/lib/utils/detectDtcgSyntax.js +26 -0
  114. package/lib/utils/flattenTokens.d.ts +2 -7
  115. package/lib/utils/flattenTokens.js +21 -14
  116. package/lib/utils/index.d.ts +2 -2
  117. package/lib/utils/index.js +2 -2
  118. package/lib/utils/preprocess.d.ts +3 -1
  119. package/lib/utils/preprocess.js +17 -15
  120. package/lib/utils/references/getReferences.d.ts +7 -9
  121. package/lib/utils/references/getReferences.js +6 -5
  122. package/lib/utils/references/resolveReferences.d.ts +6 -6
  123. package/lib/utils/references/resolveReferences.js +10 -11
  124. package/package.json +1 -1
  125. package/types/Action.d.ts +3 -3
  126. package/types/Config.d.ts +9 -2
  127. package/types/File.d.ts +1 -1
  128. package/types/Filter.d.ts +1 -1
  129. package/types/Format.d.ts +5 -3
  130. package/types/Parser.d.ts +1 -1
  131. package/types/Transform.d.ts +6 -2
  132. package/types/FormatHelpers.d.ts +0 -0
@@ -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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15",
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.15"
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.15"
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.15"
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.15"
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.15"
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.15"
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.15",
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.15';
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 = await 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
+ await buildFiles(dictionary, platformConfig, this.options);
415
+ await performActions(dictionary, platformConfig, this.options);
382
416
  // For chaining
383
417
  return this;
384
418
  }
@@ -399,9 +433,9 @@ export default class StyleDictionary extends Register {
399
433
  async cleanPlatform(platform) {
400
434
  const { dictionary, platformConfig } = await this.getPlatform(platform);
401
435
  // We clean files first, then actions, ...and then directories?
402
- cleanFiles(platformConfig);
403
- cleanActions(dictionary, platformConfig);
404
- cleanDirs(platformConfig);
436
+ await cleanFiles(platformConfig);
437
+ await cleanActions(dictionary, platformConfig, this.options);
438
+ await cleanDirs(platformConfig);
405
439
  // For chaining
406
440
  return this;
407
441
  }
@@ -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): Promise<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 async 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 = await 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 ');
@@ -112,17 +114,18 @@ export default function buildFile(file, platform = {}, dictionary) {
112
114
  });
113
115
 
114
116
  const tokenNamesCollisionCount = GroupMessages.count(PROPERTY_NAME_COLLISION_WARNINGS);
115
- fs.writeFileSync(
116
- fullDestination,
117
- format(
118
- createFormatArgs({
119
- dictionary: filteredDictionary,
120
- platform,
121
- file,
122
- }),
123
- ),
117
+
118
+ const formattedContent = await format(
119
+ createFormatArgs({
120
+ dictionary: filteredDictionary,
121
+ platform,
122
+ options,
123
+ file,
124
+ }),
124
125
  );
125
126
 
127
+ await fs.promises.writeFile(fullDestination, formattedContent);
128
+
126
129
  const filteredReferencesCount = GroupMessages.count(GroupMessages.GROUP.FilteredOutputReferences);
127
130
 
128
131
  // don't show name collision warnings for nested type formats
@@ -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): Promise<(null | undefined)[] | undefined>;
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 async function buildFiles(dictionary, platform, options) {
31
33
  if (
32
34
  platform.buildPath &&
33
35
  platform.buildPath.slice(-1) !== '/' &&
@@ -36,11 +38,15 @@ export default function buildFiles(dictionary, platform) {
36
38
  throw new Error('Build path must end in a trailing slash or you will get weird file names.');
37
39
  }
38
40
 
39
- platform.files?.forEach(function (file) {
40
- if (file.format) {
41
- buildFile(file, platform, dictionary);
42
- } else {
43
- throw new Error('Please supply a format');
44
- }
45
- });
41
+ if (platform.files) {
42
+ return Promise.all(
43
+ platform.files.map((file) => {
44
+ if (file.format) {
45
+ return buildFile(file, platform, dictionary, options);
46
+ } else {
47
+ throw new Error('Please supply a format');
48
+ }
49
+ }),
50
+ );
51
+ }
46
52
  }
@@ -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): Promise<void[] | undefined>;
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,15 +25,17 @@
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 async function cleanActions(dictionary, platform, options) {
30
32
  if (platform.actions) {
31
- platform.actions.forEach(function (action) {
32
- // ensure we've augmented action with the do/undo functions and that undo exists
33
- if (typeof action !== 'string' && typeof action.undo === 'function') {
34
- action.undo(dictionary, platform);
35
- }
36
- });
33
+ return Promise.all(
34
+ platform.actions.map((action) => {
35
+ if (typeof action !== 'string' && typeof action.undo === 'function') {
36
+ return action.undo(dictionary, platform, options);
37
+ }
38
+ }),
39
+ );
37
40
  }
38
41
  }
package/lib/cleanDir.d.ts CHANGED
@@ -9,6 +9,6 @@
9
9
  * @param {File} file
10
10
  * @param {Config} [platform]
11
11
  */
12
- export default function cleanDir(file: File, platform?: import("../types/Config.d.ts").PlatformConfig | undefined): void;
12
+ export default function cleanDir(file: File, platform?: import("../types/Config.d.ts").PlatformConfig | undefined): Promise<void>;
13
13
  export type Config = import('../types/Config.d.ts').PlatformConfig;
14
14
  export type File = import('../types/File.d.ts').File;
package/lib/cleanDir.js CHANGED
@@ -27,7 +27,7 @@ import { fs } from 'style-dictionary/fs';
27
27
  * @param {File} file
28
28
  * @param {Config} [platform]
29
29
  */
30
- export default function cleanDir(file, platform = {}) {
30
+ export default async function cleanDir(file, platform = {}) {
31
31
  let { destination } = file;
32
32
 
33
33
  if (typeof destination !== 'string') throw new Error('Please enter a valid destination');
@@ -41,10 +41,11 @@ export default function cleanDir(file, platform = {}) {
41
41
 
42
42
  while (dir) {
43
43
  if (fs.existsSync(dir)) {
44
- if (fs.readdirSync(dir, 'buffer').length === 0) {
44
+ const dirContents = fs.readdirSync(dir, 'buffer');
45
+ if (dirContents.length === 0) {
45
46
  // eslint-disable-next-line no-console
46
47
  console.log(chalk.bold.red('-') + ' ' + dir);
47
- fs.rmdirSync(dir);
48
+ fs.rmSync(dir, { recursive: true });
48
49
  } else {
49
50
  break;
50
51
  }
@@ -9,5 +9,5 @@
9
9
  * @memberOf StyleDictionary
10
10
  * @param {Config} platform
11
11
  */
12
- export default function cleanDirs(platform: Config): void;
12
+ export default function cleanDirs(platform: Config): Promise<void[] | undefined>;
13
13
  export type Config = import('../types/Config.d.ts').PlatformConfig;
package/lib/cleanDirs.js CHANGED
@@ -25,17 +25,20 @@ import cleanDir from './cleanDir.js';
25
25
  * @memberOf StyleDictionary
26
26
  * @param {Config} platform
27
27
  */
28
- export default function cleanDirs(platform) {
28
+ export default async function cleanDirs(platform) {
29
29
  if (platform.buildPath && platform.buildPath.slice(-1) !== '/') {
30
30
  throw new Error('Build path must end in a trailing slash or you will get weird file names.');
31
31
  }
32
32
 
33
- // while neither the format or dictionary are used by clean file I'm passing them in for symmetry to buildFile
34
- platform.files?.forEach((file) => {
35
- if (file.format) {
36
- cleanDir(file, platform);
37
- } else {
38
- throw new Error('Please supply a format');
39
- }
40
- });
33
+ if (platform.files) {
34
+ return Promise.all(
35
+ platform.files?.map((file) => {
36
+ if (file.format) {
37
+ return cleanDir(file, platform);
38
+ } else {
39
+ throw new Error('Please supply a format');
40
+ }
41
+ }),
42
+ );
43
+ }
41
44
  }