UNPKG

1 kBJavaScriptView Raw
1const sass = require('node-sass');
2const { existsSync, mkdirSync, writeFileSync, readdirSync, lstatSync } = require('fs');
3
4const sourceDir = './src';
5const destinationDir = './dist';
6const sassFiles = [];
7
8readdirSync(sourceDir).forEach(path => {
9 if (lstatSync(`${sourceDir}/${path}`).isDirectory()) {
10 if (path === 'node_modules' || path === 'test') return;
11 readdirSync(`${sourceDir}/${path}`).forEach(file => {
12 if ( ! file.endsWith('.scss')) return;
13 sassFiles.push({
14 path,
15 file,
16 });
17 });
18 }
19});
20
21if (!existsSync(destinationDir)) mkdirSync(destinationDir);
22
23sassFiles.forEach(sassFile => {
24 const { path, file } = sassFile;
25
26 const cssContent = sass.renderSync({
27 file: `${sourceDir}/${path}/${file}`,
28 outputStyle: 'compressed'
29 });
30
31 if (!existsSync(`${destinationDir}/${path}`)) mkdirSync(`${destinationDir}/${path}`);
32
33 writeFileSync(
34 `${destinationDir}/${path}/${file.replace('.scss', '.css')}`,
35 cssContent.css.toString()
36 );
37});