alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
134 lines (130 loc) • 3.98 kB
JavaScript
import {
package_default
} from "../../chunks/chunk-KWP47LDR.js";
import {
__commonJS,
__toESM
} from "../../chunks/chunk-U5RRZUYZ.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 = """;
break;
case 38:
escape = "&";
break;
case 39:
escape = "'";
break;
case 60:
escape = "<";
break;
case 62:
escape = ">";
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 { buildOptions } from "alinea/cli/build/BuildOptions";
import { writeFileIfContentsDiffer } from "alinea/cli/util/FS";
import { publicDefines } from "alinea/cli/util/PublicDefines";
import { code } from "alinea/core/util/CodeGen";
import { build } from "esbuild";
import fs from "node:fs";
import path from "node:path";
async function generateDashboard({ rootDir, configDir }, 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 entryPoints = {
entry: "alinea/cli/static/dashboard/entry",
config: "@alinea/generated/config.js"
};
const basename = path.basename(staticFile, ".html");
const assetsFolder = path.join(rootDir, path.dirname(staticFile), basename);
const altConfig = path.join(rootDir, "tsconfig.alinea.json");
const tsconfig = fs.existsSync(altConfig) ? altConfig : void 0;
await build({
format: "esm",
target: "esnext",
treeShaking: true,
minify: true,
splitting: true,
outdir: assetsFolder,
bundle: true,
absWorkingDir: configDir,
entryPoints,
platform: "browser",
inject: ["alinea/cli/util/WarnPublicEnv"],
define: {
"process.env.NODE_ENV": "'production'",
...publicDefines(process.env)
},
...buildOptions,
tsconfig,
logLevel: "error"
}).catch((e) => {
throw "Could not compile entrypoint";
});
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?${package_default.version}" rel="stylesheet" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="handshake_url" value="${handlerUrl}/hub/auth/handshake" />
<meta name="redirect_url" value="${handlerUrl}/hub/auth" />
<body>
<script type="module">
import {boot} from '${baseUrl}/entry.js?${package_default.version}'
boot('${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
*)
*/