Requirement
Install
npm install requirement --save
Why index
Generating index files allows you to do a require
on any directory and get back an object representing the directory structure.
For big projects, this allows you to require dependencies in a more concise way.
Example
cms/index.coffee
:
# Generated by `gulp index`. # module.exports = Editor: Article: require "./editor/cms.editor.article" Header: require "./editor/cms.editor.header" Header: require "./header/cms.header" Modals: Cropper: require "./modals/cms.modals.cropper" Embed: require "./modals/cms.modals.embed" Media: require "./modals/cms.modals.media" Headers: Publish: require "./modals/headers/cms.modals.headers.publish" Strip: require "./modals/headers/cms.modals.headers.strip"
Now requiring becomes easy:
require "./cms"
Indexing with explicit requires also keeps your project compliant with Browserify compilation.
Build indices
This gulp task generates an index.coffee
file in a directory and its subdirectories.
gulp = require "gulp"Task = require"requirement"Task gulptask "index"-> paths = "/../../app/scripts" "/../../app2/components" paths