generate css files from themes/*.styles.ts

This commit is contained in:
Cory LaViska
2021-08-05 16:48:15 -04:00
parent 3877e89277
commit c5d4c532b3
10 changed files with 941 additions and 897 deletions

31
scripts/make-css.js Normal file
View File

@@ -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);
}