Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't add a XCode prebuild action to invoke codegen anymore #679

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ async function create(_argv: yargs.Arguments<any>) {
exampleCommunityCLIVersion;

if (arch !== 'legacy') {
addCodegenBuildScript(folder, options.project.name);
addCodegenBuildScript(folder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ if (isNewArchitectureEnabled()) {
preBuild.dependsOn invokeLibraryCodegen
}`;

// This is added to the example app's xcscheme file to invoke codegen before every build
const XCODE_INVOKE_CODEGEN_ACTION = `
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Invoke Codegen"
scriptText = "cd &quot;$WORKSPACE_PATH/../../../&quot; &amp;&amp; npx bob build --target codegen&#10;">
</ActionContent>
</ExecutionAction>
</PreActions>`;

// You need to have the files before calling pod install otherwise they won't be registered in your pod.
// So we add a pre_install hook to the podfile that invokes codegen
const PODSPEC_INVOKE_CODEGEN_SCRIPT = `
Expand All @@ -40,26 +28,14 @@ const PODSPEC_INVOKE_CODEGEN_SCRIPT = `
* Codegen isn't invoked for libraries with `includesGeneratedCode` set to `true`.
* This patches the example app to invoke library codegen on every app build.
*/
export async function addCodegenBuildScript(
libraryPath: string,
projectName: string
) {
export async function addCodegenBuildScript(libraryPath: string) {
const appBuildGradlePath = path.join(
libraryPath,
'example',
'android',
'app',
'build.gradle'
);
const exampleAppBuildSchemePath = path.join(
libraryPath,
'example',
'ios',
`${projectName}Example.xcodeproj`,
'xcshareddata',
'xcschemes',
`${projectName}Example.xcscheme`
);
const podfilePath = path.join(libraryPath, 'example', 'ios', 'Podfile');

// Add a gradle task that runs before every build
Expand All @@ -68,25 +44,6 @@ export async function addCodegenBuildScript(

await fs.writeFile(appBuildGradlePath, appBuildGradle);

// Add an XCode prebuild action.
const exampleAppBuildScheme = (await fs.readFile(exampleAppBuildSchemePath))
.toString()
.split('\n');
// Used XCode and inspected the result to determine where it inserts the actions
const actionTargetLineIndex = exampleAppBuildScheme.findIndex((line) =>
line.includes('<BuildActionEntries>')
);
exampleAppBuildScheme.splice(
actionTargetLineIndex,
0,
XCODE_INVOKE_CODEGEN_ACTION
);

await fs.writeFile(
exampleAppBuildSchemePath,
exampleAppBuildScheme.join('\n')
);

// Add a preinstall action to the podfile that invokes codegen
const podfile = (await fs.readFile(podfilePath)).toString().split('\n');
const podfilePostInstallIndex = podfile.findIndex((line) =>
Expand Down
Loading