Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use synchronous filterExists

  • Loading branch information...
commit 671e1b097fafc0ad85798d1d8d89b9e58824196b 1 parent b236220
@veged veged authored
Showing with 28 additions and 29 deletions.
  1. +19 −29 lib/tech.js
  2. +9 −0 lib/util.js
View
48 lib/tech.js
@@ -41,24 +41,21 @@ exports.Tech = function (path) {
}
};
-exports.Tech.prototype.bemBuild = function (prefixes, outputDir, outputName, callback) {
+exports.Tech.prototype.bemBuild = function (prefixes, outputDir, outputName) {
var _this = this,
- content = '';
- this.filterExists(prefixes, function(filtered){
- filtered.map(function (file) {
- return myPath.relative(outputDir, file);
- })
- .forEach(function (file) {
- content += _this.outFile(file);
- });
-
- fs.createWriteStream(
- myPath.join(outputDir, outputName + '.' + _this.getTechName()),
- { encoding: 'utf8' })
- .write(content);
-
- callback && callback();
- });
+ content = this.filterExists(prefixes)
+ .map(function (file) {
+ return myPath.relative(outputDir, file);
+ })
+ .map(function (file) {
+ return _this.outFile(file);
+ });
+
+ fs.createWriteStream(
+ myPath.join(outputDir, outputName + '.' + _this.getTechName()),
+ { encoding: 'utf8' })
+ .write(content.join(''));
+
return this;
};
@@ -74,21 +71,14 @@ exports.Tech.prototype.bemCreate = function (prefix, vars) {
return this;
};
-exports.Tech.prototype.filterExists = function (prefixes, callback) {
+exports.Tech.prototype.filterExists = function (prefixes) {
var _this = this,
- res = [],
- keys = {};
-
- prefixes.forEach(function (p) { keys[p] = true });
-
- prefixes.forEach(function (prefix) {
+ res = [];
+ prefixes.forEach(function(prefix){
var file = _this.fileByPrefix(prefix);
- myPath.exists(file, function(exists){
- delete keys[prefix];
- exists && res.push(file);
- bemUtil.isEmptyObject(keys) && callback(res);
- });
+ bemUtil.isFile(file) && res.push(file);
});
+ return res;
};
exports.Tech.prototype.fileByPrefix = function (prefix) {
View
9 lib/util.js
@@ -57,6 +57,15 @@ exports.mkdir = function(path) {
try { fs.mkdirSync(path, 0777) } catch(ignore) {}
};
+exports.isFile = function(path) {
+ var res = false;
+ try {
+ var stat = fs.statSync(path)
+ res = stat && stat.isFile();
+ } catch(ignore) {}
+ return res;
+};
+
exports.isDirectory = function(path) {
var res = false;
try {
Please sign in to comment.
Something went wrong with that request. Please try again.