A lightweight, modular bash-based CLI tool for generating TypeScript boilerplate code for the shared-kernel project.
- 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
bash schorts/install.shThis will:
- Copy command modules to
~/.schorts/commands/ - Copy templates to
~/.schorts/templates/ - Create the
schortsbinary in~/.local/bin/
Make sure ~/.local/bin is in your PATH:
export PATH="$HOME/.local/bin:$PATH"schorts list templatesschorts generate <template> <name># 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| 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 |
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
- CLI Binary:
~/.local/bin/schorts - Commands:
~/.schorts/commands/ - Templates:
~/.schorts/templates/
- Template Selection: Choose a template type
- Name Conversion: Convert name from PascalCase to kebab-case for filenames
- Template Rendering: Replace placeholders in template
- File Creation: Write rendered content to appropriate directory
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 |
-
Create a new template file in
schorts/templates/:cat > schorts/templates/my-template.ts << 'EOF' export class {{CLASS_NAME}} { // Your template code here } EOF
-
Update the
01-generate.shcommand 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" ;;
-
Reinstall:
bash schorts/install.sh
-
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
-
Update the case statement in
install.sh(binary section) -
Add help text in
04-help.sh -
Reinstall:
bash schorts/install.sh
log "Info message" # ➜ Blue arrow
warn "Warning message" # ⚠️ Yellow
error "Error message" # ❌ Red (exits with code 1)
success "Success message" # ✅ Green
info "Info message" # ℹ Cyanto_pascal_case "my-command" # MyCommand
to_kebab_case "MyCommand" # my-commandensure_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/ directorylist_templates # List available templates
template_exists "command" # Check if template exists
render_template "command" "MyCommand" # Render template with placeholders# 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 TestCommandMake sure ~/.local/bin is in your PATH:
echo $PATH | grep ~/.local/binIf not present, add it to your shell profile:
export PATH="$HOME/.local/bin:$PATH"Ensure templates are installed:
ls ~/.schorts/templates/If missing, reinstall:
bash schorts/install.shThe CLI prevents overwriting existing files. Delete the file or use a different name:
rm src/cqrs/commands/my-command.ts
schorts generate command MyCommandTo modify or extend schorts:
- Edit the relevant file in
schorts/ - Test syntax:
bash -n <file> - Reinstall:
bash schorts/install.sh - Test functionality:
schorts <command>
Part of the shared-kernel project.