{"action":"created","issue":{"url":"https://api.github.com/repos/substack/brfs/issues/19","labels_url":"https://api.github.com/repos/substack/brfs/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/substack/brfs/issues/19/comments","events_url":"https://api.github.com/repos/substack/brfs/issues/19/events","html_url":"https://github.com/substack/brfs/issues/19","id":30867335,"number":19,"title":"support fs.readdir and fs.readdirSync","user":{"login":"yamadapc","id":3923654,"avatar_url":"https://avatars.githubusercontent.com/u/3923654?v=3","gravatar_id":"","url":"https://api.github.com/users/yamadapc","html_url":"https://github.com/yamadapc","followers_url":"https://api.github.com/users/yamadapc/followers","following_url":"https://api.github.com/users/yamadapc/following{/other_user}","gists_url":"https://api.github.com/users/yamadapc/gists{/gist_id}","starred_url":"https://api.github.com/users/yamadapc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yamadapc/subscriptions","organizations_url":"https://api.github.com/users/yamadapc/orgs","repos_url":"https://api.github.com/users/yamadapc/repos","events_url":"https://api.github.com/users/yamadapc/events{/privacy}","received_events_url":"https://api.github.com/users/yamadapc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-04-04T14:58:03Z","updated_at":"2015-04-21T13:59:52Z","closed_at":null,"body":"I think this is feasible, and I personally think this is really useful.\r\n\r\nIn node.js it's reasonably common for me to do things like:\r\n```javascript\r\n// controllers/index.js\r\n'use strict';\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n\r\nvar ROOT_PATH = __dirname;\r\n\r\nmodule.exports = function(path) {\r\n  var fnames = fs.readdirSync(ROOT_PATH);\r\n\r\n  var paths = fnames.map(function(fname) {\r\n    return path.join(ROOT_PATH, fname, '.js');\r\n  });\r\n\r\n  var modules = paths.map(function(path) {\r\n    return require(path);\r\n  });\r\n\r\n  return modules.map(function(module) {\r\n    // do something with the module\r\n    // i.e. if it's this is a mongoose schema bootstrapping utility, register the model.\r\n    //       if this is a express controller bootstrapping utility, parse its methods and register\r\n   //        matching routes.\r\n   //        etc.\r\n  });\r\n};\r\n```\r\n\r\nThis allows us to abstract whole parts of the code, later on - even treat them as completely separate modules:\r\n\r\n```javascript\r\n// app.js\r\nvar controllers = require('./controllers')\r\n\r\n// bootstrap the controllers\r\ncontrollers(/* something would come here such as an express app or a mongoose.Connection */);\r\n```\r\n\r\nIf we could do this with browserify, things like bootstrapping an Ember app, could be automated. I know there are a couple of problems.\r\n\r\n[Here's an analogous example that works](https://gist.github.com/yamadapc/9976164), though not exactly as one would hope it'd.\r\n\r\nI know this has to do with limitations on the browserify module (which may be impossible to address) but this would be **really** cool.\r\n\r\nPerhaps we could even parse things like:\r\n```javascript\r\n['./a', './b'].map(function(name) {\r\n  return require(name);\r\n});\r\n```\r\n\r\nInto:\r\n```javascript\r\n[require('./a'), require('./b')];\r\n```\r\n\r\nOr provide an utility `requireMap` thing that resolved into that.\r\n\r\nI don't know if this is a relevant issue. But I though this would be a nice thing, if it was possible. \r\n\r\nAt it's core, the main point was simply to add:\r\n```javascript\r\nvar fs = require('fs');\r\nvar files = fs.readdirSync('.');\r\n```\r\n\r\nTo be transformed into:\r\n```javascript\r\nvar fs = require('fs');\r\nvar files = ['a.js', 'b.js', 'main.js' /* etc. */];\r\n```\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/substack/brfs/issues/comments/94803762","html_url":"https://github.com/substack/brfs/issues/19#issuecomment-94803762","issue_url":"https://api.github.com/repos/substack/brfs/issues/19","id":94803762,"user":{"login":"callumlocke","id":250617,"avatar_url":"https://avatars.githubusercontent.com/u/250617?v=3","gravatar_id":"","url":"https://api.github.com/users/callumlocke","html_url":"https://github.com/callumlocke","followers_url":"https://api.github.com/users/callumlocke/followers","following_url":"https://api.github.com/users/callumlocke/following{/other_user}","gists_url":"https://api.github.com/users/callumlocke/gists{/gist_id}","starred_url":"https://api.github.com/users/callumlocke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/callumlocke/subscriptions","organizations_url":"https://api.github.com/users/callumlocke/orgs","repos_url":"https://api.github.com/users/callumlocke/repos","events_url":"https://api.github.com/users/callumlocke/events{/privacy}","received_events_url":"https://api.github.com/users/callumlocke/received_events","type":"User","site_admin":false},"created_at":"2015-04-21T13:59:52Z","updated_at":"2015-04-21T13:59:52Z","body":"it would be cool if there was some way this could work:\r\n\r\n```js\r\nvar fs = require('fs');\r\n\r\nvar templates = {};\r\n\r\nfs.readdirSync(__dirname + '/../templates').forEach(function (filename) {\r\n  templates[filename] = fs.readFileSync(__dirname + '/../templates/' + filename, 'utf-8');\r\n});\r\n```"}}