0

On Windows, I have the following .cmd file:

.\node_modules\.bin\coffee .\lib\cli --html="index.htm" --whichBuild="configs/whichBuild.xml" %*

That is:

  • I call .\node_modules\.bin\coffee.cmd
  • Telling it to execute .\lib\cli.coffee
  • Passing it parameters --html="index.htm" --whichBuild="configs/whichBuild.xml"
  • And also passing it any parameters the user gave me on the command line.

On Mac, I've got no idea what to do. node.exe and coffee.cmd aren't going to be around. How are these things accomplished?

I want something easy I can tell our build-guy "run myCommand arg1 arg2 and it'll work." I have that on Windows, but on Mac I'm clueless.

Also of note: one of the features of my Windows approach that is nice is our build-guy doesn't have to install node or npm or coffee-script or anything. He just grabs a directory from source control, which has node.exe, coffee.cmd, etc. all packaged up. A similar feature for Mac would be highly desired.

1
  • I'm not sure what the equivalent tools are on a Mac, but what you're looking for is typically call a Shell Script on *nix (Including Linux and Mac) systems. I don't know anything about coffee, but if it has an equivalent tool to the coffee.cmd on a Mac you should be able to put together something to do that. Commented Jan 24, 2012 at 19:47

2 Answers 2

3

You can be sure that OS X installs a version of Ruby so this little Ruby script should be equivalent to what you wrote and work on OS X.

#!/usr/bin/env ruby

args = ARGV.join(" ")
system %Q{./node_modules/coffee-script/bin/coffee ./lib/cli --html="index.htm" --whichBuild="configs/whichBuild.xml" #{args}}

So write that into a text file named something like myMacCommand then make sure the file is executable by running chmod +x myMacCommand now running the script from the command-line should be as simple as ./myMacCommand --option1=blah --option2=blah

Edit:

Thinking this through a little more, the script above might not actually work since the Mac wouldn't have node.js installed, which I believe is required by CoffeeScript.

IMHO, your time might be better spent documenting how to install node & coffee-script locally than in creating a script to work around the developer not having them installed.

Sign up to request clarification or add additional context in comments.

2 Comments

From what I can tell this might work if I only install node, without requiring an installation of npm + coffeescript. Would that be correct? If so I think it's the best way to go.
Hi. Correct. If node is installed the script above should work.
3

First off, you can install node.js on a Mac using the installer on the node.js web site.

Remember that OSX is a flavour of unix, so you have a variety of scripting languages available to you. These can be used to make "shell scripts". In OSX (as in Linux) the common scripting language is "bash". When you launch Terminal in OSX, you are running an "interactive" shell, which can be used to run shell scripts or other commands.

Shell scripts are text files that usually start with a line that identifies which interpreter the script will use. For example, #!/bin/bash or #!/usr/bin/ruby or #!/usr/local/bin/tclsh. You'll note that each of these starts with #!, which is called "shell magic" or "shbang".

If node.js is installed in OSX from the installer package from nodejs.org, then you'll have /usr/local/bin/node which can be used with shell magic. Thus:#!/usr/local/bin/node ... though if you want your script to be able to run on different systems that may have node.js installed in different places, #!/usr/bin/env node is a more compatible option.

Clear as mud? :-)

1 Comment

So this gets me started, I guess. I suppose I'd write a little JavaScript program to manually call the coffee script runner and do arg parsing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.