UNPKG

716 BJavaScriptView Raw
1let fs = require('fs')
2let _ = require('lodash')
3let dir = __dirname + '/replacements/'
4let sassToLess = function() {}
5
6let replacements = function () {
7 let filenames = fs.readdirSync(dir)
8
9 let results = filenames.map(function (filename) {
10 return require(dir + filename)
11 })
12
13 return _.sortBy(results, 'order')
14}
15
16sassToLess.prototype = {
17 process: function(src, extra) {
18 // skip if it's not a sass/scss file
19 if (extra.fileInfo && !/\.s[a|c]ss/i.test(extra.fileInfo.filename)) {
20 return src
21 }
22
23 // process file
24 return [src].concat(replacements()).reduce(function(source, item) {
25 return source.replace(item.pattern, item.replacement)
26 })
27 }
28}
29
30module.exports = sassToLess