This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
roosevelt-sass.js
55 lines (47 loc) · 1.75 KB
/
roosevelt-sass.js
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
const fs = require('fs')
const path = require('path')
const sass = require('node-sass')
module.exports = {
versionCode: function (app) {
return `$${app.get('params').css.versionFile.varName}: '${app.get('appVersion')}';\n`
},
parse: function (app, fileName) {
return new Promise((resolve, reject) => {
const params = app.get('params').css.compiler.params
const options = params || {}
options.data = fs.readFileSync(path.join(app.get('cssPath'), fileName), 'utf8')
options.includePaths = [app.get('cssPath')]
// disable minify if minify param is false in roosevelt
if (!app.get('params').minify) {
options.outputStyle = 'nested'
}
// add the sourceMap param to option if the env is in development
if (app.settings.env === 'development' && params.sourceMap !== null && params.sourceMap !== undefined) {
options.sourceMap = params.sourceMap
options.outFile = params.outFile
options.sourceMapEmbed = params.sourceMapEmbed
options.omitSourceMapUrl = params.omitSourceMapUrl
options.sourceMapRoot = params.sourceMapRoot
} else if (app.settings.env === 'development') {
options.sourceMap = true
options.sourceMapEmbed = true
options.sourceMapContents = true
} else {
options.sourceMap = undefined
options.outFile = undefined
options.sourceMapEmbed = undefined
options.omitSourceMapUrl = undefined
options.sourceMapRoot = undefined
}
sass.render(options, (err, output) => {
if (err) {
reject(err)
return
}
const newCSS = output.css
const newFile = fileName.replace('.scss', '.css')
resolve([newFile, newCSS])
})
})
}
}