node package manager

glob-brunch

glob-brunch Circle CI

Adds glob support to Brunch. This allows lazy loading/requiring of files using pattern matching. It stores the required filenames within your app.js file using a helper function and therefore cannot be used as a file system browser or such.

Please note that this is a very early alpha of this module and its usage is pretty restrictive. Please read the usage for caveats.

Usage

Add "glob-brunch": "0.0.1" to package.json in your brunch app.

In your code, use glob('[string]') and this plugin will automatically generate a helper function at the top of the module definition. For example:

 
# @file application.coffee 
 
class App extends Application
 
  constructor: () ->
    glob 'views/**/*-view*'(err, files) ->
      console.log files # Should return an array of matching filenames. 
      files.forEach (file) ->
        view = require file
 

This will generate a function on Brunch compilation and prepend it to the file. This function matches the glob definitions and the resolved matches. This means that the glob function MUST use a string as the Node/Brunch side will not evaluate your client-side javascript and thus has no knowledge of scope, variables etc. Hopefully this is something that can get ironed out; but please file an issue or PR if you can think of an obvious solution.

The function will look something like this:

var glob = function (input, callback) {
  switch (input) {
    case 'views/**/*-view*':
      return callback(null, ['views/components/Notification-view', 'views/layouts/HeaderLayout-view']);
  }
}

Config

As of the current version, glob-brunch has three config options:

exports.config =
  ...
  plugins:
    glob:
      appDir: 'app'
      stripExt: true
      stripAppDir: true

License

The MIT License (MIT)

Copyright (c) 2015 Matt Fletcher (http://soniflow.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.