This repository has been archived by the owner on Feb 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
526 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,3 @@ globals: | |
bench: false | ||
|
||
extends: pedant | ||
|
||
rules: | ||
no-shadow: off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
benchmarks | ||
========== | ||
|
||
**2015-07-03** Latest results, using `Node.js@0.12` and latest versions of modules: | ||
**2015-07-03** Latest results, using `Node.js@4` and latest versions of modules: | ||
|
||
* `enb@0.15.0` | ||
* `scan-level@0.0.4` | ||
|
||
``` | ||
bem-walk | ||
13,913 op/s » `flat` level | ||
4,860 op/s » `nested` level | ||
223 op/s » `bem-bl` | ||
152 op/s » `bem-core` + `bem-components` | ||
14,232 op/s » `flat` level | ||
3,948 op/s » `nested` level | ||
238 op/s » `bem-bl` | ||
153 op/s » `bem-core` + `bem-components` | ||
enb@0.x | ||
8,894 op/s » `flat` level | ||
5,829 op/s » `nested` level | ||
150 op/s » `bem-bl` | ||
86 op/s » `bem-core` + `bem-components` | ||
scan-level | ||
11,317 op/s » `flat` level | ||
4,909 op/s » `nested` level | ||
140 op/s » `bem-bl` | ||
84 op/s » `bem-core` + `bem-components` | ||
enb@0.x | ||
9,879 op/s » `flat` level | ||
6,567 op/s » `nested` level | ||
146 op/s » `bem-bl` | ||
87 op/s » `bem-core` + `bem-components` | ||
scan-level | ||
11,055 op/s » `flat` level | ||
4,528 op/s » `nested` level | ||
139 op/s » `bem-bl` | ||
79 op/s » `bem-core` + `bem-components` | ||
Suites: 3 | ||
Benches: 12 | ||
Elapsed: 17,992.13 ms | ||
Elapsed: 19,547.69 ms | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,50 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const bemNaming = require('bem-naming'); | ||
const Readable = require('stream').Readable; | ||
const schemes = require('./schemes'); | ||
|
||
const async = require('async'); | ||
|
||
const walkers = require('./walkers'); | ||
|
||
/** | ||
* Scans levels in file system. | ||
* | ||
* If file or directory is valid BEM entity then will be called `add` with info about this file. | ||
* | ||
* @param {string[]} levels The paths to levels. | ||
* @param {object} options The options. | ||
* @param {object} options.levels The level map. The key is path to level, the value is options for this level. | ||
* @param {object} options.defaults The options for levels by default. | ||
* @param {object} options.defaults.naming Any options for `bem-naming`. | ||
* @param {string} options.defaults.scheme The name of level scheme. Available values: `flat` or `nested`. | ||
* | ||
* @returns {module:stream.Readable} stream with info about found files and directories. | ||
*/ | ||
module.exports = function (levels, options) { | ||
options || (options = {}); | ||
|
||
const output = new Readable({ objectMode: true }); | ||
const defaults = options.defaults || {}; | ||
const levelConfigs = options.levels || {}; | ||
const defaultNaming = defaults.naming ? bemNaming(defaults.naming) : bemNaming; | ||
const defaultScheme = (typeof defaults.scheme === 'string' ? schemes[defaults.scheme] : defaults.scheme) | ||
|| schemes.nested; | ||
|
||
levels = levels.map(levelname => { | ||
let scheme, naming; | ||
|
||
const config = levelConfigs[levelname]; | ||
const defaultNaming = defaults.naming; | ||
const defaultWalker = (typeof defaults.scheme === 'string' ? walkers[defaults.scheme] : defaults.scheme) | ||
|| walkers.nested; | ||
|
||
if (config) { | ||
scheme = config.scheme; | ||
naming = config.naming; | ||
} | ||
|
||
return { | ||
path: levelname, | ||
walk: typeof scheme === 'string' ? schemes[scheme] : (scheme || defaultScheme), | ||
naming: naming ? bemNaming(naming) : defaultNaming | ||
}; | ||
}); | ||
|
||
function add(obj) { | ||
output.push(obj); | ||
} | ||
const output = new Readable({ objectMode: true, read: () => {} }); | ||
const add = (obj) => output.push(obj); | ||
|
||
function scan(level, callback) { | ||
const levelname = level.path; | ||
const step = level.walk(levelname, level.naming); | ||
|
||
walk(levelname, 1, null, callback); | ||
|
||
function walk(dir, depth, data, callback) { | ||
fs.readdir(dir, (err, items) => { | ||
if (err) { return callback(err); } | ||
const config = levelConfigs[level]; | ||
const scheme = config && config.scheme; | ||
const naming = config && config.naming || defaultNaming; | ||
const walk = typeof scheme === 'string' ? walkers[scheme] : (scheme || defaultWalker); | ||
|
||
let n = 0; | ||
let l = items.length; | ||
|
||
if (l === 0) { | ||
callback(); | ||
} else { | ||
for (let i = 0; i < l; ++i) { | ||
const basename = items[i]; | ||
const filename = path.join(dir, basename); | ||
|
||
step({ | ||
basename: basename, | ||
dirname: dir, | ||
filename: filename, | ||
depth: depth, | ||
data: data | ||
}, add, deepWalk, next); | ||
} | ||
} | ||
|
||
function deepWalk(dir, data) { | ||
walk(dir, depth + 1, data, next); | ||
} | ||
|
||
function next(err) { | ||
err && callback(err); | ||
|
||
++n === l && callback(); | ||
} | ||
}); | ||
} | ||
walk({ path: level, naming: naming }, add, callback); | ||
} | ||
|
||
let n = levels.length; | ||
|
||
output._read = function () { | ||
n || output.push(null); | ||
|
||
levels.length && scan(levels.shift(), err => { | ||
err && output.emit('error', err); | ||
--n || output.push(null); | ||
}); | ||
}; | ||
async.each(levels, scan, err => { | ||
err | ||
? output.emit('error', err) | ||
: output.push(null); | ||
}); | ||
|
||
return output; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const bemNaming = require('bem-naming'); | ||
|
||
/** | ||
* Plugin to scan flat levels. | ||
* | ||
* @param {object} info The info about scaned level. | ||
* @param {string} info.path The level path to scan. | ||
* @param {object|string} info.naming The naming options. | ||
* @param {function} add The function to provide info about found files. | ||
* @param {function} callback The callback function. | ||
*/ | ||
module.exports = function (info, add, callback) { | ||
const levelpath = info.path; | ||
// Create `bem-naming` instance for specified options. | ||
const parseEntityName = bemNaming(info.naming).parse; | ||
|
||
fs.readdir(levelpath, (err, files) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
files.forEach(basename => { | ||
const splited = basename.split('.'); | ||
|
||
// has tech | ||
if (splited.length > 1) { | ||
const entity = parseEntityName(splited.shift()); | ||
|
||
if (entity) { | ||
add({ | ||
path: path.join(levelpath, basename), | ||
entity: entity, | ||
tech: splited.join('.'), | ||
level: levelpath | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
callback(); | ||
}); | ||
}; |
File renamed without changes.
Oops, something went wrong.