or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browser.mdcli.mdcompilation.mdindex.mdparsing.mdregistration.mdrepl.mdutilities.md
tile.json

cli.mddocs/

Command Line Interface

Command-line tools for compiling, running, and building CoffeeScript projects from the terminal, including the main coffee compiler and cake build system.

Coffee Command

The primary command-line tool for CoffeeScript compilation and execution.

Basic Usage

# Compile CoffeeScript files to JavaScript
coffee -c script.coffee
coffee -c src/

# Run CoffeeScript files directly
coffee script.coffee
coffee src/app.coffee

# Interactive REPL
coffee

# Print compiled JavaScript without writing files
coffee -p script.coffee

# Evaluate CoffeeScript expression
coffee -e "console.log 'Hello World'"

Compilation Options

# Compile to specific output directory
coffee -c -o lib/ src/

# Watch files for changes and recompile
coffee -w -c src/

# Compile with source maps
coffee -c -m script.coffee

# Bare compilation (no wrapper function)
coffee -c -b script.coffee

# Include header comment
coffee -c --header script.coffee

# Compile literate CoffeeScript
coffee -c docs.litcoffee
coffee -c readme.coffee.md

Advanced Options

# Transpile with Babel (requires @babel/core)
coffee -c -t script.coffee

# Custom Babel configuration
coffee -c -t --transpile-options '{"presets": ["@babel/preset-env"]}' script.coffee

# Require modules before execution
coffee -r ./setup.js script.coffee

# Set Node.js options
coffee --nodejs --max-old-space-size=4096 script.coffee

# Print help
coffee --help

# Print version
coffee --version

File Watching

The watch mode (-w or --watch) automatically recompiles files when they change:

# Watch single file
coffee -w -c script.coffee

# Watch directory
coffee -w -c -o lib/ src/

# Watch with specific output
coffee -w -c -o build/ src/

Watch behavior:

  • Monitors file system for changes
  • Recompiles modified .coffee, .litcoffee, and .coffee.md files
  • Displays compilation status and errors
  • Continues running until manually stopped (Ctrl+C)

Interactive REPL

Start an interactive CoffeeScript session:

coffee

REPL features:

  • Multiline input support
  • Command history (saved to ~/.coffee_history)
  • Tab completion for variables and properties
  • Access to Node.js globals and modules
  • Top-level await support
coffee> square = (x) -> x * x
[Function: square]
coffee> square 5
25
coffee> fs = require 'fs'
{ readFile: [Function], ... }
coffee> files = await fs.promises.readdir '.'
[ 'script.coffee', 'package.json', ... ]

Print and Eval Modes

# Print compiled JavaScript to stdout
coffee -p script.coffee

# Evaluate CoffeeScript expression
coffee -e "console.log Math.sqrt 16"

# Evaluate and print result
coffee -pe "square = (x) -> x * x; square 7"

# Evaluate with required modules
coffee -r underscore -e "console.log _.VERSION"

Error Handling

The coffee command provides detailed error reporting:

$ coffee invalid.coffee
invalid.coffee:3:15: error: unexpected ->
  broken syntax ->
                 ^^

Error output includes:

  • Filename and line/column location
  • Error description
  • Code context with pointer to error location
  • Stack trace for runtime errors

Environment Variables

# Set Node.js options
export NODE_OPTIONS="--max-old-space-size=4096"
coffee script.coffee

# Custom REPL history file
export COFFEE_HISTORY="/path/to/custom_history"
coffee

# Disable colors in output
export NO_COLOR=1
coffee script.coffee

Cake Command

Build system and task runner for CoffeeScript projects using Cakefile definitions.

Basic Usage

# Run default task
cake

# Run specific task
cake build
cake test
cake deploy

# List available tasks
cake --help

Cakefile Structure

Create a Cakefile in your project root to define build tasks:

# Cakefile
fs = require 'fs'
{exec} = require 'child_process'

# Task definitions
task 'build', 'Build the project', ->
  console.log 'Building project...'
  exec 'coffee -c -o lib/ src/', (err, stdout, stderr) ->
    console.log stdout if stdout
    console.error stderr if stderr
    if err
      console.error 'Build failed:', err
    else
      console.log 'Build complete!'

task 'test', 'Run tests', ->
  console.log 'Running tests...'
  exec 'npm test', (err, stdout, stderr) ->
    console.log stdout if stdout
    console.error stderr if stderr

task 'clean', 'Clean build files', ->
  console.log 'Cleaning...'
  exec 'rm -rf lib/', (err) ->
    if err
      console.error 'Clean failed:', err
    else
      console.log 'Clean complete!'

task 'watch', 'Watch and build on changes', ->
  console.log 'Watching for changes...'
  exec 'coffee -w -c -o lib/ src/'

# Task with options
option '-e', '--environment [ENV]', 'Environment (dev/prod)'

task 'deploy', 'Deploy the application', (options) ->
  env = options.environment or 'dev'
  console.log "Deploying to #{env}..."
  # Deployment logic here

Task Definition API

/**
 * Define a build task
 * @param name - Task name for command line
 * @param description - Description shown in help
 * @param action - Function to execute when task runs
 */
task(name: string, description: string, action: (options: any) => void): void;

/**
 * Define command line option for tasks
 * @param short - Short option flag (e.g., '-e')
 * @param long - Long option flag (e.g., '--environment')
 * @param description - Option description
 */
option(short: string, long: string, description: string): void;

/**
 * Execute shell command
 * @param command - Shell command to execute
 * @param callback - Callback function (err, stdout, stderr) => void
 */
exec(command: string, callback?: (err: Error, stdout: string, stderr: string) => void): void;

Advanced Cake Usage

# Cakefile with dependencies and complex tasks
fs = require 'fs'
path = require 'path'
{exec, spawn} = require 'child_process'

# Helper functions
log = (message) -> console.log "[#{new Date().toISOString()}] #{message}"
error = (message) -> console.error "[ERROR] #{message}"

# Build configuration
config =
  srcDir: 'src'
  libDir: 'lib'
  testDir: 'test'

# Utility task for directory creation
ensureDir = (dir, callback) ->
  fs.mkdir dir, recursive: true, (err) ->
    if err and err.code isnt 'EEXIST'
      error "Failed to create directory #{dir}: #{err.message}"
    else
      callback?()

# Complex build task
task 'build', 'Build the entire project', ->
  log 'Starting build process...'
  
  ensureDir config.libDir, ->
    log 'Compiling CoffeeScript...'
    exec "coffee -c -o #{config.libDir}/ #{config.srcDir}/", (err, stdout, stderr) ->
      if err
        error "Compilation failed: #{err.message}"
        process.exit 1
      else
        log 'Build completed successfully!'

# Test task with multiple test runners
task 'test', 'Run all tests', ->
  log 'Running unit tests...'
  exec 'npm test', (err, stdout, stderr) ->
    console.log stdout if stdout
    if err
      error "Tests failed: #{err.message}"
      process.exit 1
    else
      log 'All tests passed!'

# Development server task
task 'serve', 'Start development server', ->
  log 'Starting development server...'
  server = spawn 'node', ['server.js'], stdio: 'inherit'
  
  process.on 'SIGINT', ->
    log 'Stopping server...'
    server.kill 'SIGINT'
    process.exit 0

# Parallel task execution
task 'dev', 'Start development environment', ->
  log 'Starting development environment...'
  
  # Start file watcher
  watcher = spawn 'coffee', ['-w', '-c', '-o', config.libDir, config.srcDir], 
    stdio: 'inherit'
  
  # Start development server  
  server = spawn 'node', ['server.js'], stdio: 'inherit'
  
  process.on 'SIGINT', ->
    log 'Stopping development environment...'
    watcher.kill 'SIGINT'
    server.kill 'SIGINT'
    process.exit 0

Cake Command Options

# Run cake with specific options
cake deploy -e production
cake build --verbose
cake test --reporter spec

# Pass Node.js options to cake
cake --nodejs --max-old-space-size=4096 build

# Get help for available tasks and options
cake --help

Command Integration

Both coffee and cake commands integrate seamlessly with Node.js tooling:

Package.json Scripts

{
  "scripts": {
    "build": "coffee -c -o lib/ src/",
    "watch": "coffee -w -c -o lib/ src/",
    "test": "coffee -c test/ && npm run test:js",
    "dev": "cake dev",
    "deploy": "cake deploy -e production"
  }
}

Build Tool Integration

# Webpack integration
webpack --watch --config webpack.config.coffee

# Gulp integration  
gulp --require coffeescript/register --gulpfile gulpfile.coffee

# Grunt integration
grunt --gruntfile Gruntfile.coffee

IDE and Editor Integration

Most editors support CoffeeScript through plugins that use the CLI tools:

  • VS Code: CoffeeScript extension using coffee -c
  • Sublime Text: CoffeeScript build system
  • Vim: CoffeeScript syntax and compilation plugins
  • Atom: Built-in CoffeeScript support

Performance Tips

# Compile only changed files (faster for large projects)
coffee -c $(find src/ -name "*.coffee" -newer lib/)

# Use parallel compilation for multiple files
ls src/*.coffee | xargs -P 4 -I {} coffee -c -o lib/ {}

# Pre-compile for production (avoid runtime compilation)
coffee -c -o dist/ src/
NODE_ENV=production node dist/app.js