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

Draft documentation #72

Merged
merged 4 commits into from
Oct 2, 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: 0 additions & 2 deletions crates/ubrn_bindgen/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ pub struct SourceArgs {
lib_file: Option<Utf8PathBuf>,

/// Override the default crate name that is guessed from UDL file path.
///
/// In library mode, this
#[clap(long = "crate")]
crate_name: Option<String>,

Expand Down
2 changes: 2 additions & 0 deletions crates/ubrn_bindgen/src/bindings/react_native/uniffi_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ pub(crate) struct CustomTypeConfig {
#[serde(default)]
pub(crate) imports: Vec<(String, String)>,
pub(crate) type_name: Option<String>,
#[serde(alias = "lift")]
pub(crate) into_custom: TemplateExpression,
#[serde(alias = "lower")]
pub(crate) from_custom: TemplateExpression,
}

Expand Down
3 changes: 1 addition & 2 deletions crates/ubrn_cli/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub(crate) struct AndroidConfig {
#[serde(default = "AndroidConfig::default_platform", alias = "platform")]
pub(crate) api_level: usize,

#[allow(dead_code)]
#[serde(default = "AndroidConfig::default_package_name")]
pub(crate) package_name: String,
}
Expand Down Expand Up @@ -190,8 +189,8 @@ impl AndroidArgs {
cargo_extras: &ExtraArgs,
api_level: usize,
) -> Result<HashMap<Target, Utf8PathBuf>> {
let rust_dir = crate_.directory()?;
let manifest_path = crate_.manifest_path()?;
let rust_dir = crate_.crate_dir()?;
let metadata = crate_.metadata()?;
let mut target_files = HashMap::new();
let profile = self.common_args.profile();
Expand Down
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
12 changes: 11 additions & 1 deletion crates/ubrn_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) struct ProjectConfig {
#[serde(default = "ProjectConfig::default_repository")]
pub(crate) repository: String,

#[serde(rename = "crate")]
#[serde(rename = "rust", alias = "crate")]
pub(crate) crate_: CrateConfig,

#[serde(default)]
Expand Down 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()
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to start slowly work out where this is needed and where it isn't. Selectively adding trim_react_native_2 to defaults until everything works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be something good to ask Johannes in our matrix room, he seems to know about these things.


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
5 changes: 2 additions & 3 deletions crates/ubrn_cli/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl GenerateArgs {

#[derive(Debug, Subcommand)]
pub(crate) enum GenerateCmd {
/// Generate the just the bindings
/// Generate just the Typescript and C++ bindings
Bindings(BindingsArgs),
/// Generate the TurboModule code to plug the bindings into the app
TurboModule(TurboModuleArgs),
Expand Down Expand Up @@ -75,8 +75,7 @@ impl GenerateAllArgs {
let pwd = ubrn_common::pwd()?;
let lib_file = pwd.join(&self.lib_file);
let modules = {
let dir = project.crate_.directory()?;
ubrn_common::cd(&dir)?;
ubrn_common::cd(&project.crate_.crate_dir()?)?;
let ts_dir = project.bindings.ts_path(root);
let cpp_dir = project.bindings.cpp_path(root);
let config = project.bindings.uniffi_toml_path(root);
Expand Down
1 change: 1 addition & 0 deletions crates/ubrn_cli/src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl IOsArgs {
let ios = &config.ios;
let project_root = config.project_root();
let ios_dir = ios.directory(project_root);
ubrn_common::mk_dir(&ios_dir)?;
let mut library_args = Vec::new();
for library in target_files {
// :eyes: single dash arg.
Expand Down
8 changes: 7 additions & 1 deletion crates/ubrn_cli/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ impl CrateConfig {
Ok(self.directory()?.join(&self.manifest_path))
}

pub(crate) fn crate_dir(&self) -> Result<Utf8PathBuf> {
let manifest = self.manifest_path()?;
let dir = manifest.parent().unwrap();
Ok(dir.into())
}

pub(crate) fn metadata(&self) -> Result<CrateMetadata> {
self.manifest_path()?.try_into()
}
Expand All @@ -57,7 +63,7 @@ pub(crate) enum RustSource {

#[derive(Debug, Deserialize)]
pub(crate) struct OnDiskArgs {
#[serde(alias = "rust")]
#[serde(alias = "rust", alias = "directory")]
pub(crate) src: String,
}

Expand Down
10 changes: 10 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Summary

[Introduction](README.md)

* [Getting Started](getting-started/README.md)
- [Before you start](getting-started/pre-installation.md)
- [Step by step: Make your first library project](getting-started/guide.md)

* [Reference](api/README.md)
- [Command Line](api/commandline.md)
- [Configuring your project](api/config-yaml.md)
- [Tweaking code generation](api/uniffi-toml.md)
- [Generating a Turbo Module](api/turbo-module-files.md)
Empty file added docs/src/api/README.md
Empty file.
Loading