Skip to content

Commit

Permalink
disallow expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Aug 9, 2021
1 parent 5900594 commit da83581
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/make-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ 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 css = source.match(/export default css`(.*?)`;/s)[1];

// We're currently scraping for CSS with a regex, so we can't use interpolation at the moment
if (css.includes('${')) {
console.error(
chalk.red(`Template literal expressions are not currently supported in theme stylesheets: ${file}`)
);
process.exit(1);
}

const formattedStyles = prettier.format(stripComments(css), { parser: 'css' });
const filename = path.basename(file).replace('.styles.ts', '.css');
const outfile = path.join(outdir, filename);
await fs.writeFile(outfile, css, 'utf8');
await fs.writeFile(outfile, formattedStyles, 'utf8');
});

console.log(chalk.cyan(`Successfully generated stylesheets 馃帹\n`));
Expand Down

0 comments on commit da83581

Please sign in to comment.