UNPKG

alinea

Version:
139 lines (135 loc) 4.24 kB
import { __commonJS, __toESM } from "../../chunks/chunk-NZLE2WMY.js"; // node_modules/escape-html/index.js var require_escape_html = __commonJS({ "node_modules/escape-html/index.js"(exports, module) { "use strict"; var matchHtmlRegExp = /["'&<>]/; module.exports = escapeHtml2; function escapeHtml2(string) { var str = "" + string; var match = matchHtmlRegExp.exec(str); if (!match) { return str; } var escape; var html = ""; var index = 0; var lastIndex = 0; for (index = match.index; index < str.length; index++) { switch (str.charCodeAt(index)) { case 34: escape = "&quot;"; break; case 38: escape = "&amp;"; break; case 39: escape = "&#39;"; break; case 60: escape = "&lt;"; break; case 62: escape = "&gt;"; break; default: continue; } if (lastIndex !== index) { html += str.substring(lastIndex, index); } lastIndex = index + 1; html += escape; } return lastIndex !== index ? html + str.substring(lastIndex, index) : html; } } }); // src/cli/generate/GenerateDashboard.ts var import_escape_html = __toESM(require_escape_html(), 1); import fs from "node:fs"; import path from "node:path"; import { writeFileIfContentsDiffer } from "alinea/cli/util/FS"; import { createId } from "alinea/core/Id"; import { code } from "alinea/core/util/CodeGen"; import esbuild from "esbuild"; import { buildOptions } from "../build/BuildOptions.js"; import { ignorePlugin } from "../util/IgnorePlugin.js"; import { publicDefines } from "../util/PublicDefines.js"; import { viewsPlugin } from "../util/ViewsPlugin.js"; async function generateDashboard({ configLocation, rootDir, configDir }, cms, handlerUrl, staticFile) { if (!staticFile.endsWith(".html")) throw new Error( "The staticFile option in config.dashboard must point to an .html file (include the extension)" ); const buildId = createId(); const entryPoints = { entry: "alinea/cli/static/dashboard/entry" }; const basename = path.basename(staticFile, ".html"); const assetsFolder = path.join(rootDir, path.dirname(staticFile), basename); const tsconfigLocation = path.join(rootDir, "tsconfig.json"); const tsconfig = fs.existsSync(tsconfigLocation) ? tsconfigLocation : void 0; const plugins = [viewsPlugin(rootDir, cms), ignorePlugin]; await esbuild.build({ format: "esm", target: "esnext", treeShaking: true, minify: true, outdir: assetsFolder, bundle: true, absWorkingDir: configDir, entryPoints, platform: "browser", inject: ["alinea/cli/util/WarnPublicEnv"], alias: { "alinea/next": "alinea/core", "#alinea/config": configLocation }, external: ["@alinea/generated"], define: { "process.env.NODE_ENV": '"production"', "process.env.ALINEA_BUILD_ID": JSON.stringify(buildId), ...publicDefines(process.env) }, ...buildOptions, plugins, tsconfig, logLevel: "error" }); const baseUrl = `./${(0, import_escape_html.default)(basename)}`; await writeFileIfContentsDiffer( path.join(rootDir, staticFile), code` <!DOCTYPE html> <meta charset="utf-8" /> <link rel="icon" href="data:," /> <link href="${baseUrl}/entry.css?${buildId}" rel="stylesheet" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="handshake_url" value="${handlerUrl}?auth=handshake" /> <meta name="redirect_url" value="${handlerUrl}?auth=login" /> <body> <script type="module" src="${baseUrl}/entry.js?buildId=${buildId}&handlerUrl=${encodeURIComponent( handlerUrl )}"> </script> </body> `.toString() ); } export { generateDashboard }; /*! Bundled license information: escape-html/index.js: (*! * escape-html * Copyright(c) 2012-2013 TJ Holowaychuk * Copyright(c) 2015 Andreas Lubbe * Copyright(c) 2015 Tiancheng "Timothy" Gu * MIT Licensed *) */