Skip to content

Instantly share code, notes, and snippets.

@aulisius
Created February 24, 2021 09:22
Show Gist options
  • Save aulisius/35602c1f9376f738af8976128c41caa6 to your computer and use it in GitHub Desktop.
Save aulisius/35602c1f9376f738af8976128c41caa6 to your computer and use it in GitHub Desktop.
Theo Tailwind v2 Transform
const camelCase = require("lodash/camelCase");
const kebabCase = require("lodash/kebabCase");
const theo = require("theo");
theo.registerFormat("tailwindv2", (result) => {
// "result" is an Immutable.Map
// https://facebook.github.io/immutable-js/
let tailwindTheme = {
textColor: {},
backgroundColor: {},
fontFamily: {},
};
result.get("props").forEach((prop) => {
let name = prop.get("name");
let cssVar = `var(--${kebabCase(name)})`;
console.log(prop.get("category"));
switch (prop.get("category")) {
case "text-color":
{
let property = name.replace("TEXT_", "");
tailwindTheme.textColor[camelCase(property)] = cssVar;
}
break;
case "background-color":
{
let property = name.replace("BG_", "");
tailwindTheme.backgroundColor[camelCase(property)] = cssVar;
}
break;
default:
break;
}
});
return `
module.exports = ${JSON.stringify(tailwindTheme, null, 2)}
`;
});
theo
.convert({
transform: { type: "web", file: "./design-tokens/app.json" },
format: { type: "tailwindv2" },
})
.then((config) => require("fs").writeFileSync("tailwindv2.js", config))
.catch((error) => console.log(`Something went wrong: ${error}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment