Skip to content

Commit

Permalink
Added support for deps with array on the first level. Closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rmat1k committed Mar 27, 2015
1 parent 88f8d36 commit f479d46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
18 changes: 15 additions & 3 deletions bemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,22 @@ function depsToObj(data){
}

function getNormalaizedDeps(data) {
var mustDeps = depsNormalize(data.mustDeps, { parseString: parseString }),
shouldDeps = depsNormalize(data.shouldDeps, { parseString: parseString });
var mustDeps, shouldDeps;

return mustDeps.concat(shouldDeps);
if (Array.isArray(data)) {
data.forEach(function(obj){
if (obj.mustDeps) mustDeps = obj.mustDeps;
if (obj.shouldDeps) shouldDeps = obj.shouldDeps;
});
} else {
mustDeps = data.mustDeps;
shouldDeps = data.shouldDeps;
}

var normalizedMustDeps = depsNormalize(mustDeps, { parseString: parseString }),
normalizedShouldDeps = depsNormalize(shouldDeps, { parseString: parseString });

return normalizedMustDeps.concat(normalizedShouldDeps);
}

function createFile(file, type, trg, modVal, cursorPos){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/f0rmat1k/bemy.git"
},
"version": "2.2.1",
"version": "2.2.2",
"keywords": [
"bem",
"BEM Tools"
Expand Down
17 changes: 12 additions & 5 deletions test/files-creating.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('Files creating', function(){
it ('Create task: should be correct blocks files creating', function(done){
[
'config.json',
'config_custon-separators.json'
].forEach(function(configName){
'config_custon-separators.json',
'config.json'
].forEach(function(configName, i){
var configPath = path.resolve('test', configName),
config = JSON.parse(fs.readFileSync(configPath, 'utf-8')),
separators = config.bem.separators;
Expand All @@ -27,7 +28,7 @@ describe('Files creating', function(){
fs.mkdirSync(blockDir);

var deps = getDeps(separators);
createDepsTpl(deps);
createDepsTpl(deps, i);

testCreatingTask(configPath);
testDepsCreationFiles(deps, configPath);
Expand Down Expand Up @@ -71,15 +72,21 @@ function testDepsCreationFiles(deps, configPath){
});
}

function createDepsTpl(deps){
function createDepsTpl(deps, i){
var shouldDeps = Object.keys(deps).map(function(key){
return deps[key];
});

var obj = JSON.stringify(shouldDeps);

var depsPath = path.resolve('test/', 'deps-template.js');
var depsFile = '({ shouldDeps: ' + obj + '})';
var depsFile;

if (i === 2) {
depsFile = '([ { tech: "js", shouldDeps: [ { block: "foo", tech: "bemhtml" } ] }, { shouldDeps: ' + obj + '} ]);';
} else {
depsFile = '({ shouldDeps: ' + obj + '})';
}

fs.writeFileSync(depsPath, depsFile);
}
Expand Down

0 comments on commit f479d46

Please sign in to comment.