2018-12-18 02:21:29 +01:00
|
|
|
import sass from 'node-sass'
|
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
2019-01-20 00:06:25 +01:00
|
|
|
import { promisify } from 'util'
|
2018-12-18 02:21:29 +01:00
|
|
|
|
2019-01-20 00:06:25 +01:00
|
|
|
const writeFile = promisify(fs.writeFile)
|
|
|
|
const readdir = promisify(fs.readdir)
|
|
|
|
const render = promisify(sass.render.bind(sass))
|
2018-01-14 02:41:15 +01:00
|
|
|
|
2019-01-19 22:32:36 +01:00
|
|
|
const globalScss = path.join(__dirname, '../src/scss/global.scss')
|
|
|
|
const defaultThemeScss = path.join(__dirname, '../src/scss/themes/_default.scss')
|
|
|
|
const offlineThemeScss = path.join(__dirname, '../src/scss/themes/_offline.scss')
|
|
|
|
const customScrollbarScss = path.join(__dirname, '../src/scss/custom-scrollbars.scss')
|
|
|
|
const themesScssDir = path.join(__dirname, '../src/scss/themes')
|
2018-12-11 16:31:48 +01:00
|
|
|
const assetsDir = path.join(__dirname, '../static')
|
2018-01-14 02:41:15 +01:00
|
|
|
|
2018-11-24 09:41:36 +01:00
|
|
|
async function renderCss (file) {
|
|
|
|
return (await render({ file, outputStyle: 'compressed' })).css
|
|
|
|
}
|
2018-01-14 02:41:15 +01:00
|
|
|
|
2018-11-24 09:41:36 +01:00
|
|
|
async function compileGlobalSass () {
|
|
|
|
let mainStyle = (await Promise.all([defaultThemeScss, globalScss].map(renderCss))).join('')
|
|
|
|
let offlineStyle = (await renderCss(offlineThemeScss))
|
2018-11-28 04:17:18 +01:00
|
|
|
let scrollbarStyle = (await renderCss(customScrollbarScss))
|
2018-01-14 02:41:15 +01:00
|
|
|
|
2018-12-18 02:21:29 +01:00
|
|
|
return `<style>\n${mainStyle}</style>\n` +
|
2018-11-24 09:41:36 +01:00
|
|
|
`<style media="only x" id="theOfflineStyle">\n${offlineStyle}</style>\n` +
|
2018-12-18 02:21:29 +01:00
|
|
|
`<style media="all" id="theScrollbarStyle">\n${scrollbarStyle}</style>\n`
|
2018-01-14 02:41:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 07:29:29 +01:00
|
|
|
async function compileThemesSass () {
|
2018-01-14 02:41:15 +01:00
|
|
|
let files = (await readdir(themesScssDir)).filter(file => !path.basename(file).startsWith('_'))
|
|
|
|
await Promise.all(files.map(async file => {
|
2018-08-30 06:42:57 +02:00
|
|
|
let res = await render({ file: path.join(themesScssDir, file), outputStyle: 'compressed' })
|
2018-01-14 03:59:49 +01:00
|
|
|
let outputFilename = 'theme-' + path.basename(file).replace(/\.scss$/, '.css')
|
|
|
|
await writeFile(path.join(assetsDir, outputFilename), res.css, 'utf8')
|
2018-01-14 02:41:15 +01:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2018-12-18 02:21:29 +01:00
|
|
|
export async function buildSass () {
|
2018-12-18 21:45:49 +01:00
|
|
|
let [ result ] = await Promise.all([compileGlobalSass(), compileThemesSass()])
|
2018-12-18 02:21:29 +01:00
|
|
|
return result
|
2018-01-14 02:41:15 +01:00
|
|
|
}
|