2016-11-27 13:30:40 +08:00
|
|
|
var fs = require('fs')
|
|
|
|
var cssnano = require('cssnano').process
|
|
|
|
var resolve = require('path').resolve
|
2016-11-30 21:33:44 +08:00
|
|
|
var postcss = require('postcss')
|
2017-02-09 00:19:10 +08:00
|
|
|
var isProd = process.argv[process.argv.length - 1] !== '--dev'
|
2016-11-27 13:30:40 +08:00
|
|
|
|
2017-02-04 23:45:35 +08:00
|
|
|
var processor = postcss([require('postcss-salad')({
|
|
|
|
features: {
|
|
|
|
precss: {
|
|
|
|
properties: {
|
|
|
|
preserve: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})])
|
2016-11-30 21:33:44 +08:00
|
|
|
|
|
|
|
var saveMin = function (file, content) {
|
2016-11-27 13:30:40 +08:00
|
|
|
fs.writeFileSync(resolve(__dirname, '../lib/themes/', file), content)
|
|
|
|
}
|
2016-11-30 21:33:44 +08:00
|
|
|
var save = function (file, content) {
|
|
|
|
fs.writeFileSync(resolve(__dirname, '../themes/', file), content)
|
|
|
|
}
|
2016-11-27 13:30:40 +08:00
|
|
|
var load = function (file) {
|
2016-11-30 21:33:44 +08:00
|
|
|
return fs.readFileSync(resolve(__dirname, '../src/themes/', file)).toString()
|
|
|
|
}
|
|
|
|
var loadLib = function (file) {
|
2016-11-27 13:30:40 +08:00
|
|
|
return fs.readFileSync(resolve(__dirname, '../themes/', file)).toString()
|
|
|
|
}
|
|
|
|
|
2016-11-30 21:33:44 +08:00
|
|
|
var list = fs.readdirSync(resolve(__dirname, '../src/themes'))
|
2016-11-27 13:30:40 +08:00
|
|
|
|
|
|
|
list.forEach(function (file) {
|
2016-11-30 21:33:44 +08:00
|
|
|
if (!/\.css$/.test(file)) return
|
|
|
|
processor.process(load(file), { from: resolve(__dirname, '../src/themes/', file) })
|
2016-11-27 13:30:40 +08:00
|
|
|
.then(function (result) {
|
|
|
|
save(file, result.css)
|
2016-11-30 21:33:44 +08:00
|
|
|
console.log('salad - ' + file)
|
2017-02-09 00:19:10 +08:00
|
|
|
isProd && cssnano(loadLib(file))
|
2016-11-30 21:33:44 +08:00
|
|
|
.then(function (result) {
|
|
|
|
saveMin(file, result.css)
|
|
|
|
console.log('cssnao - ' + file)
|
|
|
|
})
|
|
|
|
}).catch(function (err) {
|
|
|
|
console.log(err)
|
2016-11-27 13:30:40 +08:00
|
|
|
})
|
|
|
|
})
|
2016-11-30 21:33:44 +08:00
|
|
|
|