Skip to content

Commit

Permalink
Revert "feat: merge view+module native templates (#562)"
Browse files Browse the repository at this point in the history
This reverts commit a75cf32.
  • Loading branch information
satya164 authored Jul 2, 2024
1 parent 8807954 commit 154c819
Show file tree
Hide file tree
Showing 68 changed files with 762 additions and 638 deletions.
70 changes: 45 additions & 25 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,57 @@ jobs:
- module-legacy
- module-mixed
- module-new
- view-module-legacy
- view-module-mixed
- view-module-new
- view-legacy
- view-mixed
- view-new
language:
- java-objc
- java-swift
- kotlin-objc
- cpp
- kotlin-swift
exclude:
- type: view-module-legacy
language: cpp
- type: view-module-mixed
language: cpp
- type: view-module-new
language: cpp
- type: module-legacy
language: kotlin-objc
- type: module-mixed
- os: macos-14
language: kotlin-objc
- os: macos-14
language: kotlin-swift
- type: module-new
language: java-swift
- type: module-new
language: kotlin-objc
include:
- os: ubuntu-latest
type: view-legacy
language: kotlin-swift
- os: macos-14
type: view-legacy
- type: module-mixed
language: java-swift
- type: module-mixed
language: kotlin-swift
- os: ubuntu-latest
type: module-legacy
- type: view-new
language: java-swift
- type: view-new
language: kotlin-swift
- os: macos-14
type: module-legacy
- type: view-mixed
language: java-swift
- type: view-mixed
language: kotlin-swift
include:
- os: ubuntu-latest
type: library
language: js
- os: ubuntu-latest
type: module-legacy
language: cpp
- os: ubuntu-latest
type: module-mixed
language: cpp
- os: ubuntu-latest
type: module-new
language: cpp
- os: macos-14
type: module-legacy
language: cpp
- os: macos-14
type: module-mixed
language: cpp
- os: macos-14
type: module-new
language: cpp

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}
Expand Down Expand Up @@ -134,13 +150,17 @@ jobs:
working-directory: ${{ env.work_dir }}
run: |
# Build Android for only some matrices to skip redundant builds
if [[ ${{ matrix.os }} == ubuntu-latest ]] && [[ ${{ matrix.language }} != js ]] ; then
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
echo "android_build=1" >> $GITHUB_ENV
fi
fi
# Build iOS for only some matrices to skip redundant builds
if [[ ${{ matrix.os }} == macos-14 ]] && [[ ${{ matrix.language }} != js ]]; then
if [[ ${{ matrix.os }} == macos-14 ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
echo "ios_build=1" >> $GITHUB_ENV
fi
fi
- name: Cache turborepo
Expand Down
202 changes: 106 additions & 96 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,70 +38,42 @@ const NATIVE_COMMON_EXAMPLE_FILES = path.resolve(
);

const NATIVE_FILES = {
'module-legacy': path.resolve(
__dirname,
'../templates/native-library-legacy'
),
'module-new': path.resolve(__dirname, '../templates/native-library-new'),
'module-mixed': path.resolve(__dirname, '../templates/native-library-mixed'),
'view-legacy': path.resolve(__dirname, '../templates/native-view-legacy'),
'view-module-legacy': path.resolve(
__dirname,
'../templates/native-view-library-legacy'
),
'view-module-mixed': path.resolve(
__dirname,
'../templates/native-view-library-mixed'
),
'view-module-new': path.resolve(
__dirname,
'../templates/native-view-library-new'
),
module_legacy: path.resolve(__dirname, '../templates/native-library-legacy'),
module_new: path.resolve(__dirname, '../templates/native-library-new'),
module_mixed: path.resolve(__dirname, '../templates/native-library-mixed'),
view_legacy: path.resolve(__dirname, '../templates/native-view-legacy'),
view_mixed: path.resolve(__dirname, '../templates/native-view-mixed'),
view_new: path.resolve(__dirname, '../templates/native-view-new'),
} as const;

const JAVA_FILES = {
module_legacy: path.resolve(__dirname, '../templates/java-library-legacy'),
module_new: path.resolve(__dirname, '../templates/java-library-new'),
module_mixed: path.resolve(__dirname, '../templates/java-library-mixed'),
view_legacy: path.resolve(__dirname, '../templates/java-view-legacy'),
view_mixed: path.resolve(__dirname, '../templates/java-view-mixed'),
view_new: path.resolve(__dirname, '../templates/java-view-new'),
} as const;

const OBJC_FILES = {
'module-legacy': path.resolve(__dirname, '../templates/objc-library'),
'module-mixed': path.resolve(__dirname, '../templates/objc-library'),
'module-new': path.resolve(__dirname, '../templates/objc-library'),
'view-module-legacy': path.resolve(
__dirname,
'../templates/objc-view-library-legacy'
),
'view-module-mixed': path.resolve(
__dirname,
'../templates/objc-view-library-mixed'
),
'view-module-new': path.resolve(
__dirname,
'../templates/objc-view-library-new'
),
module_common: path.resolve(__dirname, '../templates/objc-library'),
view_legacy: path.resolve(__dirname, '../templates/objc-view-legacy'),
view_mixed: path.resolve(__dirname, '../templates/objc-view-mixed'),
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
} as const;

const KOTLIN_FILES = {
'module-legacy': path.resolve(
__dirname,
'../templates/kotlin-library-legacy'
),
'module-new': path.resolve(__dirname, '../templates/kotlin-library-new'),
'module-mixed': path.resolve(__dirname, '../templates/kotlin-library-mixed'),
'view-legacy': path.resolve(__dirname, '../templates/kotlin-view-legacy'),
'view-module-legacy': path.resolve(
__dirname,
'../templates/kotlin-view-library-legacy'
),
'view-module-mixed': path.resolve(
__dirname,
'../templates/kotlin-view-library-mixed'
),
'view-module-new': path.resolve(
__dirname,
'../templates/kotlin-view-library-new'
),
module_legacy: path.resolve(__dirname, '../templates/kotlin-library-legacy'),
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
module_mixed: path.resolve(__dirname, '../templates/kotlin-library-mixed'),
view_legacy: path.resolve(__dirname, '../templates/kotlin-view-legacy'),
view_mixed: path.resolve(__dirname, '../templates/kotlin-view-mixed'),
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
} as const;

const SWIFT_FILES = {
'module-legacy': path.resolve(__dirname, '../templates/swift-library-legacy'),
'view-legacy': path.resolve(__dirname, '../templates/swift-view-legacy'),
module_legacy: path.resolve(__dirname, '../templates/swift-library-legacy'),
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
} as const;

type ArgName =
Expand All @@ -117,17 +89,22 @@ type ArgName =
| 'example'
| 'react-native-version';

type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
type ProjectLanguages =
| 'java-objc'
| 'java-swift'
| 'kotlin-objc'
| 'kotlin-swift'
| 'cpp'
| 'js';

type ProjectType =
| 'library'
| 'module-legacy'
| 'module-mixed'
| 'module-new'
| 'module-mixed'
| 'view-mixed'
| 'view-new'
| 'view-legacy'
| 'view-module-legacy'
| 'view-module-mixed'
| 'view-module-new';
| 'library';

type Answers = {
slug: string;
Expand All @@ -150,13 +127,37 @@ const LANGUAGE_CHOICES: {
{
title: 'Kotlin & Objective-C',
value: 'kotlin-objc',
types: ['view-module-legacy', 'view-module-mixed', 'view-module-new'],
types: [
'module-legacy',
'module-new',
'module-mixed',
'view-mixed',
'view-new',
'view-legacy',
],
},
{
title: 'Java & Objective-C',
value: 'java-objc',
types: [
'module-legacy',
'module-new',
'module-mixed',
'view-mixed',
'view-new',
'view-legacy',
],
},
{
title: 'Kotlin & Swift',
value: 'kotlin-swift',
types: ['module-legacy', 'view-legacy'],
},
{
title: 'Java & Swift',
value: 'java-swift',
types: ['module-legacy', 'view-legacy'],
},
{
title: 'C++ for Android & iOS',
value: 'cpp',
Expand All @@ -177,21 +178,6 @@ const TYPE_CHOICES: {
value: ProjectType;
description: string;
}[] = [
{
title: 'Fabric view and Turbo module with backward compat',
value: 'view-module-mixed',
description: BACKCOMPAT_DESCRIPTION,
},
{
title: 'Fabric view and Turbo module',
value: 'view-module-new',
description: NEWARCH_DESCRIPTION,
},
{
title: 'Native module and Native view',
value: 'view-module-legacy',
description: 'bridge for native APIs and views to JS',
},
{
title: 'JavaScript library',
value: 'library',
Expand All @@ -217,6 +203,16 @@ const TYPE_CHOICES: {
value: 'module-new',
description: NEWARCH_DESCRIPTION,
},
{
title: 'Fabric view with backward compat',
value: 'view-mixed',
description: BACKCOMPAT_DESCRIPTION,
},
{
title: 'Fabric view',
value: 'view-new',
description: NEWARCH_DESCRIPTION,
},
];

const args: Record<ArgName, yargs.Options> = {
Expand Down Expand Up @@ -505,8 +501,8 @@ async function create(argv: yargs.Arguments<any>) {
authorEmail,
authorUrl,
repoUrl,
type = 'view-module-mixed',
languages = type === 'library' ? 'js' : 'kotlin-objc',
type = 'module-mixed',
languages = type === 'library' ? 'js' : 'java-objc',
example: hasExample,
reactNativeVersion,
} = {
Expand Down Expand Up @@ -573,11 +569,13 @@ async function create(argv: yargs.Arguments<any>) {
version = FALLBACK_BOB_VERSION;
}

const arch = type.endsWith('new')
? 'new'
: type.endsWith('mixed')
? 'mixed'
: 'legacy';
const moduleType = type.startsWith('view-') ? 'view' : 'module';
const arch =
type === 'module-new' || type === 'view-new'
? 'new'
: type === 'module-mixed' || type === 'view-mixed'
? 'mixed'
: 'legacy';

const example =
hasExample && !local ? (type === 'library' ? 'expo' : 'native') : 'none';
Expand Down Expand Up @@ -620,9 +618,10 @@ async function create(argv: yargs.Arguments<any>) {
native: languages !== 'js',
arch,
cpp: languages === 'cpp',
swift: languages === 'kotlin-swift',
view: type.includes('view'),
module: type.includes('module'),
kotlin: languages === 'kotlin-objc' || languages === 'kotlin-swift',
swift: languages === 'java-swift' || languages === 'kotlin-swift',
view: moduleType === 'view',
module: moduleType === 'module',
},
author: {
name: authorName,
Expand Down Expand Up @@ -706,7 +705,7 @@ async function create(argv: yargs.Arguments<any>) {
}
}

if (type === 'library') {
if (languages === 'js') {
await copyDir(JS_FILES, folder);
await copyDir(EXPO_FILES, folder);
} else {
Expand All @@ -723,18 +722,29 @@ async function create(argv: yargs.Arguments<any>) {
await copyDir(NATIVE_COMMON_EXAMPLE_FILES, folder);
}

await copyDir(NATIVE_FILES[type], folder);
if (moduleType === 'module') {
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
} else {
await copyDir(NATIVE_FILES[`${moduleType}_${arch}`], folder);
}

if (
type === 'view-legacy' ||
(type === 'module-legacy' && options.project.swift)
) {
await copyDir(SWIFT_FILES[type], folder);
if (options.project.swift) {
await copyDir(SWIFT_FILES[`${moduleType}_legacy`], folder);
} else {
await copyDir(OBJC_FILES[type], folder);
if (moduleType === 'module') {
await copyDir(OBJC_FILES[`${moduleType}_common`], folder);
} else {
await copyDir(OBJC_FILES[`view_${arch}`], folder);
}
}

await copyDir(KOTLIN_FILES[type], folder);
const templateType = `${moduleType}_${arch}` as const;

if (options.project.kotlin) {
await copyDir(KOTLIN_FILES[templateType], folder);
} else {
await copyDir(JAVA_FILES[templateType], folder);
}

if (options.project.cpp) {
await copyDir(CPP_FILES, folder);
Expand Down
Loading

0 comments on commit 154c819

Please sign in to comment.