-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathgenerate-css.ts
executable file
·35 lines (28 loc) · 1.23 KB
/
generate-css.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
// We can't use the Dart Sass CLI directly, since it doesn't support our custom tilde importer.
// So, we have this small wrapper around the Node API that gives us access to it.
import fs from 'fs';
import sass, { LegacyImporter } from 'sass';
import nodeSassImporter from 'node-sass-tilde-importer';
/**
* Ensures that errors throw an error with a stacktrace.
*/
process.on('unhandledRejection', error => {
throw error;
});
const compileSass = async (fromFile: string): Promise<void> => {
// We can't use the new `compile` method because it uses a new API for importers, which don't
// match our tilde importer. So for now we're stuck with the legacy `renderSync` method.
const { css } = sass.renderSync({
file: fromFile,
// The only difference is in the return type, which doesn't make a difference in practice,
// so we're safe to typecast here.
importer: nodeSassImporter as LegacyImporter<'sync'>,
});
const outputFileName = fromFile.replace('src/', 'dist/').replace('.scss', '.css');
return fs.writeFileSync(outputFileName, css);
};
(async (): Promise<void> => {
// Create a single CSS file with all the code.
await compileSass('src/atomic.scss');
})();