Monday, April 29, 2013

Interactive CoffeeScript from Command Line

Here's how to install the CoffeeScript interpreter and test a ternary operation.


$ npm install -g coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http 200 https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.2.tgz
npm http 200 https://registry.npmjs.org/coffee-script/-/coffee-script-1.6.2.tgz
/usr/local/bin/coffee -> /usr/local/lib/node_modules/coffee-script/bin/coffee
/usr/local/bin/cake -> /usr/local/lib/node_modules/coffee-script/bin/cake
coffee-script@1.6.2 /usr/local/lib/node_modules/coffee-script
$ coffee -h

Usage: coffee [options] path/to/script.coffee -- [args]

If called without options, `coffee` will run your script.

  -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         concatenate the source CoffeeScript before compiling
  -l, --lint         pipe the compiled JavaScript through JavaScript Lint
  -m, --map          generate source map and save as .map files
  -n, --nodes        print out the parse tree that the parser produces
      --nodejs       pass options directly to the "node" binary
  -o, --output       set the output directory for compiled JavaScript
  -p, --print        print out the compiled JavaScript
  -s, --stdio        listen for and compile scripts over stdio
  -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

$ coffee
coffee> name = "Activities"
'Activities'
coffee> a = if name==\"Activities\" then true else false
repl:1:15: error: missing ", starting
a = if name==\"Activities\" then true else false
              ^
coffee> a = if name=="Activities" then true else false
true
coffee>



References

Little Book on CoffeeScript
http://dailyjs.com/2011/05/30/code-review-coffeescript/



Sponsor Ads(Please visit one if you liked this article. Thanks!)

2 comments:

  1. Kameraövervakning



    Vi erbjuder Kvalité och snabb service och vet att det är mycket viktigt att få saker gjort snabbt , därför kan vi erbjuda service avtal Från 99:-/mån så du får snabbt på plats service (även distans avtal)och så ser vi till att du alltid håller ditt kassasystem uppdaterad med den nyaste programvaran!

    Kontakt información:

    Norra Ågatan 5 A Arboga Västmanland 732 31
    teléfono: 0589-10031
    Site: www.kassanetto.se

    ReplyDelete