From 59f81190474c348a59aa461b8dea2a7f6a04ce4e Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sun, 19 May 2024 04:21:35 +0200 Subject: [PATCH] Do not manually bundle --- scripts/build.ts | 20 ------------------- scripts/link-in-app.ts | 6 +++++- .../keycloakify/generateFtl/generateFtl.ts | 5 ++++- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index 6210fe53..d77e276a 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -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 diff --git a/scripts/link-in-app.ts b/scripts/link-in-app.ts index eacb3214..8314ba3c 100644 --- a/scripts/link-in-app.ts +++ b/scripts/link-in-app.ts @@ -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 diff --git a/src/bin/keycloakify/generateFtl/generateFtl.ts b/src/bin/keycloakify/generateFtl/generateFtl.ts index 29b34d59..97e70ece 100644 --- a/src/bin/keycloakify/generateFtl/generateFtl.ts +++ b/src/bin/keycloakify/generateFtl/generateFtl.ts @@ -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(/^