From 50159cc5713e49fb3ee9c3a36f1ba139be5198ae Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Mon, 13 Nov 2023 18:59:52 -0500 Subject: [PATCH] Extract cargo-i18n binary to a separate crate - reduce dependencies on the main crate drastically - import serde derive via serde import --- Cargo.toml | 17 +---------------- crates/cli/Cargo.toml | 21 +++++++++++++++++++++ {src => crates/cli/src}/config.rs | 3 ++- {src => crates/cli/src}/main.rs | 3 --- 4 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 crates/cli/Cargo.toml rename {src => crates/cli/src}/config.rs (97%) rename {src => crates/cli/src}/main.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 04ec6f0..d2c8b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,17 +13,9 @@ repository = "https://github.com/longbridgeapp/rust-i18n" version = "2.2.1" [dependencies] -anyhow = {version = "1", optional = true} -clap = {version = "2.32", optional = true} -itertools = {version = "0.10.3", optional = true} once_cell = "1.10.0" -quote = {version = "1", optional = true} -rust-i18n-extract = {path = "./crates/extract", version = "2.1.0", optional = true} rust-i18n-support = {path = "./crates/support", version = "2.1.0"} rust-i18n-macro = {path = "./crates/macro", version = "2.1.0"} -serde = "1" -serde_derive = "1" -toml = "0.7.4" [dev-dependencies] foo = {path = "examples/foo"} @@ -31,9 +23,6 @@ criterion = "0.5" lazy_static = "1" serde_yaml = "0.8" -[features] -default = ["rust-i18n-extract", "clap", "anyhow", "quote", "itertools"] - [build-dependencies] globwalk = "0.8.1" regex = "1" @@ -42,13 +31,9 @@ regex = "1" name = "app" test = true -[[bin]] -name = "cargo-i18n" -path = "src/main.rs" -required-features = ["default"] - [workspace] members = [ + "crates/cli", "crates/extract", "crates/support", "crates/macro", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml new file mode 100644 index 0000000..ee1ac25 --- /dev/null +++ b/crates/cli/Cargo.toml @@ -0,0 +1,21 @@ +[package] +description = "cargo-i18n tool for the rust-i18n crate." +edition = "2021" +license = "MIT" +name = "rust-i18n-cli" +readme = "../../README.md" +repository = "https://github.com/longbridgeapp/rust-i18n" +version = "2.1.0" + +[dependencies] +anyhow = "1" +clap = "2.32" +itertools = "0.10.3" +rust-i18n-support = { path = "../support", version = "2.1.0" } +rust-i18n-extract = { path = "../extract", version = "2.1.0" } +serde = { version = "1", features = ["derive"] } +toml = "0.7.4" + +[[bin]] +name = "cargo-i18n" +path = "src/main.rs" diff --git a/src/config.rs b/crates/cli/src/config.rs similarity index 97% rename from src/config.rs rename to crates/cli/src/config.rs index 53743ac..883a433 100644 --- a/src/config.rs +++ b/crates/cli/src/config.rs @@ -4,6 +4,7 @@ //! See `Manifest::from_slice`. use itertools::Itertools; +use serde::{Deserialize, Serialize}; use std::fs; use std::io; use std::io::Read; @@ -138,7 +139,7 @@ fn test_load_default() { #[test] fn test_load() { let workdir = Path::new(env!["CARGO_MANIFEST_DIR"]); - let cargo_root = workdir.join("examples/foo"); + let cargo_root = workdir.join("../../examples/foo"); let cfg = load(&cargo_root).unwrap(); assert_eq!(cfg.default_locale, "en"); diff --git a/src/main.rs b/crates/cli/src/main.rs similarity index 98% rename from src/main.rs rename to crates/cli/src/main.rs index 951dac9..8704a77 100644 --- a/src/main.rs +++ b/crates/cli/src/main.rs @@ -6,9 +6,6 @@ use std::{collections::HashMap, path::Path}; use rust_i18n_extract::{extractor, generator, iter}; mod config; -#[macro_use] -extern crate serde_derive; - const APP_NAME: &str = "rust-i18n"; const ABOUT: &str = r#"Rust I18n command for help you simply to extract all untranslated texts from soruce code.