Skip to content

Commit 74c4791

Browse files
committed
feat: re-enable microsoft test app
1 parent 009ccd0 commit 74c4791

8 files changed

Lines changed: 62 additions & 37 deletions

File tree

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: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,23 @@ const LANGUAGE_CHOICES: {
7474
},
7575
];
7676

77-
const EXAMPLE_CHOICES = (
78-
[
79-
{
80-
title: 'App with Community CLI',
81-
value: 'vanilla',
82-
description: "Provides access to app's native code",
83-
disabled: false,
84-
},
85-
{
86-
title: 'Test App by Microsoft',
87-
value: 'test-app',
88-
description: "App's native code is abstracted away",
89-
// Test App currently doesn't work with React Native 0.79.2
90-
// due to missing `Gemfile` in the template
91-
disabled: !process.env.CRNL_ENABLE_TEST_APP,
92-
},
93-
{
94-
title: 'App with Expo CLI',
95-
value: 'expo',
96-
description: 'Managed expo app with web support',
97-
disabled: false,
98-
},
99-
] as const
100-
).filter((choice) => !choice.disabled);
77+
const EXAMPLE_CHOICES = [
78+
{
79+
title: 'App with Community CLI',
80+
value: 'vanilla',
81+
description: 'Classic React Native app with native code access',
82+
},
83+
{
84+
title: 'App with Expo CLI',
85+
value: 'expo',
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",
92+
},
93+
] as const;
10194

10295
const validateDirectory = (input: string) => {
10396
if (!input) {
@@ -329,10 +322,8 @@ export const prompt = create(['[name]'], {
329322
skip: (): boolean => {
330323
const answers = prompt.read();
331324

332-
if (typeof answers.type === 'string') {
333-
return answers.type === 'library'
334-
? choice.value !== 'expo'
335-
: choice.value === 'expo';
325+
if (answers.type === 'library') {
326+
return choice.value !== 'expo';
336327
}
337328

338329
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'
@@ -202,14 +202,18 @@ export async function applyTemplates(
202202

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

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

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

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/metro.config.js renamed to packages/create-react-native-library/templates/example-expo/example/metro.config.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)