-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (34 loc) · 1.4 KB
/
index.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
const fs = require('fs')
const readDir = require('./src/readDir')
const sass2css = require('./src/sass2css')
const css2less = require('./src/css2less')
/**
* author zhoulujun.cn
* version 1.0
* @param dir {String} filePath 文件目录
* @param sassToCssOptions {Object} sass输出配置文件,uuti参照 compile.Sass.style.expanded
* @param cssToLessOptions css2less输出配置文件 参考 https://github.com/zhoulujun/css2less fork 自: https://github.com/sshmyg/css2less
* @param fileWriteOptions fs.writeFile options
*/
function sass2less (dir, sassToCssOptions, cssToLessOptions = {updateColors: true}, fileWriteOptions = null) {
readDir(dir, (path, file) => {
let arrFile = file.split('.')
let fileType = arrFile.pop()
let fileName = arrFile.join('')
if (fileType === 'scss' || fileType === 'sass') {
debugger
sass2css(`${path}/${file}`, sassToCssOptions).then(data => {
debugger
// if (data.status !== 0) {
// return false
// }
let cssString = data.text
let resultString = css2less(cssString, cssToLessOptions)
fs.writeFile(`${path}/${fileName}.less`, resultString, fileWriteOptions, (err) => {
console.log(err)
})
})
}
})
}
module.exports = {sass2less, css2less, sass2css}