Do not manually bundle

This commit is contained in:
Joseph Garrone 2024-05-19 04:21:35 +02:00
parent a28a1531d9
commit 59f8119047
3 changed files with 9 additions and 22 deletions
scripts
src/bin/keycloakify/generateFtl

@ -37,26 +37,6 @@ transformCodebase({
fs.rmSync(join("dist", "ncc_out"), { "recursive": true });
{
const before = fs.readFileSync(join("dist", "bin", "main.js")).toString("utf8");
const search = `fs
.readFileSync((0, path_1.join)(__dirname, "ftl_object_to_js_code_declaring_an_object.ftl"))`;
const after = before.replace(
search,
[
`Buffer.from("`,
fs.readFileSync(join("src", "bin", "keycloakify", "generateFtl", "ftl_object_to_js_code_declaring_an_object.ftl")).toString("base64"),
`", "base64")`
].join("")
);
assert(after !== before, "Ned to update the code that bundles the ftl file");
fs.writeFileSync(join("dist", "bin", "main.js"), Buffer.from(after, "utf8"));
}
fs.chmodSync(
join("dist", "bin", "main.js"),
fs.statSync(join("dist", "bin", "main.js")).mode | fs.constants.S_IXUSR | fs.constants.S_IXGRP | fs.constants.S_IXOTH

@ -37,7 +37,11 @@ fs.writeFileSync(
)
);
fs.cpSync(pathJoin(rootDirPath, "src"), pathJoin(rootDirPath, "dist", "src"), { "recursive": true });
const destSrcDirPath = pathJoin(rootDirPath, "dist", "src");
fs.rmSync(destSrcDirPath, { "recursive": true, "force": true });
fs.cpSync(pathJoin(rootDirPath, "src"), destSrcDirPath, { "recursive": true });
const commonThirdPartyDeps = (() => {
// For example [ "@emotion" ] it's more convenient than

@ -7,6 +7,7 @@ import { join as pathJoin } from "path";
import type { BuildOptions } from "../../shared/buildOptions";
import { assert } from "tsafe/assert";
import { type ThemeType, nameOfTheGlobal, basenameOfTheKeycloakifyResourcesDir, resources_common } from "../../shared/constants";
import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
export type BuildOptionsLike = {
bundler: "vite" | "webpack";
@ -96,7 +97,9 @@ export function generateFtlFilesCodeFactory(params: {
//FTL is no valid html, we can't insert with cheerio, we put placeholder for injecting later.
const ftlObjectToJsCodeDeclaringAnObject = fs
.readFileSync(pathJoin(__dirname, "ftl_object_to_js_code_declaring_an_object.ftl"))
.readFileSync(
pathJoin(getThisCodebaseRootDirPath(), "src", "bin", "keycloakify", "generateFtl", "ftl_object_to_js_code_declaring_an_object.ftl")
)
.toString("utf8")
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1]
.replace("FIELD_NAMES_eKsIY4ZsZ4xeM", fieldNames.map(name => `"${name}"`).join(", "))