1 | const sass = require('node-sass');
|
2 | const { existsSync, mkdirSync, writeFileSync, readdirSync, lstatSync } = require('fs');
|
3 |
|
4 | const sourceDir = './src';
|
5 | const destinationDir = './dist';
|
6 | const sassFiles = [];
|
7 |
|
8 | readdirSync(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 |
|
21 | if (!existsSync(destinationDir)) mkdirSync(destinationDir);
|
22 |
|
23 | sassFiles.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 | });
|