sstephenson/stitch — pull request #43 by craigdavey (2012-11-01 20:49:38+00:00)
Title: Filtered paths

I’m working on a project where my models exist in Node and in the browser. The directory layout of the project looks something like this:

application/
models
webserver
website

test/
models
webserver
website

node_modules/
...

vendor/
stitch/
dependencies
modules

In Node, I set `process.env["NODE_PATH"]` to the `application` directory so that I can require my models like this:

Memo = require "models/memo"
Person = require "models/person"

In the browser, I want to require my models using identical paths (`"models/memo"`, `"models/person"`).

And I want Stitch to include everything in `application/models` and `application/website`.

But I want Stitch to exclude everything in `application/webserver`.

And I couldn’t get Stitch to do that :(

---

This pull request lets you define filtered paths that instruct Stitch to selectively include specific subdirectories.
A filtered path ends with a comma separated list of subdirectories that Stitch should include in the script.
All other subdirectories are excluded.

For example, in my project, the script configuration looks like this:

script = stitch.createPackage
paths: [
"application/core_extensions,models,website"
"vendor/stitch/modules"
]
dependencies: [
"vendor/stitch/dependencies/zepto.js"
]

Stitch bundles all my code from:

- application/core_extensions
- application/models
- application/website

Stitch it excludes everything in:

- application/webserver

And, in the browser environment I can require my models like this:

Memo = require "models/memo"
Person = require "models/person"