Skip to content
This repository has been archived by the owner on Oct 20, 2018. It is now read-only.
/ node-rq-dir Public archive

A RequireJS plugin to recursively require files from a directory

License

Notifications You must be signed in to change notification settings

dbartholomae/node-rq-dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-rq-dir@1.0.0

!!! This package is no longer maintained !!!

node-rq-dir is a RequireJS plugin to recursively require files from a directory. It is useful when using requirejs with node. Please note that although the examples are written in CoffeeScript, the plugin currently only reads JavaScript files. Any other files in the folder will be ignored.

define ['rq-dir!configDir', 'path'], (dir, path) ->
  config = {}
  for filename, content of dir
    config[path.basename filename, '.js'] = content
  return config

Example

Assuming the following directory structure

+-- example
|   +-- main.coffee
|   +-- config
|   |   +-- router.js
|   |   +-- database.js
|   |   +-- info.txt
|   |   +-- middleware
|   |   |   +-- security.js

and files router.js, database.js, and security.js all containing

define({});

running the following code from inside example directory

requirejs = require 'requirejs'

requirejs.config
  baseUrl = ''
  nodeRequire: require

requirejs ['rq-dir!configDir', 'path'], (dir, path) ->
  config = {}
  for filename, content of dir
    config[path.basename filename, '.js'] = content
  console.log config

will print (except for comments)

{ database: {}, router: {},  security: {} }

Todos

There should be an option to use another plugin for loading the files.

About

A RequireJS plugin to recursively require files from a directory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published