Skip to content

Commit

Permalink
Fixup turbo-module templates to work with getting started guides
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Oct 2, 2024
1 parent 3d8fc52 commit b91a05e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <React/RCTBridgeModule.h>

Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions crates/ubrn_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions crates/ubrn_cli/src/config/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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 {
Expand Down

0 comments on commit b91a05e

Please sign in to comment.