[Pkg-javascript-commits] [node-require-all] 01/05: Imported Upstream version 0.0.6

Mike Gabriel sunweaver at debian.org
Thu Dec 15 10:18:22 UTC 2016


This is an automated email from the git hooks/post-receive script.

sunweaver pushed a commit to branch master
in repository node-require-all.

commit e967d710f9557457194e1861c4ffc99f66a9701d
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Wed May 15 09:13:55 2013 +0200

    Imported Upstream version 0.0.6
---
 .gitignore                           |  1 +
 License                              | 19 ++++++++++
 Readme.md                            | 17 +++++++++
 index.js                             | 33 ++++++++++++++++++
 package.json                         | 26 ++++++++++++++
 test/controllers/main-Controller.js  |  4 +++
 test/controllers/notthis.js          |  1 +
 test/controllers/other-Controller.js |  2 ++
 test/filterdir/.svn/stuff.js         |  1 +
 test/filterdir/root.js               |  1 +
 test/filterdir/sub/hello.js          |  1 +
 test/mydir/foo.js                    |  1 +
 test/mydir/hello.js                  |  2 ++
 test/mydir/sub/config.json           |  4 +++
 test/mydir/sub/no.2js                |  1 +
 test/mydir/sub/yes.js                |  1 +
 test/test.js                         | 67 ++++++++++++++++++++++++++++++++++++
 17 files changed, 182 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c5d99cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.un~
diff --git a/License b/License
new file mode 100644
index 0000000..143bad2
--- /dev/null
+++ b/License
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Felix Geisendörfer (felix at debuggable.com) and contributors
+
+ 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.
\ No newline at end of file
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..9f1097e
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,17 @@
+# require-all
+
+An easy way to require all files within a directory.
+
+## Usage
+
+```js
+var controllers = require('require-all')({
+  dirname     :  __dirname + '/controllers',
+  filter      :  /(.+Controller)\.js$/,
+  excludeDirs :  /^\.(git|svn)$/
+});
+
+// controllers now is an object with references to all modules matching the filter
+// for example:
+// { HomeController: function HomeController() {...}, ...}
+```
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..4ddce31
--- /dev/null
+++ b/index.js
@@ -0,0 +1,33 @@
+var fs    = require('fs');
+
+module.exports = function requireAll(options) {
+  var files   = fs.readdirSync(options.dirname);
+  var modules = {};
+
+  function excludeDirectory(dirname) {
+    return options.excludeDirs && dirname.match(options.excludeDirs);
+  }
+
+  files.forEach(function(file) {
+    var filepath = options.dirname + '/' + file;
+    if (fs.statSync(filepath).isDirectory()) {
+
+      if (excludeDirectory(file)) return;
+
+      modules[file] = requireAll({
+        dirname     :  filepath,
+        filter      :  options.filter,
+        excludeDirs :  options.excludeDirs
+      });
+
+    } else {
+      var match = file.match(options.filter);
+      if (!match) return;
+
+      modules[match[1]] = require(filepath);
+    }
+  });
+
+  return modules;
+};
+
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..3cac64d
--- /dev/null
+++ b/package.json
@@ -0,0 +1,26 @@
+{
+  "author": "Felix Geisendörfer <felix at debuggable.com> (http://debuggable.com/)",
+  "name": "require-all",
+  "description": "An easy way to require all files within a directory.",
+  "version": "0.0.6",
+  "scripts": {
+    "test": "node test/test.js"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git://github.com/felixge/node-require-all.git"
+  },
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "https://github.com/felixge/node-require-all/blob/master/License"
+    }
+  ],
+  "main": "./index",
+  "engines": {
+    "node": "*"
+  },
+  "dependencies": {},
+  "devDependencies": {},
+  "optionalDependencies": {}
+}
diff --git a/test/controllers/main-Controller.js b/test/controllers/main-Controller.js
new file mode 100644
index 0000000..355ce40
--- /dev/null
+++ b/test/controllers/main-Controller.js
@@ -0,0 +1,4 @@
+exports.index = 1;
+exports.show  = 2;
+exports.add   = 3;
+exports.edit  = 4;
diff --git a/test/controllers/notthis.js b/test/controllers/notthis.js
new file mode 100644
index 0000000..8ac88c5
--- /dev/null
+++ b/test/controllers/notthis.js
@@ -0,0 +1 @@
+exports.yes = 'no';
diff --git a/test/controllers/other-Controller.js b/test/controllers/other-Controller.js
new file mode 100644
index 0000000..aec8f24
--- /dev/null
+++ b/test/controllers/other-Controller.js
@@ -0,0 +1,2 @@
+exports.index = 1;
+exports.show = 'nothing'
diff --git a/test/filterdir/.svn/stuff.js b/test/filterdir/.svn/stuff.js
new file mode 100644
index 0000000..2c61c58
--- /dev/null
+++ b/test/filterdir/.svn/stuff.js
@@ -0,0 +1 @@
+module.exports = { gute: 'nacht' };
diff --git a/test/filterdir/root.js b/test/filterdir/root.js
new file mode 100644
index 0000000..c9fd536
--- /dev/null
+++ b/test/filterdir/root.js
@@ -0,0 +1 @@
+module.exports = { guten: 'tag' };
diff --git a/test/filterdir/sub/hello.js b/test/filterdir/sub/hello.js
new file mode 100644
index 0000000..0174eea
--- /dev/null
+++ b/test/filterdir/sub/hello.js
@@ -0,0 +1 @@
+module.exports = { guten: 'abend' };
diff --git a/test/mydir/foo.js b/test/mydir/foo.js
new file mode 100644
index 0000000..cb1c2c0
--- /dev/null
+++ b/test/mydir/foo.js
@@ -0,0 +1 @@
+module.exports = 'bar';
diff --git a/test/mydir/hello.js b/test/mydir/hello.js
new file mode 100644
index 0000000..b1d17c1
--- /dev/null
+++ b/test/mydir/hello.js
@@ -0,0 +1,2 @@
+exports.world = true;
+exports.universe = 42;
diff --git a/test/mydir/sub/config.json b/test/mydir/sub/config.json
new file mode 100644
index 0000000..d2b5939
--- /dev/null
+++ b/test/mydir/sub/config.json
@@ -0,0 +1,4 @@
+{
+  "settingA": "A",
+  "settingB": "B"
+}
diff --git a/test/mydir/sub/no.2js b/test/mydir/sub/no.2js
new file mode 100644
index 0000000..ec01c2c
--- /dev/null
+++ b/test/mydir/sub/no.2js
@@ -0,0 +1 @@
+module.exports = true;
diff --git a/test/mydir/sub/yes.js b/test/mydir/sub/yes.js
new file mode 100644
index 0000000..ec01c2c
--- /dev/null
+++ b/test/mydir/sub/yes.js
@@ -0,0 +1 @@
+module.exports = true;
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..ea8457c
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,67 @@
+var assert = require('assert');
+var requireAll = require('..');
+
+var controllers = requireAll({
+  dirname: __dirname + '/controllers',
+  filter: /(.+Controller)\.js$/
+});
+
+assert.deepEqual(controllers, {
+  'main-Controller': {
+    index: 1,
+    show: 2,
+    add: 3,
+    edit: 4
+  },
+
+  'other-Controller': {
+    index: 1,
+    show: 'nothing'
+  }
+});
+
+
+if (process.version > 'v0.6.0') {
+  var mydir = requireAll({
+    dirname: __dirname + '/mydir',
+    filter: /(.+)\.(js|json)$/
+  });
+
+  assert.deepEqual(mydir, {
+    foo: 'bar',
+    hello: { world: true, universe: 42 },
+    sub: {
+      config: { settingA: 'A', settingB: 'B' },
+      yes: true
+    }
+  });
+}
+
+var unfiltered = requireAll({
+  dirname: __dirname + '/filterdir',
+  filter: /(.+)\.js$/
+});
+
+assert(unfiltered['.svn']);
+assert(unfiltered['root']);
+assert(unfiltered['sub']);
+
+var excludedSvn = requireAll({
+  dirname: __dirname + '/filterdir',
+  filter: /(.+)\.js$/,
+  excludeDirs: /^\.svn$/
+});
+
+assert.equal(excludedSvn['.svn'], undefined);
+assert.ok(excludedSvn['root']);
+assert.ok(excludedSvn['sub']);
+
+var excludedSvnAndSub = requireAll({
+  dirname: __dirname + '/filterdir',
+  filter: /(.+)\.js$/,
+  excludeDirs: /^(\.svn|sub)$/
+});
+
+assert.equal(excludedSvnAndSub['.svn'], undefined);
+assert.ok(excludedSvnAndSub['root']);
+assert.equal(excludedSvnAndSub['sub'], undefined);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-require-all.git



More information about the Pkg-javascript-commits mailing list