Created
October 25, 2018 23:59
-
-
Save mannyyang/f5cb6db4e86e2bbd24a659300bf3ca1b to your computer and use it in GitHub Desktop.
Generating a SCSS color variable file from a Tailwind config file.
This file contains hidden or 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
| const fs = require('fs'); | |
| const path = require('path'); | |
| const TailwindConfig = require('./tailwind.config'); | |
| const colors = TailwindConfig.colors; | |
| const outPath = path.join(__dirname, 'theme-variables.scss'); | |
| // If the file exists, delete it. | |
| fs.unlink(outPath, err => { | |
| if (err && err.code !== 'ENOENT') return console.error(err); | |
| // Iterate through the colors property of the tailwinds config | |
| // and create a scss variable for each color. | |
| Object.keys(colors).forEach(key => { | |
| let line = `$--${key}: ${colors[key]};\n`; | |
| fs.appendFile(outPath, line, err => { | |
| if (err) return console.error(err); | |
| console.log(`wrote ${key} color`); | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment