Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
blond committed Apr 5, 2016
1 parent 0e7ad7a commit 6eadf5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 90 deletions.
25 changes: 18 additions & 7 deletions exlib/deps-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
var inherit = require('inherit');
var vowFs = require('enb/lib/fs/async-fs');
var vm = require('vm');
var stringifyEntity = require('bem-naming').stringify;
var Vow = require('vow');
var MustDeps = require('./must-deps');

Expand Down Expand Up @@ -243,20 +244,30 @@ module.exports.OldDeps = (function () {
var _this = this;
var tech = this.tech;

var files = tech.levels.getFilesByDecl(item.item.block, item.item.elem, item.item.mod, item.item.val)
.filter(function (file) {
return file.suffix === 'deps.js';
var dep = item.item;
var entity = { block: dep.block };

dep.elem && (entity.elem = dep.elem);
dep.mod && (entity.modName = dep.mod);
dep.val && (entity.modVal = dep.val);

var id = stringifyEntity(entity);
var files = (tech.levels[id] || [])
.filter(function (filename) {
var suffix = filename.split('.').slice(1).join('.');

return suffix === 'deps.js';
});

var promise = Vow.fulfill();

files.forEach(function (file) {
files.forEach(function (filename) {
promise = promise.then(function () {
return vowFs.read(file.fullname, 'utf8').then(function (content) {
return vowFs.read(filename, 'utf8').then(function (content) {
try {
_this.parse(vm.runInThisContext(content, file.fullname), item);
_this.parse(vm.runInThisContext(content, filename), item);
} catch (e) {
throw new Error('Syntax error in file "' + file.fullname + '": ' + e.message);
throw new Error('Syntax error in file "' + filename + '": ' + e.message);
}
});
});
Expand Down
76 changes: 7 additions & 69 deletions lib/deps/deps-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
* @returns {Array}
*/
normalizeDep: function (dep, blockName, elemName) {
var fileMap = this.introspection.fileMap;
if (typeof dep === 'string') {
return [{ name: dep }];
} else {
Expand Down Expand Up @@ -93,22 +92,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
}
Object.keys(modObj).forEach(function (modName) {
var modVals = modObj[modName];
if (modVals === '*') {
modVals = [];

var id = stringifyEntity({
block: dep.block || blockName,
modName: modName
});

fileMap[id];

Object.keys(fileMap).forEach(function (name) {
if (name.indexOf(id) === 0) {
modVals.push(fileMap[name]);
}
});
}
if (!Array.isArray(modVals)) {
modVals = [modVals];
}
Expand Down Expand Up @@ -191,12 +175,13 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
mustDecls,
files,
fileMap = this.introspection.fileMap,
id = stringifyEntity({
block: decl.name,
elem: decl.elem,
modName: decl.modName,
modVal: decl.modVal
});
entity = { block: decl.name };

decl.elem && (entity.elem = decl.elem);
decl.modName && (entity.modName = decl.modName);
decl.modVal && (entity.modVal = decl.modVal);

var id = stringifyEntity(entity);

files = (fileMap[id] || []).filter(function (filename) {
var suffix = filename.split('.').slice(1).join('.');
Expand Down Expand Up @@ -343,53 +328,6 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{
}
},

/**
* Adds block to resolver.
*
* @param {String} blockName
* @param {String} modName
* @param {String} modVal
* @returns {Promise}
*/
addBlock: function (blockName, modName, modVal) {
if (modName) {
this.addDecl({
name: blockName,
modName: modName,
modVal: modVal
});
} else {
this.addDecl({
name: blockName
});
}
},

/**
* Adds element to resolver.
*
* @param {String} blockName
* @param {String} elemName
* @param {String} modName
* @param {String} modVal
* @returns {Promise}
*/
addElem: function (blockName, elemName, modName, modVal) {
if (modName) {
return this.addDecl({
name: blockName,
elem: elemName,
modName: modName,
modVal: modVal
});
} else {
return this.addDecl({
name: blockName,
elem: elemName
});
}
},

/**
* Adds declaration to resolver.
*
Expand Down
12 changes: 6 additions & 6 deletions techs/deps-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ module.exports = inherit(BaseTech, {
strictMode = this._strict;

return node.requireSources([this._levelsTarget, this._declFile])
.spread(function (levels, sourceDeps) {
var depFiles = levels.getFilesBySuffix('deps.js');
.spread(function (introspection, sourceDeps) {
// var depFiles = levels.getFilesBySuffix('deps.js');

if (cache.needRebuildFile('deps-file', targetFilename) ||
cache.needRebuildFile('decl-file', declFilename) ||
cache.needRebuildFileList('deps-file-list', depFiles)
cache.needRebuildFile('decl-file', declFilename)
// cache.needRebuildFileList('deps-file-list', depFiles)
) {
return requireSourceDeps(sourceDeps, declFilename)
.then(function (sourceDeps) {
return (new OldDeps(sourceDeps, strictMode).expandByFS({ levels: levels }))
return (new OldDeps(sourceDeps, strictMode).expandByFS({ levels: introspection.fileMap }))
.then(function (resolvedDeps) {
var resultDeps = resolvedDeps.getDeps(),
loopPaths = resolvedDeps.getLoops().mustDeps.map(function (loop) {
Expand All @@ -120,7 +120,7 @@ module.exports = inherit(BaseTech, {
.then(function () {
cache.cacheFileInfo('deps-file', targetFilename);
cache.cacheFileInfo('decl-file', declFilename);
cache.cacheFileList('deps-file-list', depFiles);
// cache.cacheFileList('deps-file-list', depFiles);
node.resolveTarget(target, { deps: resultDeps });
});
});
Expand Down
13 changes: 7 additions & 6 deletions techs/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ module.exports = inherit(BaseTech, {
hash = {};

return vow.all(sourceDeps.map(function (dep) {
var id = stringifyEntity({
block: dep.block,
elem: dep.elem,
modName: dep.mod,
modVal: dep.val
});
var entity = { block: dep.block };

dep.elem && (entity.elem = dep.elem);
dep.mod && (entity.modName = dep.mod);
dep.val && (entity.modVal = dep.val);

var id = stringifyEntity(entity);

return vow.all((introspection.fileMap[id] || []).map(function (filename) {
return vfs.stat(filename).then(function (stats) {
Expand Down
3 changes: 1 addition & 2 deletions test/techs/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ describe('techs: files', function () {
return hasDirs(scheme, deps, dirs);
});

it.only('must get boolean mod & key-val mod by deps', function () {
it('must get boolean mod & key-val mod by deps', function () {
var scheme = {
blocks: {
block: {
Expand Down Expand Up @@ -706,7 +706,6 @@ function getEntityFiles(fsScheme, deps, filetype, levels) {
function has(fsScheme, deps, filenames, filetype, levels) {
return getEntityFiles(fsScheme, deps, filetype, levels)
.then(function (files) {
console.log(files);
files.items.must.have.length(filenames.length);

filenames.forEach(function (filename, i) {
Expand Down

0 comments on commit 6eadf5e

Please sign in to comment.