Skip to content

Commit

Permalink
Merge pull request #11 from billjohnston/main
Browse files Browse the repository at this point in the history
Prebuild error fix for app name with spaces
  • Loading branch information
brunokiafuka committed Feb 14, 2023
2 parents ae2a2bb + 1ffc652 commit 1060459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
12 changes: 5 additions & 7 deletions build/withWatermelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
Expand All @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
26 changes: 9 additions & 17 deletions src/withWatermelon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1060459

Please sign in to comment.