Skip to content

Commit 349e470

Browse files
committed
refactor: drop old arch and cpp templates
the large number of templates makes it difficult to maintain and test. so this reduces the number of templates: - drop old architecture templates - users can use codegen or older version of crnl - drop cpp templates - our cpp template isn't a pure cpp template, we should eventually have it
1 parent 688e53f commit 349e470

File tree

29 files changed

+51
-496
lines changed

29 files changed

+51
-496
lines changed

.github/workflows/build-templates.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,15 @@ jobs:
2929
os:
3030
- ubuntu
3131
- macos
32-
type:
33-
- turbo-module
34-
- fabric-view
35-
- legacy-module
36-
- legacy-view
37-
- nitro-module
38-
language:
39-
- kotlin-objc
40-
- kotlin-swift
41-
- cpp
42-
exclude:
32+
type: []
33+
language: []
34+
include:
4335
- type: turbo-module
44-
language: kotlin-swift
45-
- type: fabric-view
46-
language: kotlin-swift
36+
language: kotlin-objc
4737
- type: fabric-view
48-
language: cpp
49-
- type: legacy-view
50-
language: cpp
51-
- type: nitro-module
5238
language: kotlin-objc
5339
- type: nitro-module
54-
language: cpp
55-
include:
40+
language: kotlin-swift
5641
- os: ubuntu
5742
type: library
5843
language: js

docs/pages/create.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ This will ask you a few questions about your project and generate a new project
2929

3030
After the project is created, you can find the development workflow in the generated `CONTRIBUTING.md` file.
3131

32+
> Note: If you want to create a library using the legacy native modules and view APIs instead of the new architecture, you can use the `0.49.8` version of `create-react-native-library`: `npx [email protected] awesome-library`.
33+
3234
## Local library
3335

3436
While the default templates are for libraries that are published to npm, you can also create a local library that is not published but used locally in your app.

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -261,39 +261,33 @@ export default async function generateExampleApp({
261261
'android.enableJetifier=false'
262262
);
263263

264-
// If the library is on new architecture, enable new arch for iOS and Android
265-
if (config.project.arch === 'new') {
266-
// iOS
267-
// Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile
268-
const podfile = await fs.readFile(
269-
path.join(directory, 'ios', 'Podfile'),
270-
'utf8'
271-
);
264+
// Enable new arch for iOS and Android
265+
// iOS
266+
// Add ENV['RCT_NEW_ARCH_ENABLED'] = 1 on top of example/ios/Podfile
267+
const podfile = await fs.readFile(
268+
path.join(directory, 'ios', 'Podfile'),
269+
'utf8'
270+
);
272271

273-
await fs.writeFile(
274-
path.join(directory, 'ios', 'Podfile'),
275-
"ENV['RCT_NEW_ARCH_ENABLED'] = '1'\n\n" + podfile
276-
);
272+
await fs.writeFile(
273+
path.join(directory, 'ios', 'Podfile'),
274+
"ENV['RCT_NEW_ARCH_ENABLED'] = '1'\n\n" + podfile
275+
);
277276

278-
// Android
279-
// Make sure newArchEnabled=true is present in android/gradle.properties
280-
if (gradleProperties.split('\n').includes('#newArchEnabled=true')) {
281-
gradleProperties = gradleProperties.replace(
282-
'#newArchEnabled=true',
283-
'newArchEnabled=true'
284-
);
285-
} else if (
286-
gradleProperties.split('\n').includes('newArchEnabled=false')
287-
) {
288-
gradleProperties = gradleProperties.replace(
289-
'newArchEnabled=false',
290-
'newArchEnabled=true'
291-
);
292-
} else if (
293-
!gradleProperties.split('\n').includes('newArchEnabled=true')
294-
) {
295-
gradleProperties += '\nnewArchEnabled=true';
296-
}
277+
// Android
278+
// Make sure newArchEnabled=true is present in android/gradle.properties
279+
if (gradleProperties.split('\n').includes('#newArchEnabled=true')) {
280+
gradleProperties = gradleProperties.replace(
281+
'#newArchEnabled=true',
282+
'newArchEnabled=true'
283+
);
284+
} else if (gradleProperties.split('\n').includes('newArchEnabled=false')) {
285+
gradleProperties = gradleProperties.replace(
286+
'newArchEnabled=false',
287+
'newArchEnabled=true'
288+
);
289+
} else if (!gradleProperties.split('\n').includes('newArchEnabled=true')) {
290+
gradleProperties += '\nnewArchEnabled=true';
297291
}
298292

299293
await fs.writeFile(

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ export type ArgName =
1818
| 'example'
1919
| 'reactNativeVersion';
2020

21-
export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
21+
export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'js';
2222

2323
export type ProjectType =
2424
| 'turbo-module'
2525
| 'fabric-view'
26-
| 'legacy-module'
27-
| 'legacy-view'
2826
| 'nitro-module'
2927
| 'library';
3028

@@ -36,17 +34,12 @@ const LANGUAGE_CHOICES: {
3634
{
3735
title: 'Kotlin & Swift',
3836
value: 'kotlin-swift',
39-
types: ['nitro-module', 'legacy-module', 'legacy-view'],
37+
types: ['nitro-module'],
4038
},
4139
{
4240
title: 'Kotlin & Objective-C',
4341
value: 'kotlin-objc',
44-
types: ['turbo-module', 'fabric-view', 'legacy-module', 'legacy-view'],
45-
},
46-
{
47-
title: 'C++ for Android & iOS',
48-
value: 'cpp',
49-
types: ['turbo-module', 'legacy-module'],
42+
types: ['turbo-module', 'fabric-view'],
5043
},
5144
{
5245
title: 'JavaScript for Android, iOS & Web',
@@ -101,16 +94,6 @@ const TYPE_CHOICES: {
10194
description:
10295
'type-safe, fast integration for native APIs to JS (experimental)',
10396
},
104-
{
105-
title: 'Legacy Native module',
106-
value: 'legacy-module',
107-
description: 'bridge for native APIs to JS (old architecture)',
108-
},
109-
{
110-
title: 'Legacy Native view',
111-
value: 'legacy-view',
112-
description: 'bridge for native views to JS (old architecture)',
113-
},
11497
{
11598
title: 'JavaScript library',
11699
value: 'library',
@@ -167,7 +150,6 @@ export const acceptedArgs: Record<ArgName, yargs.Options> = {
167150
} as const;
168151

169152
export type Args = Record<ArgName | 'name', string>;
170-
export type SupportedArchitecture = 'new' | 'legacy';
171153
export type ExampleApp = 'none' | 'test-app' | 'expo' | 'vanilla';
172154

173155
export type Answers = {

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

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import path from 'path';
22
import fs from 'fs-extra';
33
import ejs from 'ejs';
4-
import type {
5-
Answers,
6-
ExampleApp,
7-
ProjectType,
8-
SupportedArchitecture,
9-
} from './input';
4+
import type { Answers, ExampleApp, ProjectType } from './input';
105

116
export type TemplateVersions = {
127
bob: string;
@@ -35,8 +30,6 @@ export type TemplateConfiguration = {
3530
package_cpp: string;
3631
identifier: string;
3732
native: boolean;
38-
arch: SupportedArchitecture;
39-
cpp: boolean;
4033
swift: boolean;
4134
viewConfig: ViewConfig;
4235
moduleConfig: ModuleConfig;
@@ -62,10 +55,6 @@ const EXAMPLE_COMMON_FILES = path.resolve(
6255
__dirname,
6356
'../templates/example-common'
6457
);
65-
const EXAMPLE_MODULE_LEGACY_FILES = path.resolve(
66-
__dirname,
67-
'../templates/example-module-legacy'
68-
);
6958
const EXAMPLE_MODULE_NEW_FILES = path.resolve(
7059
__dirname,
7160
'../templates/example-module-new'
@@ -74,7 +63,6 @@ const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view');
7463

7564
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
7665
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
77-
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
7866
const NATIVE_COMMON_FILES = path.resolve(
7967
__dirname,
8068
'../templates/native-common'
@@ -85,31 +73,21 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
8573
);
8674

8775
const NATIVE_FILES = {
88-
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
8976
module_new: path.resolve(__dirname, '../templates/native-library-new'),
90-
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
9177
view_new: path.resolve(__dirname, '../templates/native-view-new'),
9278
module_nitro: path.resolve(__dirname, '../templates/nitro-module'),
9379
} as const;
9480

9581
const OBJC_FILES = {
9682
module_common: path.resolve(__dirname, '../templates/objc-library'),
97-
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
9883
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
9984
} as const;
10085

10186
const KOTLIN_FILES = {
102-
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
10387
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
104-
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
10588
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
10689
} as const;
10790

108-
const SWIFT_FILES = {
109-
module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'),
110-
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
111-
} as const;
112-
11391
export function generateTemplateConfiguration({
11492
versions,
11593
basename,
@@ -121,11 +99,6 @@ export function generateTemplateConfiguration({
12199
}): TemplateConfiguration {
122100
const { slug, languages, type } = answers;
123101

124-
const arch =
125-
type === 'legacy-module' || type === 'legacy-view' || type === 'library'
126-
? 'legacy'
127-
: 'new';
128-
129102
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
130103
let namespace: string | undefined;
131104

@@ -159,8 +132,6 @@ export function generateTemplateConfiguration({
159132
package_cpp: pack.replace(/\./g, '_'),
160133
identifier: slug.replace(/[^a-z0-9]+/g, '-').replace(/^-/, ''),
161134
native: languages !== 'js',
162-
arch,
163-
cpp: languages === 'cpp',
164135
swift: languages === 'kotlin-swift',
165136
viewConfig: getViewConfig(type),
166137
moduleConfig: getModuleConfig(type),
@@ -182,17 +153,13 @@ function getModuleConfig(projectType: ProjectType): ModuleConfig {
182153
return 'nitro-modules';
183154
case 'turbo-module':
184155
return 'turbo-modules';
185-
case 'legacy-module':
186-
return 'native-modules';
187156
default:
188157
return null;
189158
}
190159
}
191160

192161
function getViewConfig(projectType: ProjectType): ViewConfig {
193162
switch (projectType) {
194-
case 'legacy-view':
195-
return 'paper-view';
196163
case 'fabric-view':
197164
return 'fabric-view';
198165
default:
@@ -217,11 +184,7 @@ export async function applyTemplates(
217184
if (config.project.viewConfig !== null) {
218185
await applyTemplate(config, EXAMPLE_VIEW_FILES, folder);
219186
} else {
220-
if (config.project.arch === 'legacy') {
221-
await applyTemplate(config, EXAMPLE_MODULE_LEGACY_FILES, folder);
222-
} else {
223-
await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder);
224-
}
187+
await applyTemplate(config, EXAMPLE_MODULE_NEW_FILES, folder);
225188
}
226189
}
227190
}
@@ -242,43 +205,22 @@ export async function applyTemplates(
242205
}
243206

244207
if (config.project.moduleConfig !== null) {
245-
await applyTemplate(
246-
config,
247-
NATIVE_FILES[`module_${config.project.arch}`],
248-
folder
249-
);
208+
await applyTemplate(config, NATIVE_FILES[`module_new`], folder);
250209
} else {
251-
await applyTemplate(
252-
config,
253-
NATIVE_FILES[`view_${config.project.arch}`],
254-
folder
255-
);
210+
await applyTemplate(config, NATIVE_FILES[`view_new`], folder);
256211
}
257212

258-
if (config.project.swift) {
259-
await applyTemplate(config, SWIFT_FILES[`module_legacy`], folder);
213+
if (config.project.moduleConfig !== null) {
214+
await applyTemplate(config, OBJC_FILES[`module_common`], folder);
260215
} else {
261-
if (config.project.moduleConfig !== null) {
262-
await applyTemplate(config, OBJC_FILES[`module_common`], folder);
263-
} else {
264-
await applyTemplate(
265-
config,
266-
OBJC_FILES[`view_${config.project.arch}`],
267-
folder
268-
);
269-
}
216+
await applyTemplate(config, OBJC_FILES[`view_new`], folder);
270217
}
271218

272219
const templateType = `${
273220
config.project.moduleConfig !== null ? 'module' : 'view'
274-
}_${config.project.arch}` as const;
221+
}_new` as const;
275222

276223
await applyTemplate(config, KOTLIN_FILES[templateType], folder);
277-
278-
if (config.project.cpp) {
279-
await applyTemplate(config, CPP_FILES, folder);
280-
await fs.remove(path.join(folder, 'ios', `${config.project.name}.m`));
281-
}
282224
}
283225
}
284226

packages/create-react-native-library/templates/common-local/$package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
"version": "0.0.0",
44
"description": "<%- project.description %>",
55
"main": "src/index",
6-
<% if (project.arch === 'new') { -%>
76
"codegenConfig": {
87
"name": "RN<%- project.name -%><%- project.viewConfig !== null ? 'View': '' -%>Spec",
98
"type": <%- project.viewConfig !== null ? '"all"': '"modules"' %>,
109
"jsSrcsDir": "src"
1110
},
12-
<% } -%>
1311
"author": "<%- author.name -%> <<%- author.email -%>> (<%- author.url -%>)",
1412
"license": "UNLICENSED",
1513
"homepage": "<%- repo -%>#readme"

packages/create-react-native-library/templates/common/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ yarn
1818
```
1919

2020
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
21-
<% if (project.moduleConfig === 'nitro-modules') { -%>
21+
> <% if (project.moduleConfig === 'nitro-modules') { -%>
2222
2323
This project uses Nitro Modules. If you're not familiar with how Nitro works, make sure to check the [Nitro Modules Docs](https://nitro.margelo.com/).
2424

2525
You need to run [Nitrogen](https://nitro.margelo.com/docs/nitrogen) to generate the boilerplate code required for this project. The example app will not build without this step.
2626

2727
Run **Nitrogen** in following cases:
28+
2829
- When you make changes to any `*.nitro.ts` files.
2930
- When running the project for the first time (since the generated files are not committed to the repository).
3031

@@ -33,6 +34,7 @@ To invoke **Nitrogen**, use the following command:
3334
```sh
3435
yarn nitrogen
3536
```
37+
3638
<% } -%>
3739

3840
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
@@ -65,7 +67,6 @@ To run the example app on iOS:
6567
yarn example ios
6668
```
6769

68-
<% if (project.arch === 'new') { -%>
6970
To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:
7071

7172
```sh
@@ -74,7 +75,6 @@ Running "<%- project.name -%>Example" with {"fabric":true,"initialProps":{"concu
7475

7576
Note the `"fabric":true` and `"concurrentRoot":true` properties.
7677

77-
<% } -%>
7878
<% if (!project.native) { -%>
7979
To run the example app on Web:
8080

0 commit comments

Comments
 (0)