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.
- package/examples/advanced/assets-base64-embed/package.json +1 -1
- package/examples/advanced/auto-rebuild-watcher/package.json +1 -1
- package/examples/advanced/component-cti/package.json +1 -1
- package/examples/advanced/create-react-app/package.json +1 -1
- package/examples/advanced/create-react-native-app/package.json +1 -1
- package/examples/advanced/custom-file-header/package.json +1 -1
- package/examples/advanced/custom-filters/package.json +1 -1
- package/examples/advanced/custom-formats-with-templates/package.json +1 -1
- package/examples/advanced/custom-parser/package.json +1 -1
- package/examples/advanced/custom-transforms/package.json +1 -1
- package/examples/advanced/font-face-rules/package.json +1 -1
- package/examples/advanced/format-helpers/package.json +1 -1
- package/examples/advanced/matching-build-files/package.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
- package/examples/advanced/npm-module/package.json +1 -1
- package/examples/advanced/referencing_aliasing/package.json +1 -1
- package/examples/advanced/s3/package.json +1 -1
- package/examples/advanced/tokens-deprecation/package.json +1 -1
- package/examples/advanced/transitive-transforms/package.json +1 -1
- package/examples/advanced/variables-in-outputs/package.json +1 -1
- package/examples/advanced/yaml-tokens/package.json +1 -1
- package/lib/StyleDictionary.js +47 -13
- package/lib/buildFile.d.ts +4 -1
- package/lib/buildFile.js +15 -12
- package/lib/buildFiles.d.ts +7 -4
- package/lib/buildFiles.js +16 -10
- package/lib/cleanActions.d.ts +7 -4
- package/lib/cleanActions.js +12 -9
- package/lib/cleanDir.d.ts +1 -1
- package/lib/cleanDir.js +4 -3
- package/lib/cleanDirs.d.ts +1 -1
- package/lib/cleanDirs.js +12 -9
- package/lib/cleanFile.d.ts +1 -1
- package/lib/cleanFile.js +1 -1
- package/lib/cleanFiles.d.ts +1 -1
- package/lib/cleanFiles.js +12 -9
- package/lib/common/actions.js +28 -23
- package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
- package/lib/common/formatHelpers/createPropertyFormatter.js +7 -8
- package/lib/common/formatHelpers/fileHeader.d.ts +2 -2
- package/lib/common/formatHelpers/fileHeader.js +5 -3
- package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
- package/lib/common/formatHelpers/formattedVariables.js +3 -0
- package/lib/common/formatHelpers/getTypeScriptType.d.ts +4 -2
- package/lib/common/formatHelpers/getTypeScriptType.js +3 -2
- package/lib/common/formatHelpers/iconsWithPrefix.d.ts +4 -1
- package/lib/common/formatHelpers/iconsWithPrefix.js +6 -3
- package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -1
- package/lib/common/formatHelpers/minifyDictionary.js +5 -4
- package/lib/common/formatHelpers/sortByReference.js +3 -3
- package/lib/common/formats.js +147 -130
- package/lib/common/templates/android/colors.template.d.ts +1 -1
- package/lib/common/templates/android/colors.template.js +2 -2
- package/lib/common/templates/android/dimens.template.d.ts +1 -1
- package/lib/common/templates/android/dimens.template.js +2 -2
- package/lib/common/templates/android/fontDimens.template.d.ts +1 -1
- package/lib/common/templates/android/fontDimens.template.js +2 -2
- package/lib/common/templates/android/integers.template.d.ts +1 -1
- package/lib/common/templates/android/integers.template.js +2 -2
- package/lib/common/templates/android/resources.template.d.ts +3 -1
- package/lib/common/templates/android/resources.template.js +6 -4
- package/lib/common/templates/android/strings.template.d.ts +1 -1
- package/lib/common/templates/android/strings.template.js +2 -2
- package/lib/common/templates/compose/object.kt.template.d.ts +1 -1
- package/lib/common/templates/compose/object.kt.template.js +1 -1
- package/lib/common/templates/flutter/class.dart.template.d.ts +1 -1
- package/lib/common/templates/flutter/class.dart.template.js +1 -1
- package/lib/common/templates/ios/colors.h.template.d.ts +1 -1
- package/lib/common/templates/ios/colors.h.template.js +1 -1
- package/lib/common/templates/ios/colors.m.template.d.ts +1 -1
- package/lib/common/templates/ios/colors.m.template.js +2 -2
- package/lib/common/templates/ios/macros.template.d.ts +1 -1
- package/lib/common/templates/ios/macros.template.js +2 -2
- package/lib/common/templates/ios/plist.template.d.ts +1 -1
- package/lib/common/templates/ios/plist.template.js +6 -6
- package/lib/common/templates/ios/singleton.h.template.d.ts +1 -1
- package/lib/common/templates/ios/singleton.h.template.js +1 -1
- package/lib/common/templates/ios/singleton.m.template.d.ts +1 -1
- package/lib/common/templates/ios/singleton.m.template.js +3 -3
- package/lib/common/templates/ios/static.h.template.d.ts +1 -1
- package/lib/common/templates/ios/static.h.template.js +1 -1
- package/lib/common/templates/ios/static.m.template.d.ts +1 -1
- package/lib/common/templates/ios/static.m.template.js +2 -2
- package/lib/common/templates/ios/strings.h.template.d.ts +1 -1
- package/lib/common/templates/ios/strings.h.template.js +1 -1
- package/lib/common/templates/ios/strings.m.template.d.ts +1 -1
- package/lib/common/templates/ios/strings.m.template.js +3 -3
- package/lib/common/templates/ios-swift/any.swift.template.d.ts +1 -1
- package/lib/common/templates/ios-swift/any.swift.template.js +1 -1
- package/lib/common/templates/scss/map-deep.template.d.ts +1 -1
- package/lib/common/templates/scss/map-deep.template.js +1 -1
- package/lib/common/templates/scss/map-flat.template.d.ts +1 -1
- package/lib/common/templates/scss/map-flat.template.js +2 -2
- package/lib/common/templates/static-style-guide/index.html.template.d.ts +1 -1
- package/lib/common/templates/static-style-guide/index.html.template.js +2 -2
- package/lib/common/transforms.d.ts +2 -1
- package/lib/common/transforms.js +125 -119
- package/lib/filterTokens.d.ts +4 -2
- package/lib/filterTokens.js +29 -10
- package/lib/fs.js +1 -0
- package/lib/performActions.d.ts +7 -5
- package/lib/performActions.js +12 -10
- package/lib/transform/object.d.ts +7 -4
- package/lib/transform/object.js +11 -7
- package/lib/transform/token.d.ts +6 -3
- package/lib/transform/token.js +16 -14
- package/lib/utils/combineJSON.d.ts +6 -2
- package/lib/utils/combineJSON.js +9 -3
- package/lib/utils/createFormatArgs.d.ts +5 -1
- package/lib/utils/createFormatArgs.js +9 -4
- package/lib/utils/detectDtcgSyntax.d.ts +8 -0
- package/lib/utils/detectDtcgSyntax.js +26 -0
- package/lib/utils/flattenTokens.d.ts +2 -7
- package/lib/utils/flattenTokens.js +21 -14
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +2 -2
- package/lib/utils/preprocess.d.ts +3 -1
- package/lib/utils/preprocess.js +17 -15
- package/lib/utils/references/getReferences.d.ts +7 -9
- package/lib/utils/references/getReferences.js +6 -5
- package/lib/utils/references/resolveReferences.d.ts +6 -6
- package/lib/utils/references/resolveReferences.js +10 -11
- package/package.json +1 -1
- package/types/Action.d.ts +3 -3
- package/types/Config.d.ts +9 -2
- package/types/File.d.ts +1 -1
- package/types/Filter.d.ts +1 -1
- package/types/Format.d.ts +5 -3
- package/types/Parser.d.ts +1 -1
- package/types/Transform.d.ts +6 -2
- package/types/FormatHelpers.d.ts +0 -0
package/lib/StyleDictionary.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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[]} */ (
|
|
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
|
}
|
package/lib/buildFile.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
package/lib/buildFiles.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
3
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
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 {
|
|
13
|
+
* @param {PlatformConfig} platform
|
|
14
|
+
* @param {Config} options
|
|
13
15
|
*/
|
|
14
|
-
export default function buildFiles(dictionary: Dictionary, platform: Config):
|
|
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
|
|
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}
|
|
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 {
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
}
|
package/lib/cleanActions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
3
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
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 {
|
|
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
|
|
19
|
+
export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
|
|
20
|
+
export type Config = import('../types/Config.d.ts').Config;
|
package/lib/cleanActions.js
CHANGED
|
@@ -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}
|
|
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 {
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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.
|
|
48
|
+
fs.rmSync(dir, { recursive: true });
|
|
48
49
|
} else {
|
|
49
50
|
break;
|
|
50
51
|
}
|
package/lib/cleanDirs.d.ts
CHANGED
|
@@ -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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
}
|