Skip to content

tiulpin/kotlin-cv.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

kotlin-cv.js

CI Code Quality

Personal terminal-like simple webpage template built with Kotlin/JS.

The template features CLI commands like help, cat, ls, grep, wc, and many more utilities. Commands support completion and piping. It's easy to implement your own commands.

Quick Start

# Install just (https://github.com/casey/just) for convenience
# Or use the gradle commands directly

# Development server with hot reload
just dev

# Build for production
just build

# Run all tests
just test

# Run unit tests only
just test-unit

# Run e2e tests (requires npm)
just test-e2e

Build and Run

The built website contains three files:

  • styles.css – terminal styles
  • index.html – HTML entry point
  • kotlin-cv.js – the "CLI" core, built with Kotlin/JS

Commands

# Run dev server
./gradlew jsBrowserDevelopmentRun --continuous

# Build production bundle
./gradlew jsBrowserProductionWebpack

# Run unit tests
./gradlew jsTest

The built website will be located at ./build/kotlin-webpack/js/productionExecutable/.

Deployment

Deploy anywhere you want. The website can be easily deployed to GitHub Pages. The CI workflow automatically deploys to gh-pages branch on push to main.

Customization

How to change the prompt

Edit the host constant in Main.kt:

const val host = "your-domain.com"

How to add a new command

  1. Create a command object implementing the Command interface
  2. Add it to the registry in Registry.kt

Example command:

object MyCommand : Command {
    override val help = "description of my command"
    
    override fun exec(argv: List<String>, print: (String) -> Unit) {
        print("Hello from my command!")
    }
    
    override fun complete(argv: List<String>): List<String> {
        // Return completion suggestions
        return emptyList()
    }
}

// In Registry.kt, add:
"mycommand" to MyCommand,

How to add "files"

Add a new File to the list in Files.kt:

val myFile = File(
    "readme.txt", 
    "This is the content of my file.$br$br Use HTML for formatting."
)

val files = listOf(hey, quoteTxt, myFile)

Available Commands

Command Description
help Show all commands
cat Display file contents
ls List files (with flags: -l, -a, -h, -r, -t, -S, -1)
tree Show file tree
grep Search for patterns
wc Word/line/char count
head/tail Show first/last lines
echo Print text
clear Clear terminal
history Show command history
date Current date/time
whoami Current user
pwd Current directory
printenv Environment variables
uptime Session uptime
neofetch System info
open Open URL
uuid Generate UUID
base64 Encode/decode base64
json Pretty-print JSON
urlencode/urldecode URL encoding
color Preview color
man Manual for command

Piping

Commands support piping:

cat file.txt | grep pattern | wc -l
echo hello world | wc -w

Project Structure

src/
β”œβ”€β”€ jsMain/
β”‚   β”œβ”€β”€ kotlin/
β”‚   β”‚   β”œβ”€β”€ commands/     # Command implementations
β”‚   β”‚   β”‚   β”œβ”€β”€ Command.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ Console.kt
β”‚   β”‚   β”‚   β”œβ”€β”€ Registry.kt
β”‚   β”‚   β”‚   └── ...
β”‚   β”‚   β”œβ”€β”€ Main.kt       # Entry point
β”‚   β”‚   β”œβ”€β”€ Files.kt      # Virtual filesystem
β”‚   β”‚   └── Environment.kt
β”‚   └── resources/
β”‚       β”œβ”€β”€ index.html
β”‚       └── styles.css
└── jsTest/
    └── kotlin/
        └── commands/     # Unit tests
e2e/
β”œβ”€β”€ tests/                # Playwright e2e tests
β”œβ”€β”€ playwright.config.ts
└── package.json

About

πŸš€ CLI-like personal webpage built with Kotlin/JS in less than 900 lines of code

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors