Skip to content

Commit 93a7d04

Browse files
committed
fix: update the package name and bundleIdentifier for example app
1 parent 933a3b3 commit 93a7d04

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

packages/create-react-native-library/src/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,16 +713,20 @@ async function create(_argv: yargs.Arguments<any>) {
713713
await fs.mkdirp(folder);
714714

715715
if (reactNativeVersion != null) {
716-
if (example === 'expo') {
717-
console.warn(
718-
`${kleur.yellow('⚠')} Ignoring --react-native-version for Expo example`
719-
);
720-
} else {
716+
if (example === 'vanilla') {
721717
console.log(
722718
`${kleur.blue('ℹ')} Using ${kleur.cyan(
723719
`react-native@${reactNativeVersion}`
724720
)} for the example`
725721
);
722+
} else {
723+
console.warn(
724+
`${kleur.yellow(
725+
'⚠'
726+
)} Ignoring --react-native-version for unsupported example type: ${kleur.cyan(
727+
example
728+
)}`
729+
);
726730
}
727731
}
728732

@@ -734,9 +738,8 @@ async function create(_argv: yargs.Arguments<any>) {
734738
await generateExampleApp({
735739
type: example,
736740
dest: folder,
737-
slug: options.project.slug,
738-
projectName: options.project.name,
739741
arch,
742+
project: options.project,
740743
reactNativeVersion,
741744
});
742745
}

packages/create-react-native-library/src/utils/generateExampleApp.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ const PACKAGES_TO_ADD_WEB = {
4848
export default async function generateExampleApp({
4949
type,
5050
dest,
51-
slug,
52-
projectName,
5351
arch,
52+
project,
5453
reactNativeVersion = 'latest',
5554
}: {
5655
type: ExampleType;
5756
dest: string;
58-
slug: string;
59-
projectName: string;
6057
arch: 'new' | 'mixed' | 'legacy';
58+
project: {
59+
slug: string;
60+
name: string;
61+
package: string;
62+
};
6163
reactNativeVersion?: string;
6264
}) {
6365
const directory = path.join(dest, 'example');
@@ -68,7 +70,7 @@ export default async function generateExampleApp({
6870
`react-native-test-app@latest`,
6971
'init',
7072
'--name',
71-
`${projectName}Example`,
73+
`${project.name}Example`,
7274
`--destination`,
7375
directory,
7476
...(reactNativeVersion !== 'latest'
@@ -84,7 +86,9 @@ export default async function generateExampleApp({
8486
const vanillaArgs = [
8587
`react-native@${reactNativeVersion}`,
8688
'init',
87-
`${projectName}Example`,
89+
`${project.name}Example`,
90+
'--package-name',
91+
`${project.package}.example`,
8892
'--directory',
8993
directory,
9094
'--version',
@@ -126,11 +130,9 @@ export default async function generateExampleApp({
126130
}
127131

128132
// Patch the example app's package.json
129-
const pkg = JSON.parse(
130-
await fs.readFile(path.join(directory, 'package.json'), 'utf8')
131-
);
133+
const pkg = await fs.readJSON(path.join(directory, 'package.json'));
132134

133-
pkg.name = `${slug}-example`;
135+
pkg.name = `${project.slug}-example`;
134136

135137
// Remove Jest config for now
136138
delete pkg.jest;
@@ -143,7 +145,7 @@ export default async function generateExampleApp({
143145
const SCRIPTS_TO_ADD = {
144146
'build:android':
145147
'react-native build-android --extra-params "--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a"',
146-
'build:ios': `react-native build-ios --scheme ${projectName}Example --mode Debug --extra-params "-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"`,
148+
'build:ios': `react-native build-ios --scheme ${project.name}Example --mode Debug --extra-params "-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"`,
147149
};
148150

149151
if (type === 'vanilla') {
@@ -168,6 +170,17 @@ export default async function generateExampleApp({
168170
'build:android': androidBuild,
169171
'build:ios': iosBuild,
170172
});
173+
174+
const app = await fs.readJSON(path.join(directory, 'app.json'));
175+
176+
app.android = app.android || {};
177+
app.android.package = `${project.package}.example`;
178+
app.ios = app.ios || {};
179+
app.ios.bundleIdentifier = `${project.package}.example`;
180+
181+
await fs.writeJSON(path.join(directory, 'app.json'), app, {
182+
spaces: 2,
183+
});
171184
}
172185

173186
PACKAGES_TO_REMOVE.forEach((name) => {
@@ -211,6 +224,17 @@ export default async function generateExampleApp({
211224
});
212225

213226
scripts.web = 'expo start --web';
227+
228+
const app = await fs.readJSON(path.join(directory, 'app.json'));
229+
230+
app.expo.android = app.expo.android || {};
231+
app.expo.android.package = `${project.package}.example`;
232+
app.expo.ios = app.expo.ios || {};
233+
app.expo.ios.bundleIdentifier = `${project.package}.example`;
234+
235+
await fs.writeJSON(path.join(directory, 'app.json'), app, {
236+
spaces: 2,
237+
});
214238
}
215239

216240
await fs.writeJSON(path.join(directory, 'package.json'), pkg, {

0 commit comments

Comments
 (0)