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

CLI initial concept #304

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4570d9e
CLI initial concept
escritorio-gustavo Apr 9, 2024
7c15180
Add --add-features flag, fix feature! macro and bson-uuid-impl
escritorio-gustavo Apr 9, 2024
1518c18
Remove *-impl features from CLI
escritorio-gustavo Apr 10, 2024
257d04e
Gate test generation behind cargo feature
escritorio-gustavo Apr 10, 2024
27669f1
Update Github action
escritorio-gustavo Apr 10, 2024
ca3eb23
Make the --output-directory flag an Option instead of having a defaul…
escritorio-gustavo Apr 10, 2024
7914bea
Initial draft on generating index.ts
escritorio-gustavo Apr 12, 2024
58df89d
Add missing file
escritorio-gustavo Apr 12, 2024
67f9631
Update Github action
escritorio-gustavo Apr 12, 2024
f092001
Check for empty index and emit codegen warning
escritorio-gustavo Apr 12, 2024
7192a8b
Save relative paths in netadata file
escritorio-gustavo Apr 12, 2024
2b09065
Remove unused import
escritorio-gustavo Apr 12, 2024
d18bf79
Remove unused read file access
escritorio-gustavo Apr 12, 2024
af0d6d3
Add naming collision warning
escritorio-gustavo Apr 12, 2024
41cf034
Add imports
escritorio-gustavo Apr 12, 2024
2ea928f
MAke warnings colorful
escritorio-gustavo Apr 12, 2024
9557f9f
Also highlight type names
escritorio-gustavo Apr 12, 2024
4ec1679
Make type names bold
escritorio-gustavo Apr 12, 2024
9c45249
Remove commented dependency
escritorio-gustavo Apr 12, 2024
98b0c01
Print Rust type name in collision warning
escritorio-gustavo Apr 12, 2024
b80f988
Capture cargo test stderr and stdout
escritorio-gustavo Apr 12, 2024
363f7c8
Refactor CLI code
escritorio-gustavo Apr 12, 2024
7894b4b
Commit untracked files
escritorio-gustavo Apr 12, 2024
65524d5
Export all files, not just the first metadata entry
escritorio-gustavo Apr 12, 2024
7560098
Delete metadata file
escritorio-gustavo Apr 12, 2024
770d6ea
Add metadata file to .gitignore
escritorio-gustavo Apr 12, 2024
e52085c
Enable clippy pedantic and nursery
escritorio-gustavo Apr 12, 2024
275b15d
Merge branch 'main' into cli
escritorio-gustavo Apr 15, 2024
b402bdc
Merge branch 'main' into cli
escritorio-gustavo Apr 15, 2024
b1b5cbe
Clippy warning in test
escritorio-gustavo Apr 17, 2024
6790173
Remove duplicated infer_as test file
escritorio-gustavo Apr 17, 2024
50bfc35
Add error message about naming collisions
escritorio-gustavo Apr 17, 2024
88fc140
Gate metadata file behind feature
escritorio-gustavo Apr 17, 2024
66c94dd
No longer capture stderr as that would silence serde warnings
escritorio-gustavo Apr 17, 2024
1461d3f
Remove changes to infer_as test
escritorio-gustavo Apr 17, 2024
b6c5c65
Make --output-directory required
escritorio-gustavo Apr 17, 2024
c8a6b14
Make casing consistent
escritorio-gustavo Apr 17, 2024
fcaa80f
Merge branch 'main' into cli
escritorio-gustavo Apr 18, 2024
c930c0f
Avoid extra collection allocation
escritorio-gustavo Apr 22, 2024
9b19079
Improve parsing of Metadata
escritorio-gustavo Apr 23, 2024
8ff6688
Replace new with try_from for clarity
escritorio-gustavo Apr 23, 2024
f229f92
Add option to export all types to a single file
escritorio-gustavo May 9, 2024
c9b29aa
Missing imports
escritorio-gustavo May 9, 2024
89430eb
Fix Syntax Error
escritorio-gustavo May 9, 2024
147ea87
Merge branch 'main' into cli
escritorio-gustavo May 20, 2024
00f14af
Merge branch 'main' into cli
gustavo-shigueo Jul 24, 2024
7c9643e
Merge branch 'main' into cli
gustavo-shigueo Aug 1, 2024
5d72d97
Merge branch 'main' into cli
gustavo-shigueo Oct 10, 2024
5abdda9
Fix lockfile
gustavo-shigueo Oct 10, 2024
3aae633
Merge branch 'main' into cli
gustavo-shigueo Feb 22, 2025
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
Next Next commit
CLI initial concept
  • Loading branch information
escritorio-gustavo committed Apr 9, 2024
commit 4570d9e3de8a7a7a06309c99851910d64cedd127
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["macros", "ts-rs", "example"]
members = ["macros", "ts-rs", "example", "cli"]
resolver = "2"
9 changes: 9 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "cargo-ts"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4", features = ["derive"]}
118 changes: 118 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use std::path::PathBuf;

use clap::Parser;

#[derive(Parser, Debug)]
struct Args {
/// Defines where your TS bindings will be saved by setting TS_RS_EXPORT_DIR
#[arg(long, short)]
output_directory: PathBuf,

/// Disables serde compatibility
#[arg(long)]
disable_serde: bool,

/// Disables warnings caused by using serde attributes that ts-rs cannot process
#[arg(long)]
no_warnings: bool,

/// Adds the ".js" extension to import paths
#[arg(long)]
esm_imports: bool,

/// Formats the generated TypeScript files
#[arg(long)]
format: bool,

/// Enables chrono compatibility
#[arg(long)]
chrono: bool,

/// Enables bigdecimal compatibility
#[arg(long)]
bigdecimal: bool,

/// Enables uuid compatibility
#[arg(long)]
uuid: bool,

/// Enables bson compatibility
#[arg(long)]
bson: bool,

/// Enables bytes compatibility
#[arg(long)]
bytes: bool,

/// Enables url compatibility
#[arg(long)]
url: bool,

/// Enables indexmap compatibility
#[arg(long)]
indexmap: bool,

/// Enables ordered-float compatibility
#[arg(long)]
ordered_float: bool,

/// Enables heapless compatibility
#[arg(long)]
heapless: bool,

/// Enables semver compatibility
#[arg(long)]
semver: bool,

/// Enables serde_json compatibility
#[arg(long)]
serde_json: bool,
}

macro_rules! feature {
($cargo_invocation: expr, $args: expr, { $($field: ident => $feature: literal),* $(,)? }) => {
$(
if $args.$field {
$cargo_invocation
.arg("--feature")
.arg(format!("ts-rs/{}", $feature));
}
)*
};
}

fn main() {
let args = Args::parse();

println!("{args:?}");

let mut cargo_invocation = std::process::Command::new("cargo");

cargo_invocation
.arg("test")
.arg("export_bindings_")
.env("TS_RS_EXPORT_DIR", args.output_directory);

if args.disable_serde {
cargo_invocation.arg("--no-default-features");
}

feature!(cargo_invocation, args, {
no_warnings => "no-serde-warnings",
esm_imports => "import-esm",
format => "format",
chrono => "chrono-impl",
bigdecimal => "bigdecimal-impl",
uuid => "uuid-impl",
bson => "bson-impl",
bytes => "bytes-impl",
url => "url-impl",
indexmap => "indexmap-impl",
ordered_float => "ordered-float-impl",
heapless => "heapless-impl",
semver => "semver-impl",
serde_json => "serde-json-impl"
});

cargo_invocation.spawn().unwrap().wait().unwrap();
}