Skip to content

Commit 4ac88b5

Browse files
committed
feat: re-enable microsoft test app
1 parent f8f45f3 commit 4ac88b5

File tree

7 files changed

+52
-22
lines changed

7 files changed

+52
-22
lines changed

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import type { TemplateConfiguration } from '../template';
66
import sortObjectKeys from '../utils/sortObjectKeys';
77
import { spawn } from '../utils/spawn';
8+
import dedent from 'dedent';
89

910
const FILES_TO_DELETE = [
1011
'__tests__',
@@ -37,20 +38,24 @@ const PACKAGES_TO_REMOVE = [
3738
'react-native-safe-area-context',
3839
];
3940

40-
const PACKAGES_TO_ADD_WEB = {
41+
const PACKAGES_TO_ADD_EXPO_WEB = {
4142
'@expo/metro-runtime': '~5.0.4',
4243
'react-dom': '19.1.0',
4344
'react-native-web': '~0.21.1',
4445
};
4546

47+
const PACKAGES_TO_ADD_DEV_EXPO_NATIVE = {
48+
'expo-dev-client': '~5.0.3',
49+
};
50+
4651
export default async function generateExampleApp({
4752
config,
4853
root,
4954
reactNativeVersion = 'latest',
5055
}: {
5156
config: TemplateConfiguration;
5257
root: string;
53-
reactNativeVersion?: string;
58+
reactNativeVersion: string | undefined;
5459
}) {
5560
const directory = path.join(root, 'example');
5661

@@ -252,14 +257,39 @@ export default async function generateExampleApp({
252257
bundledNativeModules = {};
253258
}
254259

255-
Object.entries(PACKAGES_TO_ADD_WEB).forEach(([name, version]) => {
256-
dependencies[name] = bundledNativeModules[name] || version;
257-
});
260+
if (config.project.native) {
261+
Object.entries(PACKAGES_TO_ADD_DEV_EXPO_NATIVE).forEach(
262+
([name, version]) => {
263+
devDependencies[name] = bundledNativeModules[name] || version;
264+
}
265+
);
266+
267+
scripts.start = 'expo start --dev-client';
268+
scripts.android = 'expo run:android';
269+
scripts.ios = 'expo run:ios';
258270

259-
scripts.web = 'expo start --web';
271+
delete scripts.web;
272+
273+
await fs.writeFile(
274+
path.join(directory, '.gitignore'),
275+
dedent`
276+
# These folders are generated with prebuild (CNG)
277+
android/
278+
ios/
279+
`
280+
);
281+
} else {
282+
Object.entries(PACKAGES_TO_ADD_EXPO_WEB).forEach(([name, version]) => {
283+
dependencies[name] = bundledNativeModules[name] || version;
284+
});
285+
286+
scripts.web = 'expo start --web';
287+
}
260288

261289
const app = await fs.readJSON(path.join(directory, 'app.json'));
262290

291+
app.expo.name = `${config.project.name} Example`;
292+
app.expo.slug = `${config.project.slug}-example`;
263293
app.expo.android = app.expo.android || {};
264294
app.expo.android.package = `${config.project.package}.example`;
265295
app.expo.ios = app.expo.ios || {};

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,17 @@ const EXAMPLE_CHOICES = [
7878
{
7979
title: 'App with Community CLI',
8080
value: 'vanilla',
81-
description: "Provides access to app's native code",
82-
disabled: false,
83-
},
84-
{
85-
title: 'Test App by Microsoft',
86-
value: 'test-app',
87-
description: "App's native code is abstracted away",
81+
description: 'Classic React Native app with native code access',
8882
},
8983
{
9084
title: 'App with Expo CLI',
9185
value: 'expo',
92-
description: 'Managed expo app with web support',
93-
disabled: false,
86+
description: 'Managed Expo app for easier upgrades',
87+
},
88+
{
89+
title: 'Test App by Microsoft',
90+
value: 'test-app',
91+
description: "Test app with app's native code abstracted",
9492
},
9593
] as const;
9694

@@ -324,10 +322,8 @@ export const prompt = create(['[name]'], {
324322
skip: (): boolean => {
325323
const answers = prompt.read();
326324

327-
if (typeof answers.type === 'string') {
328-
return answers.type === 'library'
329-
? choice.value !== 'expo'
330-
: choice.value === 'expo';
325+
if (answers.type === 'library') {
326+
return choice.value !== 'expo';
331327
}
332328

333329
return false;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const EXAMPLE_MODULE_NEW_FILES = path.resolve(
6161
'../templates/example-module-new'
6262
);
6363
const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view');
64+
const EXAMPLE_EXPO_FILES = path.resolve(__dirname, '../templates/example-expo');
6465

6566
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
66-
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
6767
const NATIVE_COMMON_FILES = path.resolve(
6868
__dirname,
6969
'../templates/native-common'
@@ -203,14 +203,18 @@ export async function applyTemplates(
203203

204204
if (answers.languages === 'js') {
205205
await applyTemplate(config, JS_FILES, folder);
206-
await applyTemplate(config, EXPO_FILES, folder);
206+
await applyTemplate(config, EXAMPLE_EXPO_FILES, folder);
207207
} else {
208208
await applyTemplate(config, NATIVE_COMMON_FILES, folder);
209209

210210
if (config.example != null) {
211211
await applyTemplate(config, NATIVE_COMMON_EXAMPLE_FILES, folder);
212212
}
213213

214+
if (config.example === 'expo') {
215+
await applyTemplate(config, EXAMPLE_EXPO_FILES, folder);
216+
}
217+
214218
if (config.project.moduleConfig === 'nitro-modules') {
215219
await applyTemplate(config, NITRO_COMMON_FILES, folder);
216220
await applyTemplate(config, NATIVE_FILES['module_nitro'], folder);

packages/create-react-native-library/templates/expo-library/example/babel.config.js renamed to packages/create-react-native-library/templates/example-expo/example/babel.config.js

File renamed without changes.

packages/create-react-native-library/templates/expo-library/example/index.js renamed to packages/create-react-native-library/templates/example-expo/example/index.js

File renamed without changes.

packages/create-react-native-library/templates/expo-library/example/tsconfig.json renamed to packages/create-react-native-library/templates/example-expo/example/tsconfig.json

File renamed without changes.

packages/create-react-native-library/templates/native-common-example/example/react-native.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
automaticPodsInstallation: true,
1616
},
1717
}),
18-
<% } else { -%>
18+
<% } else if (example === 'vanilla') { -%>
1919
project: {
2020
ios: {
2121
automaticPodsInstallation: true,

0 commit comments

Comments
 (0)