@miyagi/core
Version:
miyagi is a component development tool for JavaScript template engines.
74 lines (70 loc) • 2.29 kB
JavaScript
const tests = require("../../tests.json");
const config = require("../../../config.json");
const { getThemeMode, getComponentTextDirection } = require("../../helpers");
/**
* @param {object} object - parameter object
* @param {object} object.app - the express instance
* @param {object} object.res - the express response object
* @param {string} [object.buildDate] - the build date in machine readable format
* @param {string} [object.formattedBuildDate] - the build date in human readable format
* @param {Function} [object.cb] - callback function
* @param {object} object.cookies
*/
module.exports = function renderMainIndex({
app,
res,
buildDate,
formattedBuildDate,
cb,
cookies,
}) {
const themeMode = getThemeMode(app, cookies);
const componentTextDirection = getComponentTextDirection(app, cookies);
res.render(
"main.hbs",
{
folders: app.get("state").menu,
components: app.get("state").components,
flatUrlPattern: app.get("config").isBuild
? "/show-{{component}}.html"
: "/show?file={{component}}",
iframeSrc: app.get("config").isBuild
? "component-all-embedded.html"
: "/component?file=all&embedded=true",
showAll: true,
hideTests: true,
tests,
projectName: config.projectName,
userProjectName: app.get("config").projectName,
indexPath: app.get("config").isBuild
? "component-all-embedded.html"
: "/component?file=all&embedded=true",
miyagiDev: !!process.env.MIYAGI_DEVELOPMENT,
miyagiProd: !process.env.MIYAGI_DEVELOPMENT,
isBuild: app.get("config").isBuild,
theme: themeMode
? Object.assign(app.get("config").ui.theme, { mode: themeMode })
: app.get("config").ui.theme,
componentTextDirection:
componentTextDirection || app.get("config").components.textDirection,
basePath: app.get("config").isBuild
? app.get("config").build.basePath
: "/",
buildDate,
formattedBuildDate,
uiTextDirection: app.get("config").ui.textDirection,
},
(err, html) => {
if (res.send) {
if (err) {
res.send(err);
} else {
res.send(html);
}
}
if (cb) {
cb(err, html);
}
}
);
};