2019-12-30 13:15:57 +08:00
|
|
|
const sass = require('node-sass')
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const postcss = require('postcss')
|
|
|
|
const postcssConfig = require('../postcss.config')
|
2020-02-11 20:24:56 +08:00
|
|
|
const ncp = require('ncp')
|
2019-12-30 13:15:57 +08:00
|
|
|
|
|
|
|
const styleFiles = fs
|
2020-05-16 21:08:06 +08:00
|
|
|
.readdirSync(path.resolve(__dirname, '../src/_styles'))
|
2019-12-30 13:15:57 +08:00
|
|
|
.filter(fileName => fileName.endsWith('.scss'))
|
|
|
|
|
2020-02-12 16:21:42 +08:00
|
|
|
function createDirIfNotExists (...args) {
|
|
|
|
if (!fs.existsSync(path.resolve(...args))) {
|
|
|
|
fs.mkdirSync(path.resolve(...args))
|
|
|
|
}
|
2020-02-11 20:24:56 +08:00
|
|
|
}
|
|
|
|
|
2020-02-12 16:21:42 +08:00
|
|
|
createDirIfNotExists(__dirname, '../lib')
|
|
|
|
createDirIfNotExists(__dirname, '../lib', 'styles')
|
|
|
|
createDirIfNotExists(__dirname, '../lib', 'styles', 'resources')
|
|
|
|
createDirIfNotExists(__dirname, '../es')
|
|
|
|
createDirIfNotExists(__dirname, '../es', 'styles')
|
|
|
|
createDirIfNotExists(__dirname, '../es', 'styles', 'resources')
|
|
|
|
|
2019-12-30 13:15:57 +08:00
|
|
|
styleFiles.forEach(fileName => {
|
|
|
|
sass.render({
|
2020-05-16 21:08:06 +08:00
|
|
|
file: path.resolve(__dirname, '../src/_styles', fileName),
|
2019-12-30 13:15:57 +08:00
|
|
|
outputStyle: 'expanded'
|
|
|
|
}, function (err, sassResult) {
|
|
|
|
if (err) console.error(err)
|
|
|
|
postcss(postcssConfig.plugins)
|
|
|
|
.process(sassResult.css, {
|
|
|
|
from: undefined
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
fs.writeFile(
|
|
|
|
path.resolve(__dirname, '../lib/styles', fileName.replace(/\.scss/, '.css')),
|
|
|
|
result.css,
|
|
|
|
err => {
|
|
|
|
if (err) console.error(err)
|
|
|
|
}
|
|
|
|
)
|
2020-02-12 16:21:42 +08:00
|
|
|
fs.writeFile(
|
|
|
|
path.resolve(__dirname, '../es/styles', fileName.replace(/\.scss/, '.css')),
|
|
|
|
result.css,
|
|
|
|
err => {
|
|
|
|
if (err) console.error(err)
|
|
|
|
}
|
|
|
|
)
|
2019-12-30 13:15:57 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-02-11 20:24:56 +08:00
|
|
|
|
|
|
|
ncp(
|
2020-05-16 21:08:06 +08:00
|
|
|
path.resolve(__dirname, '../src/_styles/resources'),
|
2020-02-11 20:24:56 +08:00
|
|
|
path.resolve(__dirname, '../lib/styles/resources')
|
|
|
|
)
|
2020-05-16 21:08:06 +08:00
|
|
|
|
|
|
|
ncp(
|
|
|
|
path.resolve(__dirname, '../src/_styles/resources'),
|
|
|
|
path.resolve(__dirname, '../es/styles/resources')
|
|
|
|
)
|