Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Changed require configuration to path relative to current working dir…
Browse files Browse the repository at this point in the history
…ectory

For example working directory is `/home/foo/project_with_gemini/gemini/`.
We use js or json default path configuration or use `-c` option.
Run `./gemini` or `./gemini -c .very_special_configuration.json`.
And we get configuration relative to current working directory:
/home/foo/project_with_gemini/gemini/.gemini.conf.json
/home/foo/project_with_gemini/gemini/.gemini.conf.js
/home/foo/project_with_gemini/gemini/.very_special_configuration.json
not in directory anywhere in the node_modules.
Fixed #418.
  • Loading branch information
Alexandr Ishchenko committed Apr 12, 2016
1 parent d11c52c commit 9879fe3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ function getDefaultConfig() {

function requireModule(file) {
try {
return require(file);
if(file.indexOf('./') === 0 || file.indexOf('/') !== 0) {
return require(process.cwd() + '/' + file);
} else {
return require(file);
}

} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new GeminiError('Config file does not exist: ' + file);
Expand Down
20 changes: 20 additions & 0 deletions test/functional/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ describe('config', function() {
return new Config(configPath('notExists.js'));
}, GeminiError);
});

it('should read relative to current working directory', function() {
assert.deepPropertyVal(
new Config(configPath('validConfig.js').replace(process.cwd() + '/', '')),
'system.projectRoot', '/it/works');

assert.deepPropertyVal(
new Config(configPath('validConfig.js').replace(process.cwd() + '/', './')),
'system.projectRoot', '/it/works');
});
});

describe('.json', function() {
Expand All @@ -64,6 +74,16 @@ describe('config', function() {
return new Config(configPath('notExists.json'));
}, GeminiError);
});

it('should read relative to current working directory', function() {
assert.deepPropertyVal(
new Config(configPath('validConfig.json').replace(process.cwd() + '/', '')),
'system.projectRoot', '/it/works');

assert.deepPropertyVal(
new Config(configPath('validConfig.json').replace(process.cwd() + '/', './')),
'system.projectRoot', '/it/works');
});
});
});
});

0 comments on commit 9879fe3

Please sign in to comment.