From 1ffc652800c986253e5ef9ab18de163a83dae521 Mon Sep 17 00:00:00 2001 From: Bill Johnston Date: Mon, 13 Feb 2023 02:15:22 +0000 Subject: [PATCH] Fix for app names with spaces --- build/withWatermelon.js | 12 +++++------- src/withWatermelon.ts | 26 +++++++++----------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/build/withWatermelon.js b/build/withWatermelon.js index e426c09..8f7668e 100644 --- a/build/withWatermelon.js +++ b/build/withWatermelon.js @@ -32,7 +32,7 @@ function setAppDelegate(config) { return (0, config_plugins_1.withDangerousMod)(config, [ "ios", async (config) => { - const filePath = path_1.default.join(config.modRequest.platformProjectRoot, config.name.replace("-", ""), "AppDelegate.h"); + const filePath = getPlatformProjectFilePath(config, 'AppDelegate.h'); const contents = await fs.readFile(filePath, "utf-8"); let updated = `#import #import @@ -51,7 +51,7 @@ function setWmelonBridgingHeader(config) { return (0, config_plugins_1.withDangerousMod)(config, [ "ios", async (config) => { - const filePath = path_1.default.join(config.modRequest.projectRoot + "/ios", config.name.replace("-", ""), "wmelon.swift"); + const filePath = getPlatformProjectFilePath(config, 'wmelon.swift'); const contents = ` // // water.swift @@ -118,11 +118,9 @@ function isWatermelonDBInstalled(projectRoot) { const resolved = resolve_from_1.default.silent(projectRoot, "@nozbe/watermelondb/package.json"); return resolved ? path_1.default.dirname(resolved) : null; } -function replace(contents, match, replace) { - // @ts-ignore - if (!(match.test ? RegExp(match).test(contents) : contents.includes(match))) - throw new Error("Invalid text replace in config"); - return contents.replace(match, replace); +function getPlatformProjectFilePath(config, fileName) { + const projectName = config.modRequest.projectName || config.name.replace(/[- ]/g, ''); + return path_1.default.join(config.modRequest.platformProjectRoot, projectName, fileName); } // @ts-ignore exports.default = (config, options) => { diff --git a/src/withWatermelon.ts b/src/withWatermelon.ts index b12c5d6..14943db 100644 --- a/src/withWatermelon.ts +++ b/src/withWatermelon.ts @@ -45,11 +45,7 @@ function setAppDelegate(config: ExportedConfigWithProps) { return withDangerousMod(config, [ "ios", async (config) => { - const filePath = path.join( - config.modRequest.platformProjectRoot, - config.name.replace("-", ""), - "AppDelegate.h" - ); + const filePath = getPlatformProjectFilePath(config, 'AppDelegate.h') const contents = await fs.readFile(filePath, "utf-8"); let updated = @@ -73,12 +69,7 @@ function setWmelonBridgingHeader(config: ExportedConfigWithProps) { return withDangerousMod(config, [ "ios", async (config) => { - const filePath = path.join( - config.modRequest.projectRoot + "/ios", - config.name.replace("-", ""), - "wmelon.swift" - ); - + const filePath = getPlatformProjectFilePath(config, 'wmelon.swift') const contents = ` // // water.swift @@ -165,12 +156,13 @@ function isWatermelonDBInstalled(projectRoot: string) { return resolved ? path.dirname(resolved) : null; } -function replace(contents: string, match: string, replace: string): string { - // @ts-ignore - if (!(match.test ? RegExp(match).test(contents) : contents.includes(match))) - throw new Error("Invalid text replace in config"); - - return contents.replace(match, replace); +function getPlatformProjectFilePath(config: ExportedConfigWithProps, fileName: string) { + const projectName = config.modRequest.projectName || config.name.replace(/[- ]/g, '') + return path.join( + config.modRequest.platformProjectRoot, + projectName, + fileName + ) } // @ts-ignore