From c2f15a569f4e2c727f56ca3128d3eb85fd506544 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 18 May 2024 03:41:12 +0200 Subject: [PATCH] Don't fail if the pages directory do not exist when ejecting --- src/bin/eject-keycloak-page.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bin/eject-keycloak-page.ts b/src/bin/eject-keycloak-page.ts index a8439898..257281c8 100644 --- a/src/bin/eject-keycloak-page.ts +++ b/src/bin/eject-keycloak-page.ts @@ -5,8 +5,8 @@ import cliSelect from "cli-select"; import { loginThemePageIds, accountThemePageIds, type LoginThemePageId, type AccountThemePageId } from "./shared/pageIds"; import { capitalize } from "tsafe/capitalize"; import { readFile, writeFile } from "fs/promises"; -import { existsSync } from "fs"; -import { join as pathJoin, relative as pathRelative } from "path"; +import * as fs from "fs"; +import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path"; import { kebabCaseToCamelCase } from "./tools/kebabCaseToSnakeCase"; import { assert, Equals } from "tsafe/assert"; import { getThemeSrcDirPath } from "./shared/getThemeSrcDirPath"; @@ -55,12 +55,20 @@ export async function command(params: { cliCommandOptions: CliCommandOptions }) const targetFilePath = pathJoin(themeSrcDirPath, themeType, "pages", pageBasename); - if (existsSync(targetFilePath)) { + if (fs.existsSync(targetFilePath)) { console.log(`${pageId} is already ejected, ${pathRelative(process.cwd(), targetFilePath)} already exists`); process.exit(-1); } + { + const targetDirPath = pathDirname(targetFilePath); + + if (!fs.existsSync(targetDirPath)) { + fs.mkdirSync(targetDirPath, { "recursive": true }); + } + } + await writeFile(targetFilePath, await readFile(pathJoin(getThisCodebaseRootDirPath(), "src", themeType, "pages", pageBasename))); console.log(`${pathRelative(process.cwd(), targetFilePath)} created`);