Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 170 additions & 2 deletions packages/app/android/template.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,139 @@
// @ts-check
import * as nodefs from "node:fs";
import * as path from "node:path";
import { findFile } from "../scripts/helpers.js";
import { findFile, toVersionNumber } from "../scripts/helpers.js";
import { copyFrom } from "../scripts/template.mjs";
import { generateAndroidManifest } from "./android-manifest.js";
import { configureGradleWrapper } from "./gradle-wrapper.js";

/** @import { ProjectConfig, ProjectParams } from "../scripts/types.js"; */
/**
* @import {
* Configuration,
* ConfigureParams,
* ProjectConfig,
* ProjectParams,
* } from "../scripts/types.js";
*/

/**
* @returns {string}
*/
export function buildGradle() {
return `buildscript {
apply(from: {
def searchDir = rootDir.toPath()
do {
def p = searchDir.resolve("node_modules/react-native-test-app/android/dependencies.gradle")
if (p.toFile().exists()) {
return p.toRealPath().toString()
}
} while (searchDir = searchDir.getParent())
throw new GradleException("Could not find \`react-native-test-app\`");
}())

repositories {
mavenCentral()
google()
}

dependencies {
getReactNativeDependencies().each { dependency ->
classpath(dependency)
}
}
}
`;
}

/**
* @param {number} _targetVersion Target React Native version
* @returns {string}
*/
export function gradleProperties(_targetVersion) {
return `# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the Gradle Daemon. The setting is
# particularly useful for configuring JVM memory settings for build performance.
# This does not affect the JVM settings for the Gradle client VM.
# The default is \`-Xmx512m -XX:MaxMetaspaceSize=256m\`.
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute
# projects in parallel. To learn more about parallel task execution, see the
# section on Gradle build performance:
# https://docs.gradle.org/current/userguide/performance.html#parallel_execution.
# Default is \`false\`.
#org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
#android.enableJetifier=true
# Jetifier randomly fails on these libraries
#android.jetifier.ignorelist=hermes-android,react-android

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
# Note that this is incompatible with web debugging.
newArchEnabled=true
#bridgelessEnabled=true

# Uncomment the line below to build React Native from source.
#react.buildFromSource=true

# Version of Android NDK to build against.
#ANDROID_NDK_VERSION=26.1.10909125

# Version of Kotlin to build against.
#KOTLIN_VERSION=1.8.22
`;
}

/**
* @param {string} name Root project name
* @returns {string}
*/
export function settingsGradle(name) {
return `pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

rootProject.name = "${name}"

apply(from: {
def searchDir = rootDir.toPath()
do {
def p = searchDir.resolve("node_modules/react-native-test-app/test-app.gradle")
if (p.toFile().exists()) {
return p.toRealPath().toString()
}
} while (searchDir = searchDir.getParent())
throw new GradleException("Could not find \`react-native-test-app\`");
}())
applyTestAppSettings(settings)
`;
}

/**
* @returns {string | undefined}
Expand Down Expand Up @@ -47,3 +175,43 @@ export function configure(
packageName: packageName || getAndroidPackageName(),
};
}

/**
* @param {ConfigureParams} params
* @returns {Configuration}
*/
export function getTemplate({ name, testAppPath, targetVersion }) {
const targetVersionNum = toVersionNumber(targetVersion);
return {
files: {
"build.gradle": buildGradle(),
"gradle/wrapper/gradle-wrapper.jar": copyFrom(
testAppPath,
"example",
"android",
"gradle",
"wrapper",
"gradle-wrapper.jar"
),
"gradle/wrapper/gradle-wrapper.properties": copyFrom(
testAppPath,
"example",
"android",
"gradle",
"wrapper",
"gradle-wrapper.properties"
),
"gradle.properties": gradleProperties(targetVersionNum),
gradlew: copyFrom(testAppPath, "example", "android", "gradlew"),
"gradlew.bat": copyFrom(testAppPath, "example", "android", "gradlew.bat"),
"settings.gradle": settingsGradle(name),
},
oldFiles: [],
scripts: {
android: "react-native run-android",
"build:android":
"react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist/res",
},
dependencies: {},
};
}
62 changes: 61 additions & 1 deletion packages/app/ios/template.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
// @ts-check
import * as nodefs from "node:fs";
import { toVersionNumber, v } from "../scripts/helpers.js";

/** @import { ProjectConfig, ProjectParams } from "../scripts/types.js"; */
/**
* @import {
* Configuration,
* ConfigureParams,
* ProjectConfig,
* ProjectParams,
* } from "../scripts/types.js";
*/

/**
* @param {string} name Root project name
* @param {"" | "macos/" | "visionos/"} prefix Platform prefix
* @param {number} targetVersion Target React Native version
* @returns {string}
*/
export function podfile(name, prefix, targetVersion) {
// https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here
/** @type {Record<typeof prefix, number>} */
const newArchMatrix = {
"": v(0, 76, 0),
"macos/": v(1000, 0, 0),
"visionos/": v(0, 76, 0),
};
const newArchEnabled = targetVersion >= newArchMatrix[prefix];
return `ws_dir = Pathname.new(__dir__)
ws_dir = ws_dir.parent until
File.exist?("#{ws_dir}/node_modules/react-native-test-app/${prefix}test_app.rb") ||
ws_dir.expand_path.to_s == '/'
require "#{ws_dir}/node_modules/react-native-test-app/${prefix}test_app.rb"

workspace '${name}.xcworkspace'

use_test_app! :hermes_enabled => true, :fabric_enabled => ${newArchEnabled}
`;
}

/**
* @param {string} _projectRoot
Expand All @@ -11,3 +46,28 @@ import * as nodefs from "node:fs";
export function configure(_projectRoot, config, _fs = nodefs) {
return config;
}

/**
* @param {ConfigureParams} params
* @returns {Configuration}
*/
export function getTemplate({ name, targetVersion }) {
const targetVersionNum = toVersionNumber(targetVersion);
return {
files: {
Podfile: podfile(name, "", targetVersionNum),
},
oldFiles: [
"Podfile.lock",
"Pods",
`${name}.xcodeproj`,
`${name}.xcworkspace`,
],
scripts: {
"build:ios":
"react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist",
ios: "react-native run-ios",
},
dependencies: {},
};
}
40 changes: 40 additions & 0 deletions packages/app/macos/template.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @ts-check
import * as nodefs from "node:fs";
import { podfile } from "../ios/template.config.mjs";
import { toVersionNumber } from "../scripts/helpers.js";

/** @import { Configuration, ConfigureParams } from "../scripts/types.js"; */

/**
* @param {string} _projectRoot
* @param {unknown} _config
* @returns {undefined}
*/
export function configure(_projectRoot, _config, _fs = nodefs) {
return undefined;
}

/**
* @param {ConfigureParams} params
* @returns {Configuration}
*/
export function getTemplate({ name, targetVersion }) {
const targetVersionNum = toVersionNumber(targetVersion);
return {
files: {
Podfile: podfile(name, "macos/", targetVersionNum),
},
oldFiles: [
"Podfile.lock",
"Pods",
`${name}.xcodeproj`,
`${name}.xcworkspace`,
],
scripts: {
"build:macos":
"react-native bundle --entry-file index.js --platform macos --dev true --bundle-output dist/main.macos.jsbundle --assets-dest dist",
macos: `react-native run-macos --scheme ${name}`,
},
dependencies: {},
};
}
Loading
Loading