{"action":"created","comment":{"url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/comments/60012775","id":60012775,"diff_hunk":"@@ -1,95 +1,50 @@\n 'use strict';\n \n-const fs = require('fs');\n-const path = require('path');\n-const bemNaming = require('bem-naming');\n const Readable = require('stream').Readable;\n-const schemes = require('./schemes');\n-\n+const async = require('async');\n+\n+const walkers = require('./walkers');\n+\n+/**\n+ * Scans levels in file system.\n+ *\n+ * If file or directory is valid BEM entity then will be called `add` with info about this file.\n+ *\n+ * @param {string[]} levels                The paths to levels.\n+ * @param {object} options                 The options.\n+ * @param {object} options.levels          The level map. The key is path to level, the value is options for this level.\n+ * @param {object} options.defaults        The options for levels by default.\n+ * @param {object} options.defaults.naming Any options for `bem-naming`.\n+ * @param {string} options.defaults.scheme The name of level scheme. Available values: `flat` or `nested`.\n+ *\n+ * @returns {module:stream.Readable} stream with info about found files and directories.\n+ */\n module.exports = function (levels, options) {\n     options || (options = {});\n \n-    const output = new Readable({ objectMode: true });\n     const defaults = options.defaults || {};\n     const levelConfigs = options.levels || {};\n-    const defaultNaming = defaults.naming ? bemNaming(defaults.naming) : bemNaming;\n-    const defaultScheme = (typeof defaults.scheme === 'string' ? schemes[defaults.scheme] : defaults.scheme)\n-        || schemes.nested;\n-\n-    levels = levels.map(levelname => {\n-        let scheme, naming;\n-\n-        const config = levelConfigs[levelname];\n+    const defaultNaming = defaults.naming;\n+    const defaultWalker = (typeof defaults.scheme === 'string' ? walkers[defaults.scheme] : defaults.scheme)\n+        || walkers.nested;\n \n-        if (config) {\n-            scheme = config.scheme;\n-            naming = config.naming;\n-        }\n-\n-        return {\n-            path: levelname,\n-            walk: typeof scheme === 'string' ? schemes[scheme] : (scheme || defaultScheme),\n-            naming: naming ? bemNaming(naming) : defaultNaming\n-        };\n-    });\n-\n-    function add(obj) {\n-        output.push(obj);\n-    }\n+    const output = new Readable({ objectMode: true, read: () => {} });\n+    const add = (obj) => output.push(obj);\n \n     function scan(level, callback) {\n-        const levelname = level.path;\n-        const step = level.walk(levelname, level.naming);\n-\n-        walk(levelname, 1, null, callback);\n-\n-        function walk(dir, depth, data, callback) {\n-            fs.readdir(dir, (err, items) => {\n-                if (err) { return callback(err); }\n+        const config = levelConfigs[level];\n+        const scheme = config && config.scheme;\n+        const naming = config && config.naming || defaultNaming;\n+        const walk = typeof scheme === 'string' ? walkers[scheme] : (scheme || defaultWalker);\n \n-                let n = 0;\n-                let l = items.length;\n-\n-                if (l === 0) {\n-                    callback();\n-                } else {\n-                    for (let i = 0; i < l; ++i) {\n-                        const basename = items[i];\n-                        const filename = path.join(dir, basename);\n-\n-                        step({\n-                            basename: basename,\n-                            dirname: dir,\n-                            filename: filename,\n-                            depth: depth,\n-                            data: data\n-                        }, add, deepWalk, next);\n-                    }\n-                }\n-\n-                function deepWalk(dir, data) {\n-                    walk(dir, depth + 1, data, next);\n-                }\n-\n-                function next(err) {\n-                    err && callback(err);\n-\n-                    ++n === l && callback();\n-                }\n-            });\n-        }\n+        walk({ path: level, naming: naming }, add, callback);\n     }\n \n-    let n = levels.length;\n-\n-    output._read = function () {\n-        n || output.push(null);\n-\n-        levels.length && scan(levels.shift(), err => {\n-            err && output.emit('error', err);\n-            --n || output.push(null);\n-        });\n-    };\n+    async.each(levels, scan, err => {","path":"lib/index.js","position":122,"original_position":121,"commit_id":"030709f73561b5fc405a8f5997a6db5720619238","original_commit_id":"a83a9cc9af8db0ffec4a923af733f97c5f7a72c0","user":{"login":"zxqfox","id":677518,"avatar_url":"https://avatars.githubusercontent.com/u/677518?v=3","gravatar_id":"","url":"https://api.github.com/users/zxqfox","html_url":"https://github.com/zxqfox","followers_url":"https://api.github.com/users/zxqfox/followers","following_url":"https://api.github.com/users/zxqfox/following{/other_user}","gists_url":"https://api.github.com/users/zxqfox/gists{/gist_id}","starred_url":"https://api.github.com/users/zxqfox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zxqfox/subscriptions","organizations_url":"https://api.github.com/users/zxqfox/orgs","repos_url":"https://api.github.com/users/zxqfox/repos","events_url":"https://api.github.com/users/zxqfox/events{/privacy}","received_events_url":"https://api.github.com/users/zxqfox/received_events","type":"User","site_admin":false},"body":"окок, забей )\r\n","created_at":"2016-04-18T07:07:12Z","updated_at":"2016-04-18T07:07:12Z","html_url":"https://github.com/bem-sdk/bem-walk/pull/40#discussion_r60012775","pull_request_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/comments/60012775"},"html":{"href":"https://github.com/bem-sdk/bem-walk/pull/40#discussion_r60012775"},"pull_request":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40","id":66342216,"html_url":"https://github.com/bem-sdk/bem-walk/pull/40","diff_url":"https://github.com/bem-sdk/bem-walk/pull/40.diff","patch_url":"https://github.com/bem-sdk/bem-walk/pull/40.patch","issue_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/40","number":40,"state":"open","locked":false,"title":"Core Refactor","user":{"login":"blond","id":2225579,"avatar_url":"https://avatars.githubusercontent.com/u/2225579?v=3","gravatar_id":"","url":"https://api.github.com/users/blond","html_url":"https://github.com/blond","followers_url":"https://api.github.com/users/blond/followers","following_url":"https://api.github.com/users/blond/following{/other_user}","gists_url":"https://api.github.com/users/blond/gists{/gist_id}","starred_url":"https://api.github.com/users/blond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blond/subscriptions","organizations_url":"https://api.github.com/users/blond/orgs","repos_url":"https://api.github.com/users/blond/repos","events_url":"https://api.github.com/users/blond/events{/privacy}","received_events_url":"https://api.github.com/users/blond/received_events","type":"User","site_admin":false},"body":"Move scan logic to walkers:\r\n\r\n* The core should only run walkers with specified options and provide result:\r\n* Now walker is simple function with `info` object and `add` function to provide result.\r\n\r\n  ```js\r\n  function({ path: '/path/to/level', naming: 'two-dashes' }, add })\r\n  ```\r\n* Now walkers get naming options instead of `naming` instance.\r\n\r\n**Before:**\r\n\r\n```\r\n         flat level\r\nbem-walk x 12,090 ops/sec ±4.70% (72 runs sampled) mean 0.08 ms\r\n     enb x 9,829 ops/sec ±2.19% (81 runs sampled) mean 0.10 ms\r\n   scanl x 12,234 ops/sec ±2.59% (81 runs sampled) mean 0.08 ms\r\n\r\n         nested level\r\nbem-walk x 4,637 ops/sec ±2.05% (79 runs sampled) mean 0.22 ms\r\n     enb x 6,034 ops/sec ±1.82% (81 runs sampled) mean 0.17 ms\r\n   scanl x 4,500 ops/sec ±2.29% (76 runs sampled) mean 0.22 ms\r\n\r\n         bem-bl\r\nbem-walk x 207 ops/sec ±1.20% (79 runs sampled) mean 4.83 ms\r\n     enb x 147 ops/sec ±1.68% (76 runs sampled) mean 6.79 ms\r\n   scanl x 143 ops/sec ±1.90% (81 runs sampled) mean 7.00 ms\r\n\r\n         bem-components\r\nbem-walk x 132 ops/sec ±2.13% (76 runs sampled) mean 7.58 ms\r\n     enb x 86.25 ops/sec ±1.98% (79 runs sampled) mean 11.59 ms\r\n   scanl x 80.86 ops/sec ±3.02% (74 runs sampled) mean 12.37 ms\r\n```\r\n\r\n**After:**\r\n\r\n```\r\n         flat level\r\nbem-walk x 15,036 ops/sec ±2.00% (80 runs sampled) mean 0.07 ms\r\n     enb x 9,924 ops/sec ±1.48% (79 runs sampled) mean 0.10 ms\r\n   scanl x 12,583 ops/sec ±2.39% (79 runs sampled) mean 0.08 ms\r\n\r\n         nested level\r\nbem-walk x 3,670 ops/sec ±1.19% (79 runs sampled) mean 0.27 ms\r\n     enb x 6,336 ops/sec ±1.38% (81 runs sampled) mean 0.16 ms\r\n   scanl x 4,582 ops/sec ±2.83% (73 runs sampled) mean 0.22 ms\r\n\r\n         bem-bl\r\nbem-walk x 211 ops/sec ±2.31% (80 runs sampled) mean 4.74 ms\r\n     enb x 149 ops/sec ±1.91% (75 runs sampled) mean 6.73 ms\r\n   scanl x 122 ops/sec ±4.24% (69 runs sampled) mean 8.16 ms\r\n\r\n         bem-components\r\nbem-walk x 129 ops/sec ±2.74% (74 runs sampled) mean 7.72 ms\r\n     enb x 77.95 ops/sec ±3.25% (73 runs sampled) mean 12.83 ms\r\n   scanl x 77.12 ops/sec ±3.35% (72 runs sampled) mean 12.97 ms\r\n```","created_at":"2016-04-13T15:33:05Z","updated_at":"2016-04-18T07:07:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ca541f484f041b052a7e4dc2cd75375de5ce9dd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40/commits","review_comments_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40/comments","review_comment_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/40/comments","statuses_url":"https://api.github.com/repos/bem-sdk/bem-walk/statuses/030709f73561b5fc405a8f5997a6db5720619238","head":{"label":"bem-sdk:refactor","ref":"refactor","sha":"030709f73561b5fc405a8f5997a6db5720619238","user":{"login":"bem-sdk","id":18242231,"avatar_url":"https://avatars.githubusercontent.com/u/18242231?v=3","gravatar_id":"","url":"https://api.github.com/users/bem-sdk","html_url":"https://github.com/bem-sdk","followers_url":"https://api.github.com/users/bem-sdk/followers","following_url":"https://api.github.com/users/bem-sdk/following{/other_user}","gists_url":"https://api.github.com/users/bem-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/bem-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bem-sdk/subscriptions","organizations_url":"https://api.github.com/users/bem-sdk/orgs","repos_url":"https://api.github.com/users/bem-sdk/repos","events_url":"https://api.github.com/users/bem-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/bem-sdk/received_events","type":"Organization","site_admin":false},"repo":{"id":26680552,"name":"bem-walk","full_name":"bem-sdk/bem-walk","owner":{"login":"bem-sdk","id":18242231,"avatar_url":"https://avatars.githubusercontent.com/u/18242231?v=3","gravatar_id":"","url":"https://api.github.com/users/bem-sdk","html_url":"https://github.com/bem-sdk","followers_url":"https://api.github.com/users/bem-sdk/followers","following_url":"https://api.github.com/users/bem-sdk/following{/other_user}","gists_url":"https://api.github.com/users/bem-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/bem-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bem-sdk/subscriptions","organizations_url":"https://api.github.com/users/bem-sdk/orgs","repos_url":"https://api.github.com/users/bem-sdk/repos","events_url":"https://api.github.com/users/bem-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/bem-sdk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bem-sdk/bem-walk","description":"","fork":false,"url":"https://api.github.com/repos/bem-sdk/bem-walk","forks_url":"https://api.github.com/repos/bem-sdk/bem-walk/forks","keys_url":"https://api.github.com/repos/bem-sdk/bem-walk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bem-sdk/bem-walk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bem-sdk/bem-walk/teams","hooks_url":"https://api.github.com/repos/bem-sdk/bem-walk/hooks","issue_events_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/events{/number}","events_url":"https://api.github.com/repos/bem-sdk/bem-walk/events","assignees_url":"https://api.github.com/repos/bem-sdk/bem-walk/assignees{/user}","branches_url":"https://api.github.com/repos/bem-sdk/bem-walk/branches{/branch}","tags_url":"https://api.github.com/repos/bem-sdk/bem-walk/tags","blobs_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/refs{/sha}","trees_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bem-sdk/bem-walk/statuses/{sha}","languages_url":"https://api.github.com/repos/bem-sdk/bem-walk/languages","stargazers_url":"https://api.github.com/repos/bem-sdk/bem-walk/stargazers","contributors_url":"https://api.github.com/repos/bem-sdk/bem-walk/contributors","subscribers_url":"https://api.github.com/repos/bem-sdk/bem-walk/subscribers","subscription_url":"https://api.github.com/repos/bem-sdk/bem-walk/subscription","commits_url":"https://api.github.com/repos/bem-sdk/bem-walk/commits{/sha}","git_commits_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/commits{/sha}","comments_url":"https://api.github.com/repos/bem-sdk/bem-walk/comments{/number}","issue_comment_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/comments{/number}","contents_url":"https://api.github.com/repos/bem-sdk/bem-walk/contents/{+path}","compare_url":"https://api.github.com/repos/bem-sdk/bem-walk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bem-sdk/bem-walk/merges","archive_url":"https://api.github.com/repos/bem-sdk/bem-walk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bem-sdk/bem-walk/downloads","issues_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues{/number}","pulls_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls{/number}","milestones_url":"https://api.github.com/repos/bem-sdk/bem-walk/milestones{/number}","notifications_url":"https://api.github.com/repos/bem-sdk/bem-walk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bem-sdk/bem-walk/labels{/name}","releases_url":"https://api.github.com/repos/bem-sdk/bem-walk/releases{/id}","deployments_url":"https://api.github.com/repos/bem-sdk/bem-walk/deployments","created_at":"2014-11-15T13:24:13Z","updated_at":"2016-04-03T13:12:07Z","pushed_at":"2016-04-16T18:19:34Z","git_url":"git://github.com/bem-sdk/bem-walk.git","ssh_url":"git@github.com:bem-sdk/bem-walk.git","clone_url":"https://github.com/bem-sdk/bem-walk.git","svn_url":"https://github.com/bem-sdk/bem-walk","homepage":null,"size":133,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":14,"forks":6,"open_issues":14,"watchers":13,"default_branch":"master"}},"base":{"label":"bem-sdk:master","ref":"master","sha":"9969c6822f79aac440f88da8ca39812940307023","user":{"login":"bem-sdk","id":18242231,"avatar_url":"https://avatars.githubusercontent.com/u/18242231?v=3","gravatar_id":"","url":"https://api.github.com/users/bem-sdk","html_url":"https://github.com/bem-sdk","followers_url":"https://api.github.com/users/bem-sdk/followers","following_url":"https://api.github.com/users/bem-sdk/following{/other_user}","gists_url":"https://api.github.com/users/bem-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/bem-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bem-sdk/subscriptions","organizations_url":"https://api.github.com/users/bem-sdk/orgs","repos_url":"https://api.github.com/users/bem-sdk/repos","events_url":"https://api.github.com/users/bem-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/bem-sdk/received_events","type":"Organization","site_admin":false},"repo":{"id":26680552,"name":"bem-walk","full_name":"bem-sdk/bem-walk","owner":{"login":"bem-sdk","id":18242231,"avatar_url":"https://avatars.githubusercontent.com/u/18242231?v=3","gravatar_id":"","url":"https://api.github.com/users/bem-sdk","html_url":"https://github.com/bem-sdk","followers_url":"https://api.github.com/users/bem-sdk/followers","following_url":"https://api.github.com/users/bem-sdk/following{/other_user}","gists_url":"https://api.github.com/users/bem-sdk/gists{/gist_id}","starred_url":"https://api.github.com/users/bem-sdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bem-sdk/subscriptions","organizations_url":"https://api.github.com/users/bem-sdk/orgs","repos_url":"https://api.github.com/users/bem-sdk/repos","events_url":"https://api.github.com/users/bem-sdk/events{/privacy}","received_events_url":"https://api.github.com/users/bem-sdk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bem-sdk/bem-walk","description":"","fork":false,"url":"https://api.github.com/repos/bem-sdk/bem-walk","forks_url":"https://api.github.com/repos/bem-sdk/bem-walk/forks","keys_url":"https://api.github.com/repos/bem-sdk/bem-walk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bem-sdk/bem-walk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bem-sdk/bem-walk/teams","hooks_url":"https://api.github.com/repos/bem-sdk/bem-walk/hooks","issue_events_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/events{/number}","events_url":"https://api.github.com/repos/bem-sdk/bem-walk/events","assignees_url":"https://api.github.com/repos/bem-sdk/bem-walk/assignees{/user}","branches_url":"https://api.github.com/repos/bem-sdk/bem-walk/branches{/branch}","tags_url":"https://api.github.com/repos/bem-sdk/bem-walk/tags","blobs_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/refs{/sha}","trees_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bem-sdk/bem-walk/statuses/{sha}","languages_url":"https://api.github.com/repos/bem-sdk/bem-walk/languages","stargazers_url":"https://api.github.com/repos/bem-sdk/bem-walk/stargazers","contributors_url":"https://api.github.com/repos/bem-sdk/bem-walk/contributors","subscribers_url":"https://api.github.com/repos/bem-sdk/bem-walk/subscribers","subscription_url":"https://api.github.com/repos/bem-sdk/bem-walk/subscription","commits_url":"https://api.github.com/repos/bem-sdk/bem-walk/commits{/sha}","git_commits_url":"https://api.github.com/repos/bem-sdk/bem-walk/git/commits{/sha}","comments_url":"https://api.github.com/repos/bem-sdk/bem-walk/comments{/number}","issue_comment_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues/comments{/number}","contents_url":"https://api.github.com/repos/bem-sdk/bem-walk/contents/{+path}","compare_url":"https://api.github.com/repos/bem-sdk/bem-walk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bem-sdk/bem-walk/merges","archive_url":"https://api.github.com/repos/bem-sdk/bem-walk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bem-sdk/bem-walk/downloads","issues_url":"https://api.github.com/repos/bem-sdk/bem-walk/issues{/number}","pulls_url":"https://api.github.com/repos/bem-sdk/bem-walk/pulls{/number}","milestones_url":"https://api.github.com/repos/bem-sdk/bem-walk/milestones{/number}","notifications_url":"https://api.github.com/repos/bem-sdk/bem-walk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bem-sdk/bem-walk/labels{/name}","releases_url":"https://api.github.com/repos/bem-sdk/bem-walk/releases{/id}","deployments_url":"https://api.github.com/repos/bem-sdk/bem-walk/deployments","created_at":"2014-11-15T13:24:13Z","updated_at":"2016-04-03T13:12:07Z","pushed_at":"2016-04-16T18:19:34Z","git_url":"git://github.com/bem-sdk/bem-walk.git","ssh_url":"git@github.com:bem-sdk/bem-walk.git","clone_url":"https://github.com/bem-sdk/bem-walk.git","svn_url":"https://github.com/bem-sdk/bem-walk","homepage":null,"size":133,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":14,"forks":6,"open_issues":14,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40"},"html":{"href":"https://github.com/bem-sdk/bem-walk/pull/40"},"issue":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/issues/40"},"comments":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/bem-sdk/bem-walk/statuses/030709f73561b5fc405a8f5997a6db5720619238"}}}}