LinuxCommandLibrary

coffee

Prevent the system from sleeping

TLDR

Run a script

$ coffee [path/to/file.coffee]
copy

Compile to JavaScript and save to a file with the same name
$ coffee --compile [path/to/file.coffee]
copy

Compile to JavaScript and save to a given output file
$ coffee --compile [path/to/file.coffee] --output [path/to/file.js]
copy

Start a REPL (interactive shell)
$ coffee --interactive
copy

Watch script for changes and re-run script
$ coffee --watch [path/to/file.coffee]
copy

SYNOPSIS

coffee [options] <file ...>
coffee [options] -e <command>
coffee [options] -c <file ...>
coffee (starts REPL if no arguments)

PARAMETERS

-c, --compile
    Compiles .coffee files into .js.

-o <dir>, --output <dir>
    Sets the output directory for compiled JavaScript.

-w, --watch
    Watches source files for changes and recompiles.

-j <file>, --join <file>
    Concatenates all compiled JavaScript into a single file.

-e <command>, --eval <command>
    Evaluates a string of CoffeeScript.

-p, --print
    Prints the compiled JavaScript to stdout.

-l, --lint
    Prints potential errors and warnings (deprecated).

-s, --stdio
    Reads CoffeeScript from stdin, writes JavaScript to stdout.

-b, --bare
    Compiles without the top-level function wrapper, preventing variable leakage.

-m, --map
    Generates source maps, aiding debugging of compiled JavaScript.

-v, --version
    Prints the CoffeeScript version.

-h, --help
    Displays help information.

DESCRIPTION

The `coffee` command is the primary interface for CoffeeScript, a programming language that transpiles into JavaScript. Designed to enhance JavaScript's readability and conciseness, CoffeeScript introduces a more Ruby-like syntax, omitting many of JavaScript's often verbose elements like semicolons, parentheses for function calls, and curly braces for blocks. Its primary goal is to expose the good parts of JavaScript in a simpler, more approachable way.

The `coffee` command allows users to compile `.coffee` source files into `.js` files, execute CoffeeScript code directly, or even run a CoffeeScript REPL (Read-Eval-Print Loop) for interactive development. While it enjoyed significant popularity as a preferred language for web development before the widespread adoption of ECMAScript 2015 (ES6) and later standards, which introduced many of the features CoffeeScript pioneered, it remains a robust tool for those who appreciate its unique syntax and philosophy.

CAVEATS

The `coffee` command requires Node.js and npm to be installed on the system, as CoffeeScript itself is written in JavaScript and distributed via npm. While CoffeeScript offers a concise syntax, its use has declined significantly since the advent of ECMAScript 2015 (ES6) and subsequent JavaScript standards, which have incorporated many features (e.g., arrow functions, classes, template literals) that CoffeeScript initially provided as syntactic sugar. This means less community support and fewer new projects adopting it compared to native JavaScript or TypeScript. Debugging compiled CoffeeScript can also be more challenging without proper source map setup, as error messages refer to the generated JavaScript.

<B>INSTALLATION</B>

The `coffee` command is not typically pre-installed on Linux distributions. It can be installed globally using npm (Node Package Manager), which usually comes bundled with Node.js:
npm install -g coffeescript

<B>USAGE EXAMPLES</B>

Compile a single file:
coffee -c my_script.coffee
(This will create `my_script.js` in the same directory)

Compile a directory and watch for changes:
coffee -o lib/ -cw src/
(Compiles `.coffee` files from `src/` into `lib/` and watches for modifications)

Execute a CoffeeScript file directly:
coffee my_script.coffee

Start an interactive REPL:
coffee
(Allows interactive CoffeeScript code execution)

HISTORY

CoffeeScript was created by Jeremy Ashkenas and first publicly released in December 2009. It rapidly gained popularity within the web development community for its elegant syntax and the solutions it offered to JavaScript's perceived verbosity and quirks. It significantly influenced the design of future JavaScript standards, with many of its features (like arrow functions, classes, and destructuring assignment) eventually being adopted into ECMAScript 2015 (ES6) and later versions. Its peak usage was around 2013-2015. However, as native JavaScript evolved to include these features, and TypeScript emerged as a strong alternative for type-safe JavaScript development, CoffeeScript's widespread adoption began to decline. It remains a historical milestone in web development language evolution and is still maintained for existing projects.

SEE ALSO

node(1), npm(1), babel(1), tsc(1)

Copied to clipboard