Takuya71 のぶろぐ

外資系ソフトウェア会社で働いてます、認定スクラムマスター

Mac OSX 10.8 Mountain Lion に coffee-script を install

Mac OSX 10.8 Mountain Lion に coffee-script を install

今回は coffee-script を Mac OSX 10.8 にインストールします。

nodejs を install

coffee-script をインストールする前に node.js をインストールする必要があります。
node.js は homebrew を使ってインストールしました。

brew install nodejs      
==> Downloading http://nodejs.org/dist/v0.8.8/node-v0.8.8.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/node/0.8.8
==> make install
==> Caveats
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
  /usr/local/share/npm/bin
==> Summary
/usr/local/Cellar/node/0.8.8: 846 files, 13M, built in 2.8 minutes

node.js が無事インストールできました。

% which npm
/usr/local/bin/npm

npm/usr/local/bin/npm にインストールされています。

npm で coffee-script を install

次は coffee-script のインストールです。 こちらは npm を使ってインストールを行います。

% npm install coffee-script -g
npm http GET https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/coffee-script
/usr/local/share/npm/bin/coffee -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/coffee
/usr/local/share/npm/bin/cake -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/cake
coffee-script@1.3.3 /usr/local/share/npm/lib/node_modules/coffee-script

uninstall

アンインストールする場合には

% npm uninstall coffee-script

とします。

path を設定

/usr/local/share/npm/bin にパスを通します。
私は zsh を使っているので .zshrc で PATH を変更しました。

export PATH=$PATH:/usr/local/share/npm/bin

/etc/paths に/usr/local/share/npm/binを追加してもよいです。

coffee 実行

% coffee
coffee> console.log "Hello World"
Hello World
undifined

coffee -> javascript 変換

% cat -n hello.coffee
     1  hello = ->
     2    console.log("hello world")
     3  hello()

javascript に変換

% coffee -c hello.coffee

% cat -n hello.js    
     1  // Generated by CoffeeScript 1.3.3
     2  (function() {
     3    var hello;
     4  
     5    hello = function() {
     6      return console.log("hello world");
     7    };
     8  
     9    hello();
    10  
    11  }).call(this);

変換されたjavascript を実行

% node hello.js 
hello world

問題なくインストールできました。

gist

my gist