-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
21 lines (20 loc) · 722 Bytes
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fs = require 'fs'
{join, resolve, basename} = require 'path'
module.exports = require_directory = (directory) ->
directory = resolve(directory)
fs.readdirSync(directory).reduce (hash, file) ->
file_path = join(directory, file)
file_name = file.substring(0, file.lastIndexOf('.'))
file_extension = file.substring(file.lastIndexOf('.'))
if fs.statSync(file_path).isDirectory()
hash[basename(file_path)] = require_directory(file_path)
else
if file_extension not in ['.coffee', '.js']
return hash
else if file_name is 'index' and typeof require(file_path) is 'object'
for key, value of require(file_path)
hash[key] = value
else
hash[file_name] = require(file_path)
return hash
, {}