{"name":"include-all","version":"4.0.2","description":"An easy way to include all node.js modules within a directory.","main":"index.js","directories":{"test":"test"},"scripts":{"test":"node ./node_modules/mocha/bin/mocha"},"repository":{"type":"git","url":"git://github.com/mikermcneil/include-all.git"},"keywords":["include-all","include","require-all","require","directory"],"author":{"name":"felixge+thlorenz, adapted by Mike McNeil"},"license":"MIT","dependencies":{"merge-dictionaries":"^0.0.3","@sailshq/lodash":"^3.10.2"},"devDependencies":{"mocha":"3.0.2"},"gitHead":"b323d9413e49a597ee66ab0b380e08a290ce6376","bugs":{"url":"https://github.com/mikermcneil/include-all/issues"},"homepage":"https://github.com/mikermcneil/include-all#readme","_id":"include-all@4.0.2","_shasum":"85e53065b069bebe7549b73e4be83ba8214f3793","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.3.0","_npmUser":{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},"dist":{"shasum":"85e53065b069bebe7549b73e4be83ba8214f3793","tarball":"http://registry-npm.ywwl.com/include-all/download/include-all-4.0.2.tgz","integrity":"sha512-bFH/UFH3vkk1bT+lyEPFFmu0O+bxSnx76N+ocr8R4YLIlUvUQycyGnVnpl0uVqWy614TPbCt9ePK06pylumK+A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCSqJW9Z3r043TSHcyfB95ASk7UznWLMU0I6h1Wh36cLgIgN2yJ/bealgNxnAktISgtp09Uk4hB4bAf44i0AGo67Nw="}],"size":11289,"noattachment":false,"key":"/include-all/-/include-all-4.0.2.tgz"},"maintainers":[{"name":"balderdashy","email":"mike@balderdash.co"},{"name":"mikermcneil","email":"michael.r.mcneil@gmail.com"},{"name":"sgress454","email":"sgress454@treeline.io"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/include-all-4.0.2.tgz_1489691291361_0.6599361361004412"},"readme":"# include-all\n\nAn easy way to include all node.js modules within a directory.\n\n> This utility is [called by the moduleloader hook](https://github.com/balderdashy/sails/tree/v0.12.4/lib/hooks/moduleloader) in Sails.js.\n\n\n\n## Installation\n\n```\nnpm install include-all --save\n```\n\n\n## Low-level synchronous usage\n\nBy default, `include-all` is synchronous, and a bit low-level.  There are also asynchronous helper methods (which are a bit higher-level), but more on that in a sec.\n\nFirst, here are some examples of the low-level, synchronous usage:\n\n##### Filter by filename or path\n\n\n```js\nvar path = require('path');\nvar includeAll = require('include-all');\n\nvar controllers = require('include-all')({\n  dirname     :  path.join(__dirname, 'controllers'),\n  filter      :  /(.+Controller)\\.js$/,\n  excludeDirs :  /^\\.(git|svn)$/\n});\n\n```\n\n\n`controllers` is now a dictionary with references to all modules matching the filter.\nThe keys are the filenames (minus the extension).\n\nFor example:\n\n```javascript\n{\n  PageController: {\n    showHomepage: function (req, res) { /*...*/ },\n    /*...*/\n  },\n  /*...*/\n}\n```\n\n> Keep in mind that the case-sensitivity of file and directory names varies between operating systems (Linux/Windows/Mac).\n\n\n\n##### Optional include\n\nNormally, if an error is encountered when requiring/reading/listing files or directories, it is thrown.  To swallow that error silently, set `optional: true`:\n\n```javascript\nvar models = require('include-all')({\n  dirname     :  path.join(__dirname, 'models'),\n  filter      :  /(.+)\\.js$/,\n  excludeDirs :  /^\\.(git|svn)$/,\n  optional    :  true\n});\n\n```\n\n`models` is now a dictionary with references to all modules matching the filter.\nIf `__dirname + '/models'` doesn't exist, instead of throwing an error, `{}` is returned.\n\nFor example:\n\n```\n{\n  User: {\n    attributes: {},\n    datastore: 'localDiskDb',\n    /*...*/\n  },\n  /*...*/\n}\n```\n\n\n\n\n## High-level asynchronous usage\n\n> The logic from [sails-build-dictionary](https://github.com/sailsjs/sails-build-dictionary) was migrated here.\n\nWhen you run `require('include-all')`, you get a function.  Calling that function uses include-all with default settings (and any of the options from the table below may be passed in.)\n\nBut there are also a handful of convenience methods exposed as properties of that function.  For example:\n\n```javascript\nvar includeAll = require('include-all');\n\n// Could just call `includeAll()` for synchronous usage.\n//\n// But could also take advantage of ASYNCHRONOUS usage via:\n// • includeAll.optional();\n// • includeAll.exists();\n// • includeAll.aggregate();\n```\n\n\n#### Available convenience methods\n\n`include-all` exposes 3 different methods for asynchronous usage.\n\nThe following convenience methods take all the same options as the default `includeAll` function, but they also support a few _additional_ options.  Also, since they're asynchronous, they work a bit differently:  they use the conventional Node.js \"options,cb\" function signature.\n\n\n##### .optional()\n\nBuild a dictionary of named modules.\n(fails silently-- returns {} -- if the container cannot be loaded)\n\n> This is how most things in the `api/` folder of Sails apps are loaded (e.g. controllers, models, etc.)\n\n\n```javascript\nvar path = require('path');\nvar includeAll = require('include-all');\n\nincludeAll.optional({\n  dirname: path.resolve('api/controllers'),\n  filter: /(.+)Controller\\.js$/\n}, function (err, modules){\n  if (err) {\n    console.error('Failed to load controllers.  Details:',err);\n    return;\n  }\n\n  console.log(modules);\n\n  // =>\n  // (notice that `identity` and `globalId` are added automatically)\n  //\n  // ```\n  //  { page:\n  //   { showSignupPage: [Function],\n  //     showRestorePage: [Function],\n  //     showEditProfilePage: [Function],\n  //     showProfilePage: [Function],\n  //     showAdminPage: [Function],\n  //     showHomePage: [Function],\n  //     showVideosPage: [Function],\n  //     identity: 'page',\n  //     globalId: 'Page' },\n  //  user:\n  //   { login: [Function],\n  //     logout: [Function],\n  //     signup: [Function],\n  //     removeProfile: [Function],\n  //     restoreProfile: [Function],\n  //     restoreGravatarURL: [Function],\n  //     updateProfile: [Function],\n  //     changePassword: [Function],\n  //     adminUsers: [Function],\n  //     updateAdmin: [Function],\n  //     updateBanned: [Function],\n  //     updateDeleted: [Function],\n  //     identity: 'user',\n  //     globalId: 'User' },\n  //  video: { identity: 'video', globalId: 'Video' } }\n  // ```\n});\n```\n\n\n\n##### .exists()\n\nBuild a dictionary indicating whether the matched modules exist\n(fails silently-- returns {} if the container cannot be loaded)\n\n> This is how Sails detects the existence of views.\n\n\n##### .aggregate()\n\nBuild a single module dictionary by extending {} with the contents of each module.\n(fail silently-- returns {} if the container cannot be loaded)\n\n> This is how `sails.config` is built from config files.\n\nFor example:\n\n```javascript\nrequire('include-all').aggregate({\n  dirname: '/code/brushfire-ch10-end/config/',\n  filter: /(.+)\\.js$/,\n  depth: 1\n}, function (err, modules) {\n  if (err) { console.error('Error:', err); return; }\n\n  // =>\n  //  { blueprints: { actions: false, rest: false, shortcuts: false },\n  //    bootstrap: [Function],\n  //    connections:\n  //     { localDiskDb: { adapter: 'sails-disk' },\n  //       someMysqlServer:\n  //        { adapter: 'sails-mysql',\n  //          host: 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',\n  //          user: 'YOUR_MYSQL_USER',\n  //          password: 'YOUR_MYSQL_PASSWORD',\n  //          database: 'YOUR_MYSQL_DB' },\n  //       someMongodbServer: { adapter: 'sails-mongo', host: 'localhost', port: 27017 },\n  //       somePostgresqlServer:\n  //        { adapter: 'sails-postgresql',\n  //          host: 'YOUR_POSTGRES_SERVER_HOSTNAME_OR_IP_ADDRESS',\n  //          user: 'YOUR_POSTGRES_USER',\n  //          password: 'YOUR_POSTGRES_PASSWORD',\n  //          database: 'YOUR_POSTGRES_DB' },\n  //       myPostgresqlServer:\n  //        { adapter: 'sails-postgresql',\n  //          host: 'localhost',\n  //          user: 'jgalt',\n  //          password: 'blahblah',\n  //          database: 'brushfire' } },\n  //    cors: {},\n  //    globals: {},\n  //    http: {},\n  //    i18n: {},\n  //    log: {},\n  //    models: { connection: 'localDiskDb', schema: true, migrate: 'drop' },\n  //    policies:\n  //     { '*': true,\n  //       VideoController: { create: [Object] },\n  //       UserController:\n  //        { login: [Object],\n  //          logout: [Object],\n  //          removeProfile: [Object],\n  //          updateProfile: [Object],\n  //          restoreGravatarURL: [Object],\n  //          changePassword: [Object],\n  //          signup: [Object],\n  //          restoreProfile: [Object],\n  //          adminUsers: [Object],\n  //          updateAdmin: [Object],\n  //          updateBanned: [Object],\n  //          updateDeleted: [Object] },\n  //       PageController:\n  //        { showSignupPage: [Object],\n  //          showAdminPage: [Object],\n  //          showProfilePage: [Object],\n  //          showEditProfilePage: [Object],\n  //          showRestorePage: [Object] } },\n  //    routes:\n  //     { 'PUT /login': 'UserController.login',\n  //       'GET /logout': 'UserController.logout',\n  //       'GET /video': 'VideoController.find',\n  //       'POST /video': 'VideoController.create',\n  //       'POST /user/signup': 'UserController.signup',\n  //       'PUT /user/removeProfile': 'UserController.removeProfile',\n  //       'PUT /user/restoreProfile': 'UserController.restoreProfile',\n  //       'PUT /user/restoreGravatarURL': 'UserController.restoreGravatarURL',\n  //       'PUT /user/updateProfile': 'UserController.updateProfile',\n  //       'PUT /user/changePassword': 'UserController.changePassword',\n  //       'GET /user/adminUsers': 'UserController.adminUsers',\n  //       'PUT /user/updateAdmin/:id': 'UserController.updateAdmin',\n  //       'PUT /user/updateBanned/:id': 'UserController.updateBanned',\n  //       'PUT /user/updateDeleted/:id': 'UserController.updateDeleted',\n  //       'GET /': 'PageController.showHomePage',\n  //       'GET /videos': 'PageController.showVideosPage',\n  //       'GET /administration': 'PageController.showAdminPage',\n  //       'GET /profile': 'PageController.showProfilePage',\n  //       'GET /edit-profile': 'PageController.showEditProfilePage',\n  //       'GET /restore': 'PageController.showRestorePage',\n  //       'GET /signup': 'PageController.showSignupPage' },\n  //    session: { secret: 'blahblah' },\n  //    sockets: {},\n  //    views: { engine: 'ejs', layout: 'layout', partials: true } }\n});\n```\n\n\n\n## Options\n\n| Option      | Description\n|:------------|:------------------------------------------------------------------------|\n| dirname     | The absolute path of a directory to load modules from.\n| force       | When set, any past require cache entry will be cleared before re-requiring a module.\n| optional    | if enabled, continue silently and return {} when source directory does not exist or cannot be read.  Normally, this throws an error in that scenario.  default: false\n| ignoreRequireFailures    | if enabled, continue silently if a `require()` call throws.  _This should be used with care!  It completely swallows the require error!_  default: false.  This is useful for tolerating malformed node_modules (see https://github.com/balderdashy/include-all/pull/14)\n| excludeDirs | A regular expression used to EXCLUDE directories by name.\n| depth       | the maximum level of recursion where modules will be included. Defaults to infinity.\n| filter      | only include modules whose FILENAME matches this regex. default `undefined`\n| pathFilter  | only include modules whose FULL RELATIVE PATH matches this regex (relative from the entry point directory). default `undefined`\n| dontLoad    | if `dontLoad` is set to true, don't run the module w/ V8 or load it into memory-- instead, return a tree representing the directory structure (all extant file leaves are included as keys, with their value = `true`)\n| flatten     | if enabled, ALL modules appear as top-level keys in the dictionary-- even those from within nested directories.\n| keepDirectoryPath | Only relevant if `flatten` is `true`.  If enabled, this option causes include-all to include the relative paths in the key names (for nested modules from subdirectories path in the key names).\n\n\n## High-Level Options\n\n_The following options are only usable in the higher-level asynchronous methods like `optional()`:_\n\n| Option      | Description\n|:------------|:------------------------------------------------------------------------|\n| identity    | if disabled, (explicitly set to false) don't inject an identity into the module also don't try to use the bundled `identity` property in the module to determine the keyname in the result dictionary. default: true\n| useGlobalIdForKeyName |  if `useGlobalIdForKeyName` is set to true, don't lowercase the identity to get the keyname-- just use the globalId.\n| replaceExpr | in identity: use this regex to remove substrings like 'Controller' or 'Service' and replace them with the value of `replaceVal`\n| replaceVal  | see above. default value: '' |\n| aggregate   | if enabled, include-all will build the result dictionary by merging all of the target modules together.  Note: Each module must export a dictionary in order for this to work (e.g. for building a configuration dictionary from a set of config files).\n\n\n\n## History\n\nBack in 2012, this was originally forked from felixge's awesome module, `require-all` (https://github.com/felixge/node-require-all).\n\nIt adds a few extra capabilities on top:\n- the ability to `include-all` a directory as **optional**.\n- the ability to recursively stat a directory, instead of actually requiring the modules (via the `dontLoad` option)\n- the ability to filter by path, not just filename (pathFilter)\n\nSince then, it has evolved quite a bit, but the base implementation is still the same.\n\n\n## Help\n\nFirst, please read through the documentation above.  If you have further questions or are having trouble, click [here](http://sailsjs.com/support).\n\n\n## Bugs &nbsp; [![NPM version](https://badge.fury.io/js/include-all.svg)](http://npmjs.com/package/include-all)\n\nTo report a bug, [click here](http://sailsjs.com/bugs).\n\n\n## Contributing\n\nPlease observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests.\n\n[![NPM](https://nodei.co/npm/include-all.png?downloads=true)](http://npmjs.com/package/include-all)\n\n\n## License\n\nMIT\n\nCopyright &copy; 2011 [Felix Geisendörfer](http://github.com/felixge)\nCopyright &copy; 2012 [Mike McNeil](http://github.com/mikermcneil)\n\n_A core module in the Sails framework since 2012._\n\nThe [Sails framework](http://sailsjs.com) is free and open-source under the [MIT License](http://sailsjs.com/license).\n\n","publish_time":1489691292066,"_cnpm_publish_time":1489691292066,"dist-tags":{"latest":"4.0.3"}}