From b1e24212ea2ae435268cdb9258300ccdb71a5933 Mon Sep 17 00:00:00 2001 From: garronej Date: Wed, 21 Jul 2021 22:42:00 +0200 Subject: [PATCH] Spaces in file path #22 --- src/bin/generate-i18n-messages.ts | 6 ++--- src/bin/tools/downloadAndUnzip.ts | 7 +++--- src/bin/tools/rm.ts | 42 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/bin/tools/rm.ts diff --git a/src/bin/generate-i18n-messages.ts b/src/bin/generate-i18n-messages.ts index 539163be..0c136a92 100644 --- a/src/bin/generate-i18n-messages.ts +++ b/src/bin/generate-i18n-messages.ts @@ -5,14 +5,14 @@ import { crawl } from "./tools/crawl"; import { downloadAndUnzip } from "./tools/downloadAndUnzip"; import { builtinThemesUrl } from "./install-builtin-keycloak-themes"; import { getProjectRoot } from "./tools/getProjectRoot"; -import * as child_process from "child_process"; +import { rm_rf, rm_r } from "./tools/rm"; //@ts-ignore const propertiesParser = require("properties-parser"); const tmpDirPath = pathJoin(getProjectRoot(), "tmp_xImOef9dOd44"); -child_process.execSync(`rm -rf ${tmpDirPath}`); +rm_rf(tmpDirPath); downloadAndUnzip({ "destDirPath": tmpDirPath, @@ -47,7 +47,7 @@ crawl(".").forEach(filePath => { }); -child_process.execSync(`rm -r ${tmpDirPath}`); +rm_r(tmpDirPath); const targetDirPath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_kcMessages"); diff --git a/src/bin/tools/downloadAndUnzip.ts b/src/bin/tools/downloadAndUnzip.ts index c0ba581b..551a1ad6 100644 --- a/src/bin/tools/downloadAndUnzip.ts +++ b/src/bin/tools/downloadAndUnzip.ts @@ -3,6 +3,7 @@ import { basename as pathBasename, join as pathJoin } from "path"; import { execSync } from "child_process"; import fs from "fs"; import { transformCodebase } from "../tools/transformCodebase"; +import { rm_rf, rm, rm_r } from "./rm"; /** assert url ends with .zip */ export function downloadAndUnzip( @@ -16,19 +17,19 @@ export function downloadAndUnzip( const tmpDirPath = pathJoin(destDirPath, "..", "tmp_xxKdOxnEdx"); - execSync(`rm -rf ${tmpDirPath}`); + rm_rf(tmpDirPath); fs.mkdirSync(tmpDirPath, { "recursive": true }); execSync(`wget ${url}`, { "cwd": tmpDirPath }) execSync(`unzip ${pathBasename(url)}`, { "cwd": tmpDirPath }); - execSync(`rm ${pathBasename(url)}`, { "cwd": tmpDirPath }); + rm(pathBasename(url), { "cwd": tmpDirPath }); transformCodebase({ "srcDirPath": tmpDirPath, "destDirPath": destDirPath, }); - execSync(`rm -r ${tmpDirPath}`); + rm_r(tmpDirPath); } \ No newline at end of file diff --git a/src/bin/tools/rm.ts b/src/bin/tools/rm.ts new file mode 100644 index 00000000..18136e60 --- /dev/null +++ b/src/bin/tools/rm.ts @@ -0,0 +1,42 @@ + +import { execSync } from "child_process"; + +function rmInternal( + params: { + pathToRemove: string; + args: string | undefined; + cwd: string | undefined; + } +) { + + const { pathToRemove, args, cwd } = params; + + execSync( + `rm ${args ? `-${args} ` : ""}${pathToRemove.replace(/\ /g, "\\ ")}`, + cwd !== undefined ? { cwd } : undefined + ); +} + +export function rm(pathToRemove: string, options?: { cwd: string; }) { + rmInternal({ + pathToRemove, + "args": undefined, + "cwd": options?.cwd, + }); +} + +export function rm_r(pathToRemove: string, options?: { cwd: string; }) { + rmInternal({ + pathToRemove, + "args": "r", + "cwd": options?.cwd, + }); +} + +export function rm_rf(pathToRemove: string, options?: { cwd: string; }) { + rmInternal({ + pathToRemove, + "args": "rf", + "cwd": options?.cwd, + }); +}