Skip to content

Commit d816e8f

Browse files
committed
feat: expose brownfield plugin actions
1 parent 4a0f933 commit d816e8f

2 files changed

Lines changed: 144 additions & 123 deletions

File tree

packages/plugin-brownfield-android/src/lib/pluginBrownfieldAndroid.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,58 @@ const getAarConfig = (
2020
};
2121
return config;
2222
};
23+
24+
export const pluginBrownfieldAndroidPackageAction = async (
25+
args: PackageAarFlags,
26+
apiSubset: Pick<PluginApi, 'getProjectRoot'>,
27+
pluginConfig?: AndroidProjectConfig,
28+
) => {
29+
intro('Creating an AAR file');
30+
31+
const androidConfig = projectConfig(apiSubset.getProjectRoot(), pluginConfig);
32+
33+
if (androidConfig) {
34+
const config = getAarConfig(args, androidConfig);
35+
await packageAar(config, args);
36+
} else {
37+
throw new RockError('Android project not found.');
38+
}
39+
};
40+
41+
export const pluginBrownfieldAndroidPublishAction = async (
42+
args: PackageAarFlags,
43+
apiSubset: Pick<PluginApi, 'getProjectRoot'>,
44+
pluginConfig?: AndroidProjectConfig,
45+
) => {
46+
intro('Publishing AAR');
47+
48+
const androidConfig = projectConfig(apiSubset.getProjectRoot(), pluginConfig);
49+
50+
if (androidConfig) {
51+
const config = getAarConfig(args, androidConfig);
52+
await publishLocalAar(config);
53+
} else {
54+
throw new RockError('Android project not found.');
55+
}
56+
};
57+
2358
export const pluginBrownfieldAndroid =
2459
(pluginConfig?: AndroidProjectConfig) =>
2560
(api: PluginApi): PluginOutput => {
26-
const projectRoot = api.getProjectRoot();
27-
2861
api.registerCommand({
2962
name: 'package:aar',
3063
description:
3164
'Produces an AAR file suitable for including React Native app in native projects.',
32-
action: async (args: PackageAarFlags) => {
33-
intro('Creating an AAR file');
34-
35-
const androidConfig = projectConfig(projectRoot, pluginConfig);
36-
37-
if (androidConfig) {
38-
const config = getAarConfig(args, androidConfig);
39-
await packageAar(config, args);
40-
} else {
41-
throw new RockError('Android project not found.');
42-
}
43-
},
65+
action: (args: PackageAarFlags) =>
66+
pluginBrownfieldAndroidPackageAction(args, api, pluginConfig),
4467
options: packageAarOptions,
4568
});
4669

4770
api.registerCommand({
4871
name: 'publish-local:aar',
4972
description: 'Publishes a AAR to local maven repo',
50-
action: async (args: PackageAarFlags) => {
51-
intro('Publishing AAR');
52-
53-
const androidConfig = projectConfig(projectRoot, pluginConfig);
54-
55-
if (androidConfig) {
56-
const config = getAarConfig(args, androidConfig);
57-
await publishLocalAar(config);
58-
} else {
59-
throw new RockError('Android project not found.');
60-
}
61-
},
73+
action: async (args: PackageAarFlags) =>
74+
pluginBrownfieldAndroidPublishAction(args, api, pluginConfig),
6275
options: publishLocalAarOptions,
6376
});
6477

packages/plugin-brownfield-ios/src/lib/pluginBrownfieldIos.ts

Lines changed: 105 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -15,109 +15,117 @@ import { copyHermesXcframework } from './copyHermesXcframework.js';
1515

1616
const buildOptions = getBuildOptions({ platformName: 'ios' });
1717

18+
export const pluginBrownfieldIosPackageAction = async (
19+
args: BuildFlags,
20+
apiSubset: Pick<
21+
PluginApi,
22+
| 'getReactNativeVersion'
23+
| 'getProjectRoot'
24+
| 'getReactNativePath'
25+
| 'getFingerprintOptions'
26+
| 'getRemoteCacheProvider'
27+
| 'getUsePrebuiltRNCore'
28+
>,
29+
pluginConfig?: IOSProjectConfig,
30+
) => {
31+
intro('Packaging iOS project');
32+
33+
// 1) Build the project
34+
const projectRoot = apiSubset.getProjectRoot();
35+
const iosConfig = getValidProjectConfig('ios', projectRoot, pluginConfig);
36+
const { derivedDataDir } = getBuildPaths('ios');
37+
38+
const destination = args.destination ?? [
39+
genericDestinations.ios.device,
40+
genericDestinations.ios.simulator,
41+
];
42+
43+
const buildFolder = args.buildFolder ?? derivedDataDir;
44+
const configuration = args.configuration ?? 'Debug';
45+
46+
const { sourceDir } = iosConfig;
47+
48+
const { scheme } = await createBuild({
49+
platformName: 'ios',
50+
projectConfig: iosConfig,
51+
args: { ...args, destination, buildFolder },
52+
projectRoot,
53+
reactNativePath: apiSubset.getReactNativePath(),
54+
fingerprintOptions: apiSubset.getFingerprintOptions(),
55+
brownfield: true,
56+
remoteCacheProvider: await apiSubset.getRemoteCacheProvider(),
57+
usePrebuiltRNCore: apiSubset.getUsePrebuiltRNCore(),
58+
});
59+
60+
// 2) Merge the .framework outputs of the framework target
61+
const productsPath = path.join(buildFolder, 'Build', 'Products');
62+
const { packageDir: frameworkTargetOutputDir } = getBuildPaths('ios');
63+
64+
await mergeFrameworks({
65+
sourceDir,
66+
frameworkPaths: [
67+
path.join(
68+
productsPath,
69+
`${configuration}-iphoneos`,
70+
`${scheme}.framework`,
71+
),
72+
path.join(
73+
productsPath,
74+
`${configuration}-iphonesimulator`,
75+
`${scheme}.framework`,
76+
),
77+
],
78+
outputPath: path.join(frameworkTargetOutputDir, `${scheme}.xcframework`),
79+
});
80+
81+
// 3) Merge React Native Brownfield paths
82+
await mergeFrameworks({
83+
sourceDir,
84+
frameworkPaths: [
85+
path.join(
86+
productsPath,
87+
`${configuration}-iphoneos`,
88+
'ReactBrownfield',
89+
'ReactBrownfield.framework',
90+
),
91+
path.join(
92+
productsPath,
93+
`${configuration}-iphonesimulator`,
94+
'ReactBrownfield',
95+
'ReactBrownfield.framework',
96+
),
97+
],
98+
outputPath: path.join(
99+
frameworkTargetOutputDir,
100+
'ReactBrownfield.xcframework',
101+
),
102+
});
103+
104+
// 4) Copy hermes xcframework to the output path
105+
copyHermesXcframework({
106+
sourceDir,
107+
destinationDir: frameworkTargetOutputDir,
108+
reactNativeVersion: apiSubset.getReactNativeVersion(),
109+
});
110+
111+
// 5) Inform the user
112+
logger.log(
113+
`XCFrameworks are available at: ${colorLink(
114+
relativeToCwd(frameworkTargetOutputDir),
115+
)}`,
116+
);
117+
118+
outro('Success 🎉.');
119+
};
120+
18121
export const pluginBrownfieldIos =
19122
(pluginConfig?: IOSProjectConfig) =>
20123
(api: PluginApi): PluginOutput => {
21124
api.registerCommand({
22125
name: 'package:ios',
23126
description: 'Emit a .xcframework file from React Native code.',
24-
action: async (args: BuildFlags) => {
25-
intro('Packaging iOS project');
26-
27-
// 1) Build the project
28-
const projectRoot = api.getProjectRoot();
29-
const iosConfig = getValidProjectConfig(
30-
'ios',
31-
projectRoot,
32-
pluginConfig,
33-
);
34-
const { derivedDataDir } = getBuildPaths('ios');
35-
36-
const destination = args.destination ?? [
37-
genericDestinations.ios.device,
38-
genericDestinations.ios.simulator,
39-
];
40-
41-
const buildFolder = args.buildFolder ?? derivedDataDir;
42-
const configuration = args.configuration ?? 'Debug';
43-
44-
const { sourceDir } = iosConfig;
45-
46-
const { scheme } = await createBuild({
47-
platformName: 'ios',
48-
projectConfig: iosConfig,
49-
args: { ...args, destination, buildFolder },
50-
projectRoot,
51-
reactNativePath: api.getReactNativePath(),
52-
fingerprintOptions: api.getFingerprintOptions(),
53-
brownfield: true,
54-
remoteCacheProvider: await api.getRemoteCacheProvider(),
55-
usePrebuiltRNCore: api.getUsePrebuiltRNCore(),
56-
});
57-
58-
// 2) Merge the .framework outputs of the framework target
59-
const productsPath = path.join(buildFolder, 'Build', 'Products');
60-
const { packageDir: frameworkTargetOutputDir } = getBuildPaths('ios');
61-
62-
await mergeFrameworks({
63-
sourceDir,
64-
frameworkPaths: [
65-
path.join(
66-
productsPath,
67-
`${configuration}-iphoneos`,
68-
`${scheme}.framework`,
69-
),
70-
path.join(
71-
productsPath,
72-
`${configuration}-iphonesimulator`,
73-
`${scheme}.framework`,
74-
),
75-
],
76-
outputPath: path.join(
77-
frameworkTargetOutputDir,
78-
`${scheme}.xcframework`,
79-
),
80-
});
81-
82-
// 3) Merge React Native Brownfield paths
83-
await mergeFrameworks({
84-
sourceDir,
85-
frameworkPaths: [
86-
path.join(
87-
productsPath,
88-
`${configuration}-iphoneos`,
89-
'ReactBrownfield',
90-
'ReactBrownfield.framework',
91-
),
92-
path.join(
93-
productsPath,
94-
`${configuration}-iphonesimulator`,
95-
'ReactBrownfield',
96-
'ReactBrownfield.framework',
97-
),
98-
],
99-
outputPath: path.join(
100-
frameworkTargetOutputDir,
101-
'ReactBrownfield.xcframework',
102-
),
103-
});
104-
105-
// 4) Copy hermes xcframework to the output path
106-
copyHermesXcframework({
107-
sourceDir,
108-
destinationDir: frameworkTargetOutputDir,
109-
reactNativeVersion: api.getReactNativeVersion(),
110-
});
111-
112-
// 5) Inform the user
113-
logger.log(
114-
`XCFrameworks are available at: ${colorLink(
115-
relativeToCwd(frameworkTargetOutputDir),
116-
)}`,
117-
);
118-
119-
outro('Success 🎉.');
120-
},
127+
action: (args: BuildFlags) =>
128+
pluginBrownfieldIosPackageAction(args, api, pluginConfig),
121129
options: buildOptions,
122130
});
123131

0 commit comments

Comments
 (0)