#!/bin/bash # Advanced Leptos Component Generator Script # Usage: ./scripts/generate_leptos_component_advanced.sh [description] set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_header() { echo -e "${BLUE}================================${NC}" echo -e "${BLUE} Advanced Leptos Generator${NC}" echo -e "${BLUE}================================${NC}" } print_component_type() { echo -e "${PURPLE}[COMPONENT TYPE]${NC} $1" } # Check if component name and type are provided if [ $# -lt 2 ]; then print_error "Usage: $0 [description]" print_error "Component types: basic, form, interactive, layout, feedback" print_error "Example: $0 input form 'Form input component'" print_error "Example: $0 button basic 'Button component'" exit 1 fi COMPONENT_NAME=$1 COMPONENT_TYPE=$2 DESCRIPTION=${3:-"Leptos port of shadcn/ui $COMPONENT_NAME"} COMPONENT_DIR="packages/leptos/$COMPONENT_NAME" COMPONENT_NAME_CAMEL=$(echo $COMPONENT_NAME | sed 's/-\([a-z]\)/\U\1/g') COMPONENT_NAME_PASCAL=$(echo $COMPONENT_NAME | sed 's/-\([a-z]\)/\U\1/g' | sed 's/^\([a-z]\)/\U\1/') print_header print_status "Generating Leptos component: $COMPONENT_NAME" print_component_type "$COMPONENT_TYPE" print_status "Description: $DESCRIPTION" print_status "Component directory: $COMPONENT_DIR" # Create component directory mkdir -p "$COMPONENT_DIR/src" # Generate Cargo.toml cat > "$COMPONENT_DIR/Cargo.toml" << EOF [package] name = "shadcn-ui-leptos-$COMPONENT_NAME" description = "$DESCRIPTION" homepage = "https://shadcn-ui.rustforweb.org/components/$COMPONENT_NAME.html" publish = false authors.workspace = true edition.workspace = true license.workspace = true repository.workspace = true version.workspace = true [dependencies] leptos.workspace = true leptos-node-ref.workspace = true leptos-struct-component.workspace = true leptos-style.workspace = true tailwind_fuse.workspace = true [features] default = [] new_york = [] [dev-dependencies] shadcn-ui-test-utils = { path = "../../test-utils", features = ["leptos-testing"] } wasm-bindgen-test = { workspace = true } EOF # Generate lib.rs cat > "$COMPONENT_DIR/src/lib.rs" << EOF //! $DESCRIPTION //! //! See [the Rust shadcn/ui book](https://shadcn-ui.rustforweb.org/components/$COMPONENT_NAME.html) for more documentation. pub mod default; pub mod new_york; // Re-export the components for easy access pub use default::{$COMPONENT_NAME_PASCAL}; pub use new_york::{$COMPONENT_NAME_PASCAL as ${COMPONENT_NAME_PASCAL}NewYork}; #[cfg(test)] mod tests; EOF # Function to generate component based on type generate_component_by_type() { local component_type=$1 local file_path=$2 case $component_type in "basic") generate_basic_component "$file_path" ;; "form") generate_form_component "$file_path" ;; "interactive") generate_interactive_component "$file_path" ;; "layout") generate_layout_component "$file_path" ;; "feedback") generate_feedback_component "$file_path" ;; *) generate_basic_component "$file_path" ;; esac } # Basic component template generate_basic_component() { local file_path=$1 cat > "$file_path" << EOF use leptos::{ev::MouseEvent, prelude::*}; use leptos_style::Style; // Static classes for better compilation compatibility const ${COMPONENT_NAME_CAMEL^^}_CLASS: &str = "base-class-here"; #[component] pub fn $COMPONENT_NAME_PASCAL( // Add your props here #[prop(into, optional)] class: MaybeProp, #[prop(into, optional)] id: MaybeProp, #[prop(into, optional)] style: Signal