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"
43 lines
1 KiB
JavaScript
43 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
|
|
}
|