raptorjs-legacy / raptorjs

Source code for the RaptorJS Toolkit
Other
94 stars 12 forks source link

Support for wildcard dependency inclusion in package.json #4

Open philidem opened 11 years ago

philidem commented 11 years ago

If there are several static files that need to be included then it might be helpful to be define dependencies via includes.

For example: "dependencies": [ "images/*" ]

patrick-steele-idem commented 11 years ago

In cases where consistent file naming pattern is is used to identify files that are associated with a particular extension we can simplify package.json files as shown in the following proposal:

{
    "raptor": {
        "dependencies": [
            { "include-pattern": "\\.*", "extension-pattern": "_([A-Za-z0-9]+)\\." }
        ]
    }
}

For example, the extension would be extracted as shown: cookies.js → (none) cookies_node.jsnode cookies_browser.jsbrowser

NOTE: This solution works when order does not matter (which is normally the case). If order matters then the old package.json format could still be used.

Any objections to the proposed solution? If not, I think we should support it.

philidem commented 11 years ago

Embedding regular expressions in strings is painful. What about supporting a simple wildcard pattern (globs)? I would much rather use "*.js". Could use something like: https://github.com/kthompson/glob-js

philidem commented 11 years ago

Actually, I would recommend using https://github.com/isaacs/minimatch for glob pattern matching (doesn't pull in the recursive directory searching). You can also create a cache of glob patterns to precompiled minimatch objects (which internally use a regex I believe).

philidem commented 11 years ago

I implemented this and I'll check it in shortly: {"type": "glob", "include": [".js", ".rhtml"]}

You can also add exclude: {"type": "glob", "include": [".js", ".rhtml"], "exclude": ["bad.js"]}

As a shorthand, you can specify include and exclude with just the pattern (and not an array of patterns): {"type": "glob", "include": "*.js"}

philidem commented 11 years ago

I think we agreed on the pattern matching but we wanted to change the way you use it in package.json. We also wanted to switch to using raptor's simple regexp class. Let me know if you need any help finalizing this. Do you remember what syntax we agreed on for package.json?