Created
November 1, 2018 12:41
-
-
Save thomasJang/92a738a2a3b9bbeb9d4bcff8066abfc8 to your computer and use it in GitHub Desktop.
generate-less-var.ts
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 path = require('path'); | |
| const fs = require('fs-extra'); | |
| const chalk = require('chalk'); | |
| const srcPath = '../src/styles/theme.ts'; | |
| const srcResoloved = path.resolve(__dirname, srcPath); | |
| const target = path.resolve(__dirname, '../src/styles/less/theme-vars.less'); | |
| const buildLessVar = () => { | |
| delete require.cache[srcResoloved]; | |
| const theme = require(srcPath); | |
| fs.writeFileSync( | |
| target, | |
| Object.keys(theme.default) | |
| .map(k => `@${k.replace('_', '-')}: ${theme.default[k]};`) | |
| .join('\r\n'), | |
| ); | |
| }; | |
| // watch file theme.js to less-var | |
| fs.watchFile(srcResoloved, { interval: 1000 }, (event: any, filename: any) => { | |
| try { | |
| buildLessVar(); | |
| console.log(chalk.red('update LESS file : ') + target); | |
| } catch (e) { | |
| console.log(chalk.bgRed(e)); | |
| } | |
| }); | |
| console.log(chalk.yellow.bold(`Watching theme files : `) + srcResoloved); | |
| // build less vars | |
| buildLessVar(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment