-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate css files from themes/*.styles.ts
- Loading branch information
Showing
10 changed files
with
941 additions
and
897 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,31 @@ | ||
// | ||
// This script generates stylesheets from all *.styles.ts files in src/themes | ||
// | ||
import chalk from 'chalk'; | ||
import esbuild from 'esbuild'; | ||
import fs from 'fs/promises'; | ||
import glob from 'globby'; | ||
import mkdirp from 'mkdirp'; | ||
import path from 'path'; | ||
import prettier from 'prettier'; | ||
import stripComments from 'strip-css-comments'; | ||
|
||
const files = glob.sync('./src/themes/**/*.styles.ts'); | ||
const outdir = './dist/themes'; | ||
|
||
mkdirp.sync(outdir); | ||
|
||
try { | ||
files.map(async file => { | ||
const source = await fs.readFile(file, 'utf8'); | ||
const css = prettier.format(stripComments(source.match(/export default css`(.*?)`;/s)[1]), { parser: 'css' }); | ||
const filename = path.basename(file).replace('.styles.ts', '.css'); | ||
const outfile = path.join(outdir, filename); | ||
await fs.writeFile(outfile, css, 'utf8'); | ||
}); | ||
|
||
console.log(chalk.cyan(`Successfully generated stylesheets 🎨\n`)); | ||
} catch (err) { | ||
console.error(chalk.red('Error generating styleseheets!')); | ||
console.error(err); | ||
} |
Oops, something went wrong.