figma-tokens-flattener 1.0.15 → 1.0.17
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/consts.js +3 -0
- package/index.js +23 -6
- package/package.json +1 -1
package/consts.js
ADDED
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const REUSED_KEYS = require('./consts.js');
|
|
5
6
|
|
|
6
7
|
/* Color */
|
|
7
8
|
function flattenColorGroups(colorGroups) {
|
|
@@ -410,6 +411,22 @@ function flattenComponentsTokens(componentsTokens, contextTokens) {
|
|
|
410
411
|
return flattened;
|
|
411
412
|
}
|
|
412
413
|
|
|
414
|
+
function addReusedTokens(lightTokens, darkTokens) {
|
|
415
|
+
const reusedCollection = {};
|
|
416
|
+
|
|
417
|
+
Object.keys(lightTokens).forEach((key) => {
|
|
418
|
+
const value = lightTokens[key];
|
|
419
|
+
|
|
420
|
+
if (typeof value === 'number' || REUSED_KEYS.includes(key)) {
|
|
421
|
+
reusedCollection[key] = value;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// darkTokens will take precedence in case of a key match.
|
|
427
|
+
return { ...darkTokens, ...reusedCollection };
|
|
428
|
+
}
|
|
429
|
+
|
|
413
430
|
function flatten() {
|
|
414
431
|
const configFilePath = path.resolve('./figma-tokens-flattener-config.json');
|
|
415
432
|
let config = {};
|
|
@@ -444,7 +461,7 @@ function flatten() {
|
|
|
444
461
|
const lightDefaultKey = `Default/Light`;
|
|
445
462
|
const darkDefaultKey = `Default/Dark`;
|
|
446
463
|
|
|
447
|
-
//
|
|
464
|
+
//Processing of light tokens
|
|
448
465
|
if (allTokensData.hasOwnProperty(lightFullKey)) {
|
|
449
466
|
// Special processing transformation of each collection into a flat structure
|
|
450
467
|
|
|
@@ -478,7 +495,7 @@ function flatten() {
|
|
|
478
495
|
console.warn(`Collection not found, collection key: ${lightFullKey}`);
|
|
479
496
|
}
|
|
480
497
|
|
|
481
|
-
//
|
|
498
|
+
//Processing of dark tokens
|
|
482
499
|
if (allTokensData.hasOwnProperty(darkFullKey)) {
|
|
483
500
|
|
|
484
501
|
if (baseKey === 'colors') {
|
|
@@ -503,6 +520,10 @@ function flatten() {
|
|
|
503
520
|
const flattenDefaultValues = flattenDefaultValueTokens(allTokensData[darkDefaultKey]);
|
|
504
521
|
darkTokens = { ...flattenDefaultValues, ...darkTokens };
|
|
505
522
|
|
|
523
|
+
// The tokens of the light theme contain numeric values, while the dark theme does not contain them to avoid duplication.
|
|
524
|
+
// Need to add these values, and some lines (shadows, focus, etc.) because only the light theme has them too.
|
|
525
|
+
darkTokens = addReusedTokens(lightTokens, darkTokens);
|
|
526
|
+
|
|
506
527
|
const flattenedComponents = flattenComponentsTokens(allTokensData[darkFullKey], darkTokens);
|
|
507
528
|
darkTokens = { ...darkTokens, components: flattenedComponents };
|
|
508
529
|
}
|
|
@@ -533,8 +554,4 @@ function flatten() {
|
|
|
533
554
|
}
|
|
534
555
|
};
|
|
535
556
|
|
|
536
|
-
// module.exports = {
|
|
537
|
-
// flatten
|
|
538
|
-
// };
|
|
539
|
-
|
|
540
557
|
flatten();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figma-tokens-flattener",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A tool for transforming Ant Design tokens from Tokens Studio for Figma (Single file) into flat style mappings for light and dark themes.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|