Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

schorts CLI - Boilerplate Generator

A lightweight, modular bash-based CLI tool for generating TypeScript boilerplate code for the shared-kernel project.

Features

  • Modular Architecture: Command-based structure similar to Simply CLI
  • Template System: Pre-built templates for common patterns
  • Git-Aware: Automatically detects project structure
  • Zero Dependencies: Pure bash implementation
  • Easy to Extend: Add new templates and commands easily

Installation

bash schorts/install.sh

This will:

  1. Copy command modules to ~/.schorts/commands/
  2. Copy templates to ~/.schorts/templates/
  3. Create the schorts binary in ~/.local/bin/

Make sure ~/.local/bin is in your PATH:

export PATH="$HOME/.local/bin:$PATH"

Usage

List Available Templates

schorts list templates

Generate Boilerplate

schorts generate <template> <name>

Examples

# Generate a CQRS Command
schorts generate command CreateUser
schorts generate cmd CreateUser

# Generate a CQRS Query
schorts generate query GetUserById
schorts generate q GetUserById

# Generate a Command Handler
schorts generate command-handler CreateUserCommandHandler
schorts generate ch CreateUserCommandHandler

# Generate a Query Handler
schorts generate query-handler GetUserByIdQueryHandler
schorts generate qh GetUserByIdQueryHandler

# Generate an Aggregate
schorts generate aggregate User
schorts generate agg User

# Generate an Exception
schorts generate exception UserNotFound
schorts generate exc UserNotFound

# Generate a Value Object
schorts generate value-object Email
schorts generate vo Email

# Generate a Criteria Specification
schorts generate criteria UserCriteria
schorts generate crit UserCriteria

# Generate an Entity
schorts generate entity UserEntity
schorts generate ent UserEntity

# Generate a Domain Event
schorts generate domain-event UserCreated
schorts generate de UserCreated

Available Templates

Template Aliases Output Directory Description
command cmd src/cqrs/commands/ CQRS Command class
query q src/cqrs/queries/ CQRS Query class
command-handler ch src/cqrs/handlers/ CQRS Command handler class
query-handler qh src/cqrs/handlers/ CQRS Query handler class
aggregate agg, a src/aggregates/ Domain Aggregate root
exception exc, e src/exceptions/ Custom exception class
value-object vo, v src/value-objects/ Value Object class
criteria crit, cr src/criteria/ Criteria search specification class
entity ent, entt src/entities/ Domain Entity class
domain-event de, event src/domain-events/ Domain Event class

Architecture

Directory Structure

schorts/
├── install.sh              # Installation script
├── commands/               # Command modules
│   ├── 00-utils.sh        # Shared utility functions
│   ├── 01-generate.sh     # Generate command
│   ├── 02-list.sh         # List command
│   ├── 03-init.sh         # Init command
│   └── 04-help.sh         # Help command
├── templates/              # Boilerplate templates
│   ├── command.ts
│   ├── query.ts
│   ├── command-handler.ts
│   ├── query-handler.ts
│   ├── aggregate.ts
│   ├── exception.ts
│   ├── value-object.ts
│   ├── criteria.ts
│   ├── entity.ts
│   └── domain-event.ts
└── README.md              # This file

Installation Locations

  • CLI Binary: ~/.local/bin/schorts
  • Commands: ~/.schorts/commands/
  • Templates: ~/.schorts/templates/

How It Works

  1. Template Selection: Choose a template type
  2. Name Conversion: Convert name from PascalCase to kebab-case for filenames
  3. Template Rendering: Replace placeholders in template
  4. File Creation: Write rendered content to appropriate directory

Placeholder Replacement

Templates support the following placeholders:

Placeholder Replaced With
{{CLASS_NAME}} PascalCase name (e.g., CreateUser)
{{KEBAB_NAME}} kebab-case name (e.g., create-user)
{{TIMESTAMP}} ISO 8601 timestamp

How to Add a New Template

  1. Create a new template file in schorts/templates/:

    cat > schorts/templates/my-template.ts << 'EOF'
    export class {{CLASS_NAME}} {
      // Your template code here
    }
    EOF
  2. Update the 01-generate.sh command to handle the new template type:

    my-template)
      output_dir="$src_path/path/to/my-templates"
      output_file="$output_dir/$kebab_name.ts"
      template_type="my-template"
      ;;
  3. Reinstall:

    bash schorts/install.sh

How to Add a New Command

  1. Create a new command file in schorts/commands/:

    cat > schorts/commands/05-mycommand.sh << 'EOF'
    cmd_mycommand() {
      log "Doing something awesome..."
      # Your command logic here
      success "Done!"
    }
    EOF
  2. Update the case statement in install.sh (binary section)

  3. Add help text in 04-help.sh

  4. Reinstall:

    bash schorts/install.sh

Utility Functions (00-utils.sh)

Logging

log "Info message"        # ➜ Blue arrow
warn "Warning message"    # ⚠️  Yellow
error "Error message"     # ❌ Red (exits with code 1)
success "Success message" # ✅ Green
info "Info message"       # ℹ  Cyan

Text Conversion

to_pascal_case "my-command"      # MyCommand
to_kebab_case "MyCommand"        # my-command

Directory Utilities

ensure_dir "/path/to/dir"        # Create if doesn't exist
ensure_not_exists "/path/to/file" # Error if file exists
get_src_path                      # Get project src/ directory

Template Utilities

list_templates                          # List available templates
template_exists "command"               # Check if template exists
render_template "command" "MyCommand"   # Render template with placeholders

Testing

# Syntax check
bash -n schorts/install.sh
bash -n schorts/commands/*.sh

# Test installation
bash schorts/install.sh

# Test commands
schorts help
schorts list templates
schorts init
schorts generate command TestCommand

Troubleshooting

Command Not Found

Make sure ~/.local/bin is in your PATH:

echo $PATH | grep ~/.local/bin

If not present, add it to your shell profile:

export PATH="$HOME/.local/bin:$PATH"

Template Not Found

Ensure templates are installed:

ls ~/.schorts/templates/

If missing, reinstall:

bash schorts/install.sh

File Already Exists

The CLI prevents overwriting existing files. Delete the file or use a different name:

rm src/cqrs/commands/my-command.ts
schorts generate command MyCommand

Contributing

To modify or extend schorts:

  1. Edit the relevant file in schorts/
  2. Test syntax: bash -n <file>
  3. Reinstall: bash schorts/install.sh
  4. Test functionality: schorts <command>

License

Part of the shared-kernel project.

About

A lightweight, modular bash-based CLI tool for generating TypeScript boilerplate code for the shared-kernel project.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages