From b91a05e00cf3673589cfda6edfe164536935e36c Mon Sep 17 00:00:00 2001 From: James Hugman Date: Wed, 2 Oct 2024 00:45:17 +0100 Subject: [PATCH] Fixup turbo-module templates to work with getting started guides --- .../ubrn_cli/src/codegen/templates/ModuleTemplate.h | 2 +- .../src/codegen/templates/ModuleTemplate.java | 2 +- crates/ubrn_cli/src/config/mod.rs | 10 ++++++++++ crates/ubrn_cli/src/config/npm.rs | 11 +++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h index a5cf6732..cb2cdd4a 100644 --- a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h +++ b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h @@ -6,7 +6,7 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "{{ self.config.project.tm.name() }}.h" -@interface {{ self.config.project.name_upper_camel() }} : NSObject <{{ self.config.project.tm.spec_name() }}> +@interface {{ self.config.project.name_upper_camel() }} : NSObject <{{ self.config.project.codegen_filename() }}Spec> #else #import diff --git a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java index 02d2d901..fffc7c89 100644 --- a/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java +++ b/crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java @@ -11,7 +11,7 @@ import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; @ReactModule(name = {{ module_class_name }}.NAME) -public class {{ module_class_name }} extends {{ self.config.project.tm.spec_name() }} { +public class {{ module_class_name }} extends {{ self.config.project.codegen_filename() }}Spec { public static final String NAME = "{{ name }}"; public {{ module_class_name }}(ReactApplicationContext reactContext) { diff --git a/crates/ubrn_cli/src/config/mod.rs b/crates/ubrn_cli/src/config/mod.rs index 6dbe0ec9..a1dc090c 100644 --- a/crates/ubrn_cli/src/config/mod.rs +++ b/crates/ubrn_cli/src/config/mod.rs @@ -59,6 +59,16 @@ fn trim_react_native(name: &str) -> String { name.trim_matches('-').trim_matches('_').to_string() } +fn trim_react_native_2(name: &str) -> String { + name.strip_prefix("RN") + .unwrap_or(name) + .replace("ReactNative", "") + .replace("react-native", "") + .trim_matches('-') + .trim_matches('_') + .to_string() +} + impl ProjectConfig { pub(crate) fn project_root(&self) -> &Utf8Path { &self.crate_.project_root diff --git a/crates/ubrn_cli/src/config/npm.rs b/crates/ubrn_cli/src/config/npm.rs index b42462d0..641af69a 100644 --- a/crates/ubrn_cli/src/config/npm.rs +++ b/crates/ubrn_cli/src/config/npm.rs @@ -7,7 +7,7 @@ use heck::ToUpperCamelCase; use serde::Deserialize; -use super::trim_react_native; +use super::{trim_react_native, trim_react_native_2}; #[derive(Deserialize)] #[serde(rename_all = "camelCase")] @@ -34,7 +34,14 @@ impl PackageJson { .android .java_package_name .clone() - .unwrap_or_else(|| format!("com.{}", self.name().to_upper_camel_case().to_lowercase())) + .unwrap_or_else(|| { + format!( + "com.{}", + trim_react_native_2(&self.name) + .to_upper_camel_case() + .to_lowercase() + ) + }) } pub(crate) fn repo(&self) -> &PackageJsonRepo {