-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace hard-coded TW tables with build-generated alternative
- Loading branch information
1 parent
bfdc50a
commit c2f8e4b
Showing
8 changed files
with
241 additions
and
864 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ yarn-error.log | |
/reset | ||
.idea/* | ||
types | ||
index.d.ts | ||
index.d.ts | ||
computed-colors-*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { | ||
numericalColors, | ||
variants, | ||
prefixes, | ||
Theme, | ||
ComputedColors, | ||
} from "../src/core/styles/colors/types"; | ||
|
||
const computeColors = (base: Theme) => { | ||
const colors = {} as ComputedColors; | ||
|
||
variants.forEach((variant) => | ||
prefixes.forEach((property) => | ||
numericalColors.forEach((colorSet) => | ||
colorSet.map((color, index) => { | ||
if (base === "dark") { | ||
colors[`${variant}${property}-${colorSet[index]}`] = { | ||
light: `${variant}${property}-${colorSet[colorSet.length - index - 1]}`, | ||
}; | ||
} else if (base === "light") { | ||
colors[`${variant}${property}-${colorSet[index]}`] = { | ||
dark: `${variant}${property}-${colorSet[colorSet.length - index - 1]}`, | ||
}; | ||
} | ||
}), | ||
), | ||
), | ||
); | ||
|
||
return colors; | ||
}; | ||
|
||
const darkOutputPath = path.join(__dirname, "..", "computed-colors-dark.json"); | ||
const lightOutputPath = path.join( | ||
__dirname, | ||
"..", | ||
"computed-colors-light.json", | ||
); | ||
|
||
try { | ||
fs.writeFileSync( | ||
darkOutputPath, | ||
JSON.stringify(computeColors("dark"), null, 2), | ||
"utf-8", | ||
); | ||
fs.writeFileSync( | ||
lightOutputPath, | ||
JSON.stringify(computeColors("light"), null, 2), | ||
"utf-8", | ||
); | ||
console.log( | ||
`🎨 Tailwind theme classes have been computed and written to computed-colors.json.`, | ||
); | ||
} catch { | ||
console.error(`Error persisting computed colors.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.