|
| 1 | +module.exports = { |
| 2 | + source: [`tokens/**/*.json`], |
| 3 | + // If you don't want to call the registerTransform method a bunch of times |
| 4 | + // you can override the whole transform object directly. This works because |
| 5 | + // the .extend method copies everything in the config |
| 6 | + // to itself, allowing you to override things. It's also doing a deep merge |
| 7 | + // to protect from accidentally overriding nested attributes. |
| 8 | + transform: { |
| 9 | + // Now we can use the transform 'myTransform' below |
| 10 | + myTransform: { |
| 11 | + type: "name", |
| 12 | + transformer: (token) => token.path.join("_").toUpperCase(), |
| 13 | + }, |
| 14 | + }, |
| 15 | + action: { |
| 16 | + colorsets: require("./src/colorset-action"), |
| 17 | + }, |
| 18 | + // Same with formats, you can now write them directly to this config |
| 19 | + // object. The name of the format is the key. |
| 20 | + format: { |
| 21 | + myFormat: ({ dictionary }) => { |
| 22 | + return dictionary.allTokens |
| 23 | + .map((token) => `${token.name}: ${token.value}`) |
| 24 | + .join("\n"); |
| 25 | + }, |
| 26 | + }, |
| 27 | + parsers: [ |
| 28 | + { |
| 29 | + pattern: /\.json|\.tokens\.json|\.tokens$/, |
| 30 | + parse: ({ contents }) => { |
| 31 | + // replace $value with value so that style dictionary recognizes it |
| 32 | + const preparedContent = (contents || "{}") |
| 33 | + .replace(/"\$?value":/g, '"value":') |
| 34 | + // convert $description to comment |
| 35 | + .replace(/"\$?description":/g, '"comment":'); |
| 36 | + // |
| 37 | + return JSON.parse(preparedContent); |
| 38 | + }, |
| 39 | + }, |
| 40 | + ], |
| 41 | + platforms: { |
| 42 | + css: { |
| 43 | + transformGroup: "css", |
| 44 | + transforms: ["attribute/cti", "name/cti/kebab", "size/px"], |
| 45 | + files: [ |
| 46 | + { |
| 47 | + destination: "assets/web/css/tokens.css", |
| 48 | + format: "css/variables", |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + js: { |
| 53 | + transformGroup: `web`, |
| 54 | + buildPath: "assets/web/js/", |
| 55 | + files: [ |
| 56 | + { |
| 57 | + destination: `tokens.json`, |
| 58 | + format: `json/flat`, |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + "ios-colorsets": { |
| 63 | + buildPath: "assets/ios/", |
| 64 | + transforms: ["attribute/cti", "name/cti/pascal", "attribute/color"], |
| 65 | + actions: [`colorsets`], |
| 66 | + }, |
| 67 | + compose: { |
| 68 | + transformGroup: `compose`, |
| 69 | + files: [ |
| 70 | + { |
| 71 | + destination: "assets/android/StyleDictionary.kt", |
| 72 | + format: "compose/object", |
| 73 | + className: "StyleDictionary", |
| 74 | + packageName: "io.element.compound.tokens", |
| 75 | + }, |
| 76 | + { |
| 77 | + destination: "assets/android/StyleDictionaryWithReferences.kt", |
| 78 | + format: "compose/object", |
| 79 | + className: "StyleDictionary", |
| 80 | + packageName: "io.element.compound.tokens", |
| 81 | + options: { |
| 82 | + outputReferences: true, |
| 83 | + }, |
| 84 | + }, |
| 85 | + ], |
| 86 | + }, |
| 87 | + }, |
| 88 | +}; |
0 commit comments