CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-coffee-script

A programming language that compiles into JavaScript, providing concise syntax and advanced features like classes, comprehensions, and destructuring.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli-tools.mddocs/

Command Line Interface

Command-line tools for compiling, running, and building CoffeeScript projects. CoffeeScript provides two main CLI utilities: coffee for compilation and execution, and cake for build automation.

Capabilities

Coffee Command

Main command-line interface for compiling and running CoffeeScript files.

/**
 * Main command line interface function
 * Handles compilation, execution, and various CoffeeScript operations
 */
function run();

Binary Location: /bin/coffee Module: lib/coffee-script/command.js

Usage Examples:

# Execute a CoffeeScript file
coffee script.coffee

# Compile to JavaScript
coffee -c script.coffee

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

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

# Run interactive REPL
coffee -i

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

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

# Compile without function wrapper
coffee -b -c script.coffee

# Join multiple files before compiling
coffee -j compiled.js -c file1.coffee file2.coffee

# Print tokens (for debugging)
coffee -t script.coffee

# Print AST nodes (for debugging)
coffee -n script.coffee

# Evaluate string directly
coffee -e "console.log 'Hello from CoffeeScript!'"

# Pass options to Node.js
coffee --nodejs --harmony script.coffee

Command Options:

const SWITCHES = [
  ['-b', '--bare', 'compile without a top-level function wrapper'],
  ['-c', '--compile', 'compile to JavaScript and save as .js files'],
  ['-e', '--eval', 'pass a string from the command line as input'],
  ['-h', '--help', 'display this help message'],
  ['-i', '--interactive', 'run an interactive CoffeeScript REPL'],
  ['-j', '--join [FILE]', 'concatenate the source CoffeeScript before compiling'],
  ['-m', '--map', 'generate source map and save as .js.map files'],
  ['-M', '--inline-map', 'generate source map and include it directly in output'],
  ['-n', '--nodes', 'print out the parse tree that the parser produces'],
  ['--nodejs [ARGS]', 'pass options directly to the "node" binary'],
  ['--no-header', 'suppress the "Generated by" header'],
  ['-o', '--output [DIR]', 'set the output directory for compiled JavaScript'],
  ['-p', '--print', 'print out the compiled JavaScript'],
  ['-r', '--require [MODULE*]', 'require the given module before eval or REPL'],
  ['-s', '--stdio', 'listen for and compile scripts over stdio'],
  ['-l', '--literate', 'treat stdio as literate style coffee-script'],
  ['-t', '--tokens', 'print out the tokens that the lexer/rewriter produce'],
  ['-v', '--version', 'display the version number'],
  ['-w', '--watch', 'watch scripts for changes and rerun commands']
];

Cake Command

Build automation tool for CoffeeScript projects, similar to Make or Rake.

/**
 * Main function for cake build tool
 * Executes build tasks defined in Cakefile
 */
function run();

Binary Location: /bin/cake Module: lib/coffee-script/cake.js

Usage Examples:

# List available tasks
cake

# Run a specific task
cake build

# Run task with options
cake deploy --production

# Show task help
cake --help

Cakefile Example:

# Cakefile - build automation for CoffeeScript projects
fs = require 'fs'
{exec} = require 'child_process'

task 'build', 'Build project', ->
  console.log 'Building project...'
  exec 'coffee -c -o lib/ src/', (err, stdout, stderr) ->
    throw err if err
    console.log 'Build complete!'

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

task 'clean', 'Clean build artifacts', ->
  console.log 'Cleaning...'
  exec 'rm -rf lib/', (err) ->
    throw err if err
    console.log 'Clean complete!'

option '-p', '--production', 'Production build'

task 'deploy', 'Deploy application', (options) ->
  if options.production
    console.log 'Production deployment...'
  else
    console.log 'Development deployment...'

Global Functions Available in Cakefile:

/**
 * Define a build task
 * @param name - Task name
 * @param description - Task description
 * @param action - Task function to execute
 */
function task(name, description, action);

/**
 * Define a command line option
 * @param letter - Short option (-p)
 * @param flag - Long option (--production)
 * @param description - Option description
 */
function option(letter, flag, description);

/**
 * Invoke another task by name
 * @param name - Task name to invoke
 */
function invoke(name);

File Watching

The coffee command supports file watching for automatic recompilation during development.

Watch Examples:

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

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

# Watch with multiple options
coffee -w -c -m -o build/ --bare src/

# Watch and execute (useful for development)
coffee -w script.coffee

Watch Features:

  • Monitors file system changes using platform-appropriate methods
  • Automatically recompiles when .coffee files change
  • Handles directory watching recursively
  • Ignores hidden files and common build artifacts
  • Provides console output showing compilation status

Interactive Mode (REPL)

Launch an interactive CoffeeScript Read-Eval-Print Loop for experimentation and debugging.

# Start REPL
coffee -i

# Start REPL with required modules
coffee -i -r lodash -r moment

REPL Features:

  • Full CoffeeScript syntax support
  • Multi-line input handling
  • Command history (saved to ~/.coffee_history)
  • Tab completion for Node.js modules
  • Access to all Node.js built-in modules
  • Context preservation between inputs

Compilation Modes

Standard Compilation:

coffee -c script.coffee  # Creates script.js

Bare Compilation (no wrapper function):

coffee -b -c script.coffee

Source Map Generation:

coffee -m -c script.coffee  # Creates script.js and script.js.map
coffee -M -c script.coffee  # Inline source map in script.js

Output Directory:

coffee -c -o build/ src/  # Output to build/ directory

File Joining:

coffee -j bundle.js -c file1.coffee file2.coffee file3.coffee

Stdio Mode

Process CoffeeScript code through standard input/output pipes:

# Compile from stdin
echo "console.log 'hello'" | coffee -cs

# Process literate CoffeeScript
cat README.litcoffee | coffee -csl

# Use in shell pipelines
find . -name "*.coffee" | xargs coffee -c

Debugging and Inspection

Token Inspection:

coffee -t script.coffee  # Show lexical tokens

AST Inspection:

coffee -n script.coffee  # Show parse tree

Version Information:

coffee -v  # Show CoffeeScript version

Command Integration

The CLI tools integrate seamlessly with the CoffeeScript compilation API:

const CoffeeScript = require('coffee-script');

// The CLI essentially calls these API functions:
const fs = require('fs');

// For compilation:
const source = fs.readFileSync('script.coffee', 'utf8');
const compiled = CoffeeScript.compile(source, {
  filename: 'script.coffee',
  bare: false,
  header: true
});
fs.writeFileSync('script.js', compiled);

// For execution:
CoffeeScript.run(source, { filename: 'script.coffee' });

Build Tool Integration

npm scripts integration:

{
  "scripts": {
    "build": "coffee -c -o lib/ src/",
    "watch": "coffee -w -c -o lib/ src/",
    "dev": "coffee -w app.coffee"
  }
}

Makefile integration:

build:
	coffee -c -o lib/ src/

watch:
	coffee -w -c -o lib/ src/

clean:
	rm -rf lib/

.PHONY: build watch clean

docs

ast-nodes.md

cli-tools.md

compilation.md

execution.md

index.md

repl-interactive.md

utilities.md

tile.json