Skip to content

Instantly share code, notes, and snippets.

@takungsk
Created September 22, 2012 03:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save takungsk/3765014 to your computer and use it in GitHub Desktop.
Save takungsk/3765014 to your computer and use it in GitHub Desktop.
Mac OSX 10.8 Mountain Lion に coffee-script を install

Mac OSX 10.8 Mountain Lion に coffee-script を install

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

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

@MarekZeman91
Copy link

ありがとうございます!!! ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment