Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further re-work trim_react_native #100

Merged
merged 3 commits into from
Sep 30, 2024
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
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.codegen_filename() }}Spec>
@interface {{ self.config.project.name_upper_camel() }} : NSObject <{{ self.config.project.tm.spec_name() }}>
#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.codegen_filename() }}Spec {
public class {{ module_class_name }} extends {{ self.config.project.tm.spec_name() }} {
public static final String NAME = "{{ name }}";

public {{ module_class_name }}(ReactApplicationContext reactContext) {
Expand Down
2 changes: 1 addition & 1 deletion crates/ubrn_cli/src/codegen/templates/ModuleTemplate.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- let module_name = self.config.project.name_upper_camel() %}
{%- let spec_jsi = self.config.project.codegen_filename()|fmt("{}JSI") %}
{%- let spec_jsi = self.config.project.tm.spec_name()|fmt("{}JSI") %}
{%- let ns = self.config.project.cpp_namespace() %}
{%- let uniffi_ns = "uniffi_generated" %}
{%- let fn_prefix = "__hostFunction_{}"|format(module_name) -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export interface Spec extends TurboModule {
cleanupRustCrate(): boolean;
}

export default TurboModuleRegistry.getEnforcing<Spec>('{{ self.config.project.tm.spec_name() }}');
export default TurboModuleRegistry.getEnforcing<Spec>('{{ self.config.project.name_upper_camel() }}');
18 changes: 6 additions & 12 deletions crates/ubrn_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod npm;

use camino::{Utf8Path, Utf8PathBuf};
use globset::GlobSet;
use heck::ToUpperCamelCase;
pub(crate) use npm::PackageJson;

use serde::Deserialize;
Expand Down Expand Up @@ -46,7 +45,7 @@ pub(crate) struct ProjectConfig {

impl ProjectConfig {
fn default_name() -> String {
workspace::package_json().trimmed_name()
workspace::package_json().raw_name()
}

fn default_repository() -> String {
Expand All @@ -57,13 +56,7 @@ impl ProjectConfig {
}

fn trim_react_native(name: &str) -> String {
name.strip_prefix("RN")
.unwrap_or(name)
.replace("ReactNative", "")
.replace("react-native", "")
.trim_matches('-')
.trim_matches('_')
.to_string()
name.trim_matches('-').trim_matches('_').to_string()
}

impl ProjectConfig {
Expand All @@ -74,7 +67,7 @@ impl ProjectConfig {

impl ProjectConfig {
fn name(&self) -> String {
self.name.clone()
trim_react_native(&self.name)
}

pub(crate) fn raw_name(&self) -> &str {
Expand Down Expand Up @@ -181,7 +174,8 @@ impl TurboModulesConfig {

fn default_spec_name() -> String {
let package_json = workspace::package_json();
trim_react_native(&package_json.codegen().name)
let codegen_name = &package_json.codegen().name;
trim_react_native(codegen_name)
}
}

Expand All @@ -201,7 +195,7 @@ impl TurboModulesConfig {
}

pub(crate) fn spec_name(&self) -> String {
self.spec_name.to_upper_camel_case()
self.spec_name.clone()
}

pub(crate) fn name(&self) -> String {
Expand Down
11 changes: 2 additions & 9 deletions crates/ubrn_cli/src/config/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl PackageJson {
self.name.clone()
}

pub(crate) fn trimmed_name(&self) -> String {
pub(crate) fn name(&self) -> String {
trim_react_native(&self.name)
}

Expand All @@ -34,14 +34,7 @@ impl PackageJson {
.android
.java_package_name
.clone()
.unwrap_or_else(|| {
format!(
"com.{}",
trim_react_native(&self.raw_name())
.to_upper_camel_case()
.to_lowercase()
)
})
.unwrap_or_else(|| format!("com.{}", self.name().to_upper_camel_case().to_lowercase()))
}

pub(crate) fn repo(&self) -> &PackageJsonRepo {
Expand Down
4 changes: 1 addition & 3 deletions crates/ubrn_cli/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ impl IOsConfig {
fn default_framework_name() -> String {
format!(
"{}Framework",
workspace::package_json()
.trimmed_name()
.to_upper_camel_case()
workspace::package_json().name().to_upper_camel_case()
)
}

Expand Down