1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00
budibase/packages/server/utilities/builder/convertCssToFiles.js
Michael Shanks c3fa212b31
Lots of poking around to get apps to run, plux fixing tests (#92)
ixing broken tests on client
typo in buildPage.js
fixing some server tests
local datastore uses fs-extra remove, not rmdir
client - loadBudibase - no longer destructuring arg
updated publishdev script for client (reads apps)
prettier fix
some little bug fixes
bugfix - set screens to empty array when falsy
typo in template page.json
replaced "Shard Factor" for "Estimated Count"
2020-02-12 12:45:24 +00:00

44 lines
1 KiB
JavaScript

const crypto = require("crypto")
const { ensureDir, emptyDir, writeFile } = require("fs-extra")
const { join } = require("path")
module.exports.convertCssToFiles = async (publicPagePath, pkg) => {
const cssDir = join(publicPagePath, "css")
await ensureDir(cssDir)
await emptyDir(cssDir)
for (let screen of pkg.screens || []) {
if (!screen._css) continue
if (screen._css.trim().length === 0) {
delete screen._css
continue
}
screen._css = await createCssFile(cssDir, screen._css)
}
if (pkg.page._css) {
pkg.page._css = await createCssFile(cssDir, pkg.page._css)
}
}
module.exports.getHashedCssPaths = (cssDir, _css) => {
const fileName =
crypto
.createHash("md5")
.update(_css)
.digest("hex") + ".css"
const filePath = join(cssDir, fileName)
const url = `/css/${fileName}`
return { filePath, url }
}
const createCssFile = async (cssDir, _css) => {
const { filePath, url } = module.exports.getHashedCssPaths(cssDir, _css)
await writeFile(filePath, _css)
return url
}