Skip to content

Commit

Permalink
added the capability of register the full location of config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ByIvo committed Feb 1, 2018
1 parent 1ef7f66 commit 26e53d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/configfile_finder/configfile-finder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('Configfile finder', function () {
name: 'Project-child-one-grandchild',
path: 'a',
branches: [],
dir: path.join(fakeGranchildPath, configFilename),
root: true
});
});
Expand All @@ -92,22 +93,26 @@ describe('Configfile finder', function () {
name: 'Project',
root: true,
custom: 'property',
dir: path.join(fakeRealConfigfilePath, configFilename),
branches: [
{
name: 'Project-child-one',
root: false,
dir: path.join(fakeFirstChildPath, configFilename),
branches: [
{
name: 'Project-child-one-grandchild',
path: 'a',
branches: [],
root: false
root: false,
dir: path.join(fakeGranchildPath, configFilename),
}
]
}, {
name: 'Project-child-two',
root: false,
path: 'a',
dir: path.join(fakeSecondChildPath, configFilename),
branches: []
}
]
Expand All @@ -120,14 +125,22 @@ describe('Configfile finder', function () {
expect(projectInfo).to.deep.equal({
name: 'Project-child-one',
root: true,
dir: path.join(fakeFirstChildPath, configFilename),
branches: [
{
name: 'Project-child-one-grandchild',
path: 'a',
branches: [],
root: false
root: false,
dir: path.join(fakeGranchildPath, configFilename),
}
]
});
});

it('Ensure the config file has the property dir, which one contains the full path of itself', function () {
var projectInfo = configfileFinder.from(fakeFirstChildPath, configFilename);

expect(projectInfo).to.have.property('dir', path.join(fakeFirstChildPath, configFilename));
});
});
4 changes: 2 additions & 2 deletions src/configfile_finder/configfile-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function readProjectInfoAndKeepSearching(dirPath, configFilename, isFirstCall) {

projectInfo.root = isFirstCall;
projectInfo.branches = readChildrenFrom(dirPath, configFilename);

projectInfo.dir = configfilePath;
return projectInfo;
} else {
return false;
Expand All @@ -38,7 +38,7 @@ function readChildrenFrom(dirPath, configFilename) {
var child = readProjectInfoAndKeepSearching(childPath, configFilename, false);

if(child) {
children.push(child);
children.push(child);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/configfile_finder/configfile-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function parseFileContent(path) {
var fileContent = fs.readFileSync(path, {encoding: 'UTF-8'});
return JSON.parse(fileContent);
}catch(err) {
console.error(err);
var message = 'The config file in path \'' + path + '\' needs to be a json file.';
throw Error(message);
}
Expand Down

0 comments on commit 26e53d8

Please sign in to comment.