2018-01-14 01:41:15 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2018-12-18 01:21:29 +00:00
|
|
|
import sass from 'node-sass'
|
|
|
|
import path from 'path'
|
|
|
|
import fs from 'fs'
|
|
|
|
import pify from 'pify'
|
2018-12-18 08:43:51 +00:00
|
|
|
import CleanCSS from 'clean-css'
|
2018-12-18 01:21:29 +00:00
|
|
|
|
2018-01-14 01:41:15 +00:00
|
|
|
const writeFile = pify(fs.writeFile.bind(fs))
|
|
|
|
const readdir = pify(fs.readdir.bind(fs))
|
2018-12-18 08:43:51 +00:00
|
|
|
const readFile = pify(fs.readFile.bind(fs))
|
2018-01-14 01:41:15 +00:00
|
|
|
const render = pify(sass.render.bind(sass))
|
|
|
|
|
|
|
|
const globalScss = path.join(__dirname, '../scss/global.scss')
|
|
|
|
const defaultThemeScss = path.join(__dirname, '../scss/themes/_default.scss')
|
2018-01-19 04:57:15 +00:00
|
|
|
const offlineThemeScss = path.join(__dirname, '../scss/themes/_offline.scss')
|
2018-11-28 03:17:18 +00:00
|
|
|
const customScrollbarScss = path.join(__dirname, '../scss/custom-scrollbars.scss')
|
2018-01-14 01:41:15 +00:00
|
|
|
const themesScssDir = path.join(__dirname, '../scss/themes')
|
2018-12-11 15:31:48 +00:00
|
|
|
const assetsDir = path.join(__dirname, '../static')
|
2018-01-14 01:41:15 +00:00
|
|
|
|
2018-11-24 08:41:36 +00:00
|
|
|
async function renderCss (file) {
|
|
|
|
return (await render({ file, outputStyle: 'compressed' })).css
|
|
|
|
}
|
2018-01-14 01:41:15 +00:00
|
|
|
|
2018-11-24 08:41:36 +00:00
|
|
|
async function compileGlobalSass () {
|
|
|
|
let mainStyle = (await Promise.all([defaultThemeScss, globalScss].map(renderCss))).join('')
|
|
|
|
let offlineStyle = (await renderCss(offlineThemeScss))
|
2018-11-28 03:17:18 +00:00
|
|
|
let scrollbarStyle = (await renderCss(customScrollbarScss))
|
2018-01-14 01:41:15 +00:00
|
|
|
|
2018-12-18 01:21:29 +00:00
|
|
|
return `<style>\n${mainStyle}</style>\n` +
|
2018-11-24 08:41:36 +00:00
|
|
|
`<style media="only x" id="theOfflineStyle">\n${offlineStyle}</style>\n` +
|
2018-12-18 01:21:29 +00:00
|
|
|
`<style media="all" id="theScrollbarStyle">\n${scrollbarStyle}</style>\n`
|
2018-01-14 01:41:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
async function compileThemesSass () {
|
2018-01-14 01:41:15 +00:00
|
|
|
let files = (await readdir(themesScssDir)).filter(file => !path.basename(file).startsWith('_'))
|
|
|
|
await Promise.all(files.map(async file => {
|
2018-08-30 04:42:57 +00:00
|
|
|
let res = await render({ file: path.join(themesScssDir, file), outputStyle: 'compressed' })
|
2018-01-14 02:59:49 +00:00
|
|
|
let outputFilename = 'theme-' + path.basename(file).replace(/\.scss$/, '.css')
|
|
|
|
await writeFile(path.join(assetsDir, outputFilename), res.css, 'utf8')
|
2018-01-14 01:41:15 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2018-12-18 08:43:51 +00:00
|
|
|
async function compileThirdPartyCss () {
|
|
|
|
let css = await readFile(path.resolve(__dirname, '../node_modules/emoji-mart/css/emoji-mart.css'), 'utf8')
|
|
|
|
css = `/* compiled from emoji-mart.css */` + new CleanCSS().minify(css).styles
|
|
|
|
await writeFile(path.resolve(__dirname, '../static/emoji-mart.css'), css, 'utf8')
|
|
|
|
}
|
|
|
|
|
2018-12-18 01:21:29 +00:00
|
|
|
export async function buildSass () {
|
2018-12-18 08:43:51 +00:00
|
|
|
let [ result ] = await Promise.all([compileGlobalSass(), compileThemesSass(), compileThirdPartyCss()])
|
2018-12-18 01:21:29 +00:00
|
|
|
return result
|
2018-01-14 01:41:15 +00:00
|
|
|
}
|