forked from airyland/vux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-styles.js
53 lines (47 loc) · 1.38 KB
/
build-styles.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
const postcss = require('postcss')
const syntax = require('postcss-less')
const path = require('path')
const fs = require('fs')
const less = require('less')
const shell = require('shelljs')
const distPath = path.resolve(__dirname, `../dist/styles/`)
shell.rm('-rf', distPath)
shell.mkdir('-p', distPath)
var pkg = require(path.join(__dirname, '../package.json'))
const p = path.resolve(__dirname, '../src/styles/')
fs.readdir(p, function (err, files) {
if (err) {
throw err
}
files.filter(function (file) {
return !fs.statSync(path.join(p, file)).isDirectory() && /less/.test(file) && !/index|variable|theme/.test(file)
}).forEach(function (file) {
parse(file)
})
})
const getPath = function (name) {
return path.resolve(__dirname, `../dist/styles/${name}`)
}
function parse (file) {
var code = fs.readFileSync(path.resolve(__dirname, `../src/styles/${file}`), 'utf-8')
less.render(code, {
compress: true,
paths: [path.resolve(__dirname, '../src/styles')]
},function (e, output) {
if (e) {
throw e
} else {
postcss([require('autoprefixer')(['iOS >= 7', 'Android >= 4.1'])])
.process(output.css, {
syntax: syntax
})
.then(function (result) {
const dist = getPath(file.replace('less', 'css'));
fs.writeFileSync(dist, result.css);
})
.catch(function(e){
console.log(e)
})
}
})
}