diff --git a/src/bin/keycloakify/BuildOptions.ts b/src/bin/keycloakify/BuildOptions.ts index f0972b8b..e20de197 100644 --- a/src/bin/keycloakify/BuildOptions.ts +++ b/src/bin/keycloakify/BuildOptions.ts @@ -3,7 +3,8 @@ import { id } from "tsafe/id"; import { parse as urlParse } from "url"; import { typeGuard } from "tsafe/typeGuard"; import { symToStr } from "tsafe/symToStr"; -import { Bundler, bundlers, getParsedPackageJson } from "./parsed-package-json"; +import { bundlers, getParsedPackageJson } from "./parsed-package-json"; +import type { Bundler } from "./parsed-package-json"; import { getAppInputPath, getKeycloakBuildPath } from "./build-paths"; /** Consolidated build option gathered form CLI arguments and config in package.json */ diff --git a/src/bin/tools/unzip.ts b/src/bin/tools/unzip.ts index cf09f3fc..3180ad2a 100644 --- a/src/bin/tools/unzip.ts +++ b/src/bin/tools/unzip.ts @@ -28,6 +28,9 @@ export async function unzip(file: string, targetFolder: string, unzipSubPath?: s if (!targetFolder.endsWith("/") || !targetFolder.endsWith("\\")) { targetFolder += "/"; } + if (!fs.existsSync(targetFolder)) { + fs.mkdirSync(targetFolder, { recursive: true }); + } return new Promise((resolve, reject) => { yauzl.open(file, { lazyEntries: true }, async (err, zipfile) => { diff --git a/test/bin/setupCustomReactProject.spec.ts b/test/bin/setupCustomReactProject.spec.ts deleted file mode 100644 index 9d14c6e0..00000000 --- a/test/bin/setupCustomReactProject.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import * as fs from "fs"; -import { getProjectRoot } from "keycloakify/bin/tools/getProjectRoot.js"; -import { join as pathJoin } from "path"; -import { downloadAndUnzip } from "keycloakify/bin/tools/downloadAndUnzip"; -import { main as initializeEmailTheme } from "keycloakify/bin/initialize-email-theme"; -import { it, describe, afterAll, beforeAll, beforeEach, vi } from "vitest"; -import { getKeycloakBuildPath } from "keycloakify/bin/keycloakify/build-paths"; -import { downloadBuiltinKeycloakTheme } from "keycloakify/bin/download-builtin-keycloak-theme"; - -export const sampleReactProjectDirPath = pathJoin(getProjectRoot(), "sample_custom_react_project"); - -async function setupSampleReactProject(destDir: string) { - await downloadAndUnzip({ - "url": "https://github.com/keycloakify/keycloakify/releases/download/v0.0.1/sample_build_dir_and_package_json.zip", - "destDirPath": destDir - }); -} -const nativeCwd = process.cwd; -vi.mock("keycloakify/bin/keycloakify/parsed-package-json", async () => ({ - ...((await vi.importActual("keycloakify/bin/keycloakify/parsed-package-json")) as Record), - getParsedPackageJson: () => ({ - "keycloakify": { - "appInputPath": "./custom_input/build", - "keycloakBuildDir": "./custom_output" - } - }) -})); - -vi.mock("keycloakify/bin/promptKeycloakVersion", async () => ({ - ...((await vi.importActual("keycloakify/bin/promptKeycloakVersion")) as Record), - promptKeycloakVersion: () => ({ "keycloakVersion": "11.0.3" }) -})); - -describe("Sample Project", () => { - beforeAll(() => { - // Monkey patching the cwd to the app location for the duration of this testv - process.cwd = () => sampleReactProjectDirPath; - }); - - afterAll(() => { - fs.rmSync(sampleReactProjectDirPath, { "recursive": true }); - process.cwd = nativeCwd; - }); - beforeEach(() => { - if (fs.existsSync(sampleReactProjectDirPath)) { - fs.rmSync(sampleReactProjectDirPath, { "recursive": true }); - } - - fs.mkdirSync(pathJoin(sampleReactProjectDirPath, "src", "keycloak-theme"), { "recursive": true }); - fs.mkdirSync(pathJoin(sampleReactProjectDirPath, "src", "login"), { "recursive": true }); - }); - it( - "Sets up the project with a custom input and output directory without error", - async () => { - await setupSampleReactProject(pathJoin(sampleReactProjectDirPath, "custom_input")); - await initializeEmailTheme(); - - const destDirPath = pathJoin(getKeycloakBuildPath(), "src", "main", "resources", "theme"); - await downloadBuiltinKeycloakTheme({ destDirPath, keycloakVersion: "11.0.3", isSilent: false }); - }, - { timeout: 30000 } - ); -}); diff --git a/test/bin/setupSampleReactProject.spec.ts b/test/bin/setupSampleReactProject.spec.ts index 7c6143a4..b5491c7e 100644 --- a/test/bin/setupSampleReactProject.spec.ts +++ b/test/bin/setupSampleReactProject.spec.ts @@ -15,10 +15,10 @@ async function setupSampleReactProject(destDir: string) { "destDirPath": destDir }); } - +let parsedPackageJson: Record = {}; vi.mock("keycloakify/bin/keycloakify/parsed-package-json", async () => ({ ...((await vi.importActual("keycloakify/bin/keycloakify/parsed-package-json")) as Record), - getParsedPackageJson: () => ({}) + getParsedPackageJson: () => parsedPackageJson })); vi.mock("keycloakify/bin/promptKeycloakVersion", async () => ({ @@ -55,6 +55,23 @@ describe("Sample Project", () => { const destDirPath = pathJoin(getKeycloakBuildPath(), "src", "main", "resources", "theme"); await downloadBuiltinKeycloakTheme({ destDirPath, keycloakVersion: "11.0.3", isSilent: false }); }, - { timeout: 30000 } + { timeout: 90000 } + ); + it( + "Sets up the project with a custom input and output directory without error", + async () => { + parsedPackageJson = { + "keycloakify": { + "appInputPath": "./custom_input/build", + "keycloakBuildDir": "./custom_output" + } + }; + await setupSampleReactProject(pathJoin(sampleReactProjectDirPath, "custom_input")); + await initializeEmailTheme(); + + const destDirPath = pathJoin(getKeycloakBuildPath(), "src", "main", "resources", "theme"); + await downloadBuiltinKeycloakTheme({ destDirPath, keycloakVersion: "11.0.3", isSilent: false }); + }, + { timeout: 90000 } ); }); diff --git a/vitest.config.ts b/vitest.config.ts index 1af3eb95..d3941fb6 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -7,6 +7,6 @@ export default defineConfig({ "alias": { "keycloakify": path.resolve(__dirname, "./src") }, - "watchExclude": ["**/node_modules/**", "**/dist/**", "**/sample_react_project/**", "**/sample_custom_react_project/**"] + "watchExclude": ["**/node_modules/**", "**/dist/**", "**/sample_react_project/**"] } });