From 26e53d80a03dd9820167233b5c5aa283cdba7dbf Mon Sep 17 00:00:00 2001 From: Ivo Batistela Date: Thu, 1 Feb 2018 00:11:40 -0200 Subject: [PATCH] added the capability of register the full location of config file --- src/configfile_finder/configfile-finder-test.js | 17 +++++++++++++++-- src/configfile_finder/configfile-finder.js | 4 ++-- src/configfile_finder/configfile-reader.js | 1 - 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/configfile_finder/configfile-finder-test.js b/src/configfile_finder/configfile-finder-test.js index dda4f9d..a08315e 100644 --- a/src/configfile_finder/configfile-finder-test.js +++ b/src/configfile_finder/configfile-finder-test.js @@ -74,6 +74,7 @@ describe('Configfile finder', function () { name: 'Project-child-one-grandchild', path: 'a', branches: [], + dir: path.join(fakeGranchildPath, configFilename), root: true }); }); @@ -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: [] } ] @@ -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)); + }); }); diff --git a/src/configfile_finder/configfile-finder.js b/src/configfile_finder/configfile-finder.js index 971b464..3a60d68 100644 --- a/src/configfile_finder/configfile-finder.js +++ b/src/configfile_finder/configfile-finder.js @@ -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; @@ -38,7 +38,7 @@ function readChildrenFrom(dirPath, configFilename) { var child = readProjectInfoAndKeepSearching(childPath, configFilename, false); if(child) { - children.push(child); + children.push(child); } } diff --git a/src/configfile_finder/configfile-reader.js b/src/configfile_finder/configfile-reader.js index 8762930..e2d32b4 100644 --- a/src/configfile_finder/configfile-reader.js +++ b/src/configfile_finder/configfile-reader.js @@ -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); }