Skip to content

Commit ba6bb5b

Browse files
committed
feat: use ruby script for post integrate
1 parent 0ee3099 commit ba6bb5b

3 files changed

Lines changed: 53 additions & 27 deletions

File tree

packages/react-native-brownfield/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"files": [
6262
"src",
6363
"lib",
64+
"scripts",
6465
"android",
6566
"ios",
6667
"cpp",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def react_native_brownfield_post_integrate(installer)
2+
projects = installer.aggregate_targets.map(&:user_project).compact.uniq
3+
projects.each do |project|
4+
modified = false
5+
6+
project.native_targets.each do |target|
7+
phases = target.build_phases
8+
expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
9+
patch_idx = phases.index { |p| p.respond_to?(:name) && p.name == 'Patch ExpoModulesProvider' }
10+
11+
next if expo_idx.nil? || patch_idx.nil?
12+
next if patch_idx > expo_idx
13+
14+
patch = phases.delete_at(patch_idx)
15+
expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
16+
phases.insert(expo_idx + 1, patch)
17+
modified = true
18+
end
19+
20+
project.save if modified
21+
end
22+
end

packages/react-native-brownfield/src/expo-config-plugin/ios/podfileHelpers.ts

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,47 @@ const BROWNFIELD_POD_HOOK_MARKER_START =
66
'# >>> react-native-brownfield expo phase ordering >>>';
77
const BROWNFIELD_POD_HOOK_MARKER_END =
88
'# <<< react-native-brownfield expo phase ordering <<<';
9+
const BROWNFIELD_POST_INTEGRATE_REQUIRE = `require File.join(File.dirname(\`node --print "require.resolve('@callstack/react-native-brownfield/package.json')"\`), "scripts/react_native_brownfield_post_integrate")`;
10+
const REACT_NATIVE_PODS_REQUIRE_REGEX =
11+
/^require File\.join\(File\.dirname\(`node --print "require\.resolve\('react-native\/package\.json'\)"`\), "scripts\/react_native_pods"\)\s*$/m;
912

10-
function ensureExpoPhaseOrderingHook(podfile: string): string {
11-
if (podfile.includes(BROWNFIELD_POD_HOOK_MARKER_START)) {
13+
function ensureBrownfieldPostIntegrateRequire(podfile: string): string {
14+
if (podfile.includes('scripts/react_native_brownfield_post_integrate')) {
1215
return podfile;
1316
}
1417

18+
const reactNativePodsRequireMatch = podfile.match(
19+
REACT_NATIVE_PODS_REQUIRE_REGEX
20+
);
21+
if (reactNativePodsRequireMatch) {
22+
const requireLine = reactNativePodsRequireMatch[0];
23+
return podfile.replace(
24+
requireLine,
25+
`${requireLine}\n${BROWNFIELD_POST_INTEGRATE_REQUIRE}\n`
26+
);
27+
}
28+
29+
return `${BROWNFIELD_POST_INTEGRATE_REQUIRE}\n\n${podfile}`;
30+
}
31+
32+
function ensureExpoPhaseOrderingHook(podfile: string): string {
33+
let modifiedPodfile = ensureBrownfieldPostIntegrateRequire(podfile);
34+
35+
if (modifiedPodfile.includes(BROWNFIELD_POD_HOOK_MARKER_START)) {
36+
return modifiedPodfile;
37+
}
38+
1539
const hook = `
1640
${BROWNFIELD_POD_HOOK_MARKER_START}
17-
def reorder_brownfield_expo_patch_phase!(installer)
18-
projects = installer.aggregate_targets.map(&:user_project).compact.uniq
19-
projects.each do |project|
20-
modified = false
21-
22-
project.native_targets.each do |target|
23-
phases = target.build_phases
24-
expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
25-
patch_idx = phases.index { |p| p.respond_to?(:name) && p.name == 'Patch ExpoModulesProvider' }
26-
27-
next if expo_idx.nil? || patch_idx.nil?
28-
next if patch_idx > expo_idx
29-
30-
patch = phases.delete_at(patch_idx)
31-
expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
32-
phases.insert(expo_idx + 1, patch)
33-
modified = true
34-
end
35-
36-
project.save if modified
37-
end
38-
end
39-
4041
post_integrate do |installer|
41-
reorder_brownfield_expo_patch_phase!(installer)
42+
react_native_brownfield_post_integrate(installer)
4243
end
4344
${BROWNFIELD_POD_HOOK_MARKER_END}
4445
`;
4546

46-
return `${podfile.trimEnd()}\n\n${hook}\n`;
47+
modifiedPodfile = `${modifiedPodfile.trimEnd()}\n\n${hook}\n`;
48+
49+
return modifiedPodfile;
4750
}
4851

4952
/**

0 commit comments

Comments
 (0)