colors.ts 838 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bun
  2. // read lines from colors.txt
  3. // parse each line into a color name and hex value
  4. // create a css variable for each color
  5. // NOTE: only use Bun file APIs here
  6. const colors = await Bun.file(import.meta.dir + "/colors.txt").text()
  7. const variables = []
  8. for (const line of colors.split("\n")) {
  9. if (!line.trim()) continue
  10. const [variable] = line.trim().split(":")
  11. const name = variable!.trim().substring(2)
  12. variables.push(`--color-${name}: var(--${name});`)
  13. }
  14. const output = `
  15. /* Generated by script/colors.ts */
  16. /* Do not edit this file manually */
  17. @theme {
  18. --color-*: initial;
  19. ${variables.join("\n ")}
  20. }
  21. `
  22. // write to src/tailwind-colors.css
  23. Bun.file(import.meta.dir + "/../src/tailwind-colors.css").write(output.trim())
  24. // Bun.file(import.meta.dir + "../src/tailwind-colors.css").write(output.trim())