0

I have a CoffeeScript project (called jAddressParser) that I am hoping to turn into reusable module. Unfortunately I am not overly familiar with how to modularize CoffeeScript for such a purpose, while maintaining sensible interoperability with an existing project.

The project in question parses address strings - no short order, to be sure. However for the purpose of the project I am working on, this strategy should work and it is possible someone else may benefit from it and perhaps others may make some useful contributions. Everybody wins!

So what I have is code laid out in a directory like this:

/
  README.md
  LICENSE
  package.json
  /src
    main.js
    main.coffee
    canada.coffee
    iso3166.js
  /test
  /build

In an ideal world, my workflow would be like this:

  1. Test the above javascript from the command line. I would think Node.js is the most suitable way.

  2. Compile the files in /src to a /build/jAddressParser.js file. I would think r.js would work well for this.

  3. When all is ready, copy the jAddressParser.js from the /build to my web project.

  4. Include the jAddressParser in my web project with the appropriate requirejs call (i.e. it would be AMD-ready) e.g. require(['jAddressParser'], -> ...)

Since it seems I have to include the dependencies (lodash, requirejs, require-cs, XRegExp, CoffeeScript) I expect I will do this by putting specific versions in the /lib directory or by using git submodules (though submodules seems to be a bit of overkill for such a small project).

I have never created a reusable CoffeeScript module, and I was essentially unable to find a good reference on how to perform the same for a web-module (there seem to be some decent examples for projects that are node.js-only - thought I would certainly love to see a list of more). I would be quite grateful for any thoughts or references that may shed light on the viability of the proposal above, or how you yourself might go about organizing such a project?

Community
  • 1
  • 1
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
  • Maybe my answer to [this](http://stackoverflow.com/questions/13050060/compile-and-join-coffeescript-files) question would be helpful. – David Weldon Oct 27 '12 at 02:42
  • @DavidWeldon: That's a helpful guide. I have done [something similar](https://github.com/brianmhunt/jAddressParser/blob/master/Cakefile), but with [coffee-toaster](https://github.com/serpentem/coffee-toaster). – Brian M. Hunt Oct 27 '12 at 16:41

0 Answers0