Skip to content

Commit

Permalink
EMBR-4337 remove adding the Embrace plist file
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmunz committed Aug 1, 2024
1 parent 009ee6e commit 64e63f2
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 151 deletions.
2 changes: 1 addition & 1 deletion packages/core/scripts/__tests__/install.ios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ beforeEach(() => {
jest.clearAllMocks().resetModules();
});

describe("Uninstall Script iOS", () => {
describe("Install Script iOS", () => {
test("Patch AppDelegate.mm", async () => {
jest.mock("glob", () => ({
sync: () => [
Expand Down
1 change: 0 additions & 1 deletion packages/core/scripts/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ The setup script for ios includes
`iosPodfile`: It patches the Podfile, only in < 0.6 adding the dependency. This is useful if the app does not have autolink for some reason.
`patchXcodeBundlePhase`: It patches the `Bundle React Native code and images` created by React Native, adding a line to export the sourcemap to a desired path
`addUploadBuildPhase`: It adds the `Upload Debug Symbols to Embrace` to the build phase
`createEmbracePlist`: It creates a new file named `Embrace-Info.plist`, add the APPID to it and then link it to the ios project

## Android

Expand Down
76 changes: 0 additions & 76 deletions packages/core/scripts/setup/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Wizard from "../util/wizard";
import {
bundlePhaseRE,
embraceNativePod,
embracePlistPatchable,
embRunScript,
exportSourcemapRNVariable,
podfilePatchable,
Expand All @@ -13,9 +12,6 @@ import EmbraceLogger from "../../src/logger";
import patch from "./patches/patch";
import {apiToken, iosAppID, IPackageJson, packageJSON} from "./common";

const path = require("path");
const fs = require("fs");

const semverGte = require("semver/functions/gte");

const logger = new EmbraceLogger(console);
Expand Down Expand Up @@ -134,75 +130,3 @@ export const addUploadBuildPhase = {
docURL:
"https://embrace.io/docs/react-native/integration/upload-symbol-files/#uploading-native-and-javascript-symbol-files",
};

export const findNameWithCaseSensitiveFromPath = (
path: string,
name: string,
) => {
const pathSplitted = path.split("/");
const nameInLowerCase = name.toLocaleLowerCase();

const nameFounded = pathSplitted.find(
element => element.toLocaleLowerCase() === `${nameInLowerCase}.xcodeproj`,
);
if (nameFounded) {
return nameFounded.replace(".xcodeproj", "");
}

logger.warn("the xcodeproj file does not match with your project's name");
logger.warn(
`skipping adding Embrace-Info.plist to ${name}, this should be added to the project manually.
You can go https://embrace.io/docs/ios/integration/session-reporting/#import-embrace for more information`,
);
return name;
};

export const createEmbracePlist = {
name: "Create Embrace plist file",
run: (wizard: Wizard): Promise<any> =>
wizard.fieldValue(packageJSON).then(({name}) => {
const p = path.join("ios", name, "Embrace-Info.plist");
if (fs.existsSync(p)) {
logger.warn("already has Embrace-Info.json file");
return;
}

fs.closeSync(fs.openSync(p, "a"));

return xcodePatchable({name})
.then(project => {
const nameWithCaseSensitive = findNameWithCaseSensitiveFromPath(
project.path,
name,
);
project.addFile(
nameWithCaseSensitive,
`${nameWithCaseSensitive}/Embrace-Info.plist`,
);
project.sync();
project.patch();
})
.then(() => embracePlistPatchable({name}))
.then(file =>
wizard.fieldValue(iosAppID).then(iosAppIDValue => {
file.contents = plistContents(iosAppIDValue);
return file.patch();
}),
);
}),
docURL:
"https://embrace.io/docs/react-native/integration/add-embrace-sdk/#manually",
};

const plistContents = (iosAppIDValue: string) => {
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>${iosAppIDValue}</string>
<key>CRASH_REPORT_ENABLED</key>
<true/>
</dict>
</plist>`;
};
6 changes: 2 additions & 4 deletions packages/core/scripts/setup/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import EmbraceLogger from "../../src/logger";

import {
addUploadBuildPhase,
createEmbracePlist,
iosInitializeEmbrace,
iosPodfile,
patchXcodeBundlePhase,
Expand All @@ -20,12 +19,11 @@ const logger = new EmbraceLogger(console);

logger.log("initializing setup wizard");

const iosSetps = [
const iosSteps = [
iosInitializeEmbrace,
iosPodfile,
patchXcodeBundlePhase,
addUploadBuildPhase,
createEmbracePlist,
];

const androidSteps = [
Expand All @@ -38,7 +36,7 @@ const androidSteps = [
const run = () => {
const wiz = new Wizard();
[iosAppID, apiToken, packageJSON].map(field => wiz.registerField(field));
[...iosSetps, ...androidSteps].map(step => wiz.registerStep(step));
[...iosSteps, ...androidSteps].map(step => wiz.registerStep(step));
wiz.runSteps();
};

Expand Down
2 changes: 0 additions & 2 deletions packages/core/scripts/setup/setupIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import EmbraceLogger from "../../src/logger";

import {
addUploadBuildPhase,
createEmbracePlist,
iosInitializeEmbrace,
iosPodfile,
patchXcodeBundlePhase,
Expand All @@ -19,7 +18,6 @@ const iosSetps = [
iosPodfile,
patchXcodeBundlePhase,
addUploadBuildPhase,
createEmbracePlist,
];

const run = () => {
Expand Down
34 changes: 0 additions & 34 deletions packages/core/scripts/setup/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Wizard, {Step} from "../util/wizard";
import {
bundlePhaseRE,
embraceNativePod,
embracePlistPatchable,
exportSourcemapRNVariable,
getPodFile,
xcodePatchable,
Expand All @@ -13,7 +12,6 @@ import EmbraceLogger from "../../src/logger";

import {getTextToAddWithBreakingLine, SUPPORTED_PATCHES} from "./patches/patch";
import {SUPPORTED_LANGUAGES} from "./patches/common";
import {findNameWithCaseSensitiveFromPath} from "./ios";
import {androidEmbraceSwazzlerPlugin, androidGenericVersion} from "./android";

const fs = require("fs");
Expand Down Expand Up @@ -165,17 +163,6 @@ export const removeEmbraceConfigFileAndroid = async () => {
}
};

export const removeEmbraceConfigFileIos = async (projectName: string) => {
try {
const iosConifgFile = await embracePlistPatchable({name: projectName});
fs.unlinkSync(iosConifgFile.path);
} catch (_) {
logger.error(
"Could not find Embrace-Info.plist, Please refer to the docs at https://embrace.io/docs/react-native/integration/add-embrace-sdk/#manually ",
);
}
};

export const removeEmbraceFromXcode = () => {
return new Promise(resolve => {
xcodePatchable(packageJson)
Expand All @@ -186,15 +173,6 @@ export const removeEmbraceFromXcode = () => {
"Could not find bundle phase, Please refer to the docs at https://embrace.io/docs/react-native/integration/upload-symbol-files/",
);
}
const nameWithCaseSensitive = findNameWithCaseSensitiveFromPath(
project.path,
packageJson.name,
);

project.removeResourceFile(
nameWithCaseSensitive,
`${nameWithCaseSensitive}/Embrace-Info.plist`,
);
project.findAndRemovePhase("Upload Debug Symbols to Embrace");
project.modifyPhase(
bundlePhaseKey,
Expand Down Expand Up @@ -232,17 +210,6 @@ const getRemoveEmbraceConfigFileAndroidStep = () => {
"https://embrace.io/docs/react-native/integration/add-embrace-sdk/#manually",
};
};
const getRemoveEmbraceConfigFileIosStep = () => {
return {
name: "Removing iOS Embrace Config File",
run: (wizard: Wizard) =>
new Promise(resolve => {
resolve(removeEmbraceConfigFileIos(packageJson));
}),
docURL:
"https://embrace.io/docs/react-native/integration/add-embrace-sdk/#manually",
};
};

const getUnlinkFilesStep = () => {
return Object.entries(UNLINK_EMBRACE_CODE).map(([key, value]) => {
Expand Down Expand Up @@ -287,7 +254,6 @@ const transformUninstalFunctionsToSteps = (): Step[] => {
const steps = getUnlinkFilesStep();
steps.push(...getUnlinkImportStartFilesStep());
steps.push(getRemoveEmbraceConfigFileAndroidStep());
steps.push(getRemoveEmbraceConfigFileIosStep());
steps.push(getRemoveEmbraceFromXcodeStep());
return steps;
};
Expand Down
33 changes: 0 additions & 33 deletions packages/core/scripts/util/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ export const podfilePatchable = (): Promise<FileUpdatable> => {
});
};

export const embracePlistPatchable = ({
name,
}: {
name: string;
}): Promise<FileUpdatable> => {
return new Promise<FileUpdatable>((resolve, reject) => {
const plistPath = glob.sync("ios/**/Embrace-Info.plist")[0];
if (!plistPath) {
return reject(embLogger.format("Could not find Embrace-Info.plist"));
}
return resolve(getFileContents(plistPath));
});
};

export const xcodePatchable = ({
name,
}: {
Expand Down Expand Up @@ -260,25 +246,6 @@ export class XcodeProject implements Patchable {
}
}

public removeResourceFile(groupName: string, path: string) {
const target = this.findHash(
this.project.hash.project.objects.PBXNativeTarget,
groupName,
);
const group = this.findHash(
this.project.hash.project.objects.PBXGroup,
groupName,
);
if (target && group) {
const file = this.project.removeSourceFile(
path,
{target: target[0]},
group[0],
);
this.project.removeFromPbxResourcesBuildPhase(file);
}
}

private findHash(objects: any, groupName: string) {
return Object.entries(objects).find(([_, group]: [any, any]): boolean => {
return group.name === groupName;
Expand Down

0 comments on commit 64e63f2

Please sign in to comment.