Skip to content

Commit

Permalink
custom formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
CCAyl committed Aug 11, 2022
1 parent 7d23881 commit d0b1b17
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const StyleDictionary = require("style-dictionary");
const ChangeCase = require("change-case");
const { fileHeader, getTypeScriptType } = StyleDictionary.formatHelpers;

function isStringPxValue(token) {
const isStringPxValue = (token) => {
if (typeof token.value === "string") {
return token.value.endsWith("px");
}
}
};

StyleDictionary.registerFilter({
name: "filter-typography",
Expand Down Expand Up @@ -51,6 +52,24 @@ StyleDictionary.registerTransform({
},
});

StyleDictionary.registerFormat({
name: `typescript/color-declaration`,
formatter: ({ dictionary, file }) => {
return (
fileHeader({ file }) +
Object.entries(dictionary.properties.colors)
.map((tokens) => {
return `export const ${tokens[0]} : {${Object.entries(tokens[1]).map(
(token) => {
return `${token[0]} : ${getTypeScriptType(token[1].value)}`;
}
)}};`;
})
.join(`\n`)
);
},
});

StyleDictionary.registerTransformGroup({
name: "custom/aviary",
transforms: [
Expand Down Expand Up @@ -118,7 +137,7 @@ const getStyleDictionaryConfig = (theme) => {
},
},
{
format: "typescript/es6-declarations",
format: "typescript/color-declaration",
destination: core ? "colors.d.ts" : `themes/${theme}.d.ts`,
filter: {
type: "color",
Expand Down Expand Up @@ -149,7 +168,7 @@ const getStyleDictionaryConfig = (theme) => {
},
},
{
format: "typescript/es6-declarations",
format: "typescript/color-declaration",
destination: core ? "colors.d.ts" : `themes/${theme}.d.ts`,
filter: {
type: "color",
Expand Down

0 comments on commit d0b1b17

Please sign in to comment.