This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
compileSass.ts
58 lines (51 loc) · 1.77 KB
/
compileSass.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Application } from 'express';
import * as path from 'path';
import * as config from 'config';
import {
default as compileSass,
compileSassAndSaveMultiple,
setupCleanupOnExit as setupCleanupOnExitCs
} from 'compile-sass';
import { CssConfigInterface } from '../../interfaces/Config';
const cssConfig: CssConfigInterface = config.get('css');
const publicFolder: string = path.resolve(__dirname, '../../public');
const srcFolder: string = config.get('folders.srcFolder');
function setupCleanupOnExit(): void {
process.on('SIGINT', (): void => {
try {
setupCleanupOnExitCs(path.resolve(publicFolder, 'css/'));
process.exit(0);
}
catch(error) {
process.exit(1);
}
});
}
export default (app: Application): Promise<void> => {
if (app.get('env') === 'staging' || app.get('env') === 'production') {
return compileSassAndSaveMultiple({
sassPath: path.resolve(srcFolder, 'scss/'),
cssPath: path.resolve(publicFolder, 'css/'),
files: cssConfig.sassFilesToCompile
}).then((): void => {
setupCleanupOnExit();
}).catch((error): void => {
throw new Error(error);
});
}
else {
// If not staging or production, just compile the libs.scss
return compileSassAndSaveMultiple({
sassPath: path.resolve(srcFolder, 'scss/'),
cssPath: path.resolve(publicFolder, 'css/'),
files: ['libs.scss']
}).then((): void => {
app.use('/css/:cssName', compileSass({
sassFilePath: path.resolve(srcFolder, 'scss/')
}));
setupCleanupOnExit();
}).catch((error): void => {
throw new Error(error);
});
}
};