Skip to content

Commit

Permalink
choose .tmp subfolder based on environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mislam committed Sep 19, 2015
1 parent d074587 commit 314c560
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/olive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ exports.getOptions = function() {

try {
userOptions = JSON.parse(fs.readFileSync(path.join(process.cwd(), '.oliverc')));
} catch(err) {
} catch (err) {
// Do nothing
}

// merge default options (default.oliverc) and user provided options (.oliverc)
_.merge(options, userOptions);

// choose .tmp subfolder based on environment variable
if (process.env.NODE_ENV === 'development') {
options.paths.tmp += '/serve';
} else {
options.paths.tmp += '/build';
}

return options;
};
23 changes: 22 additions & 1 deletion test/olive/olive.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('require(olive)', function() {
if (fs.existsSync(sandboxDir)) {
fs.removeSync(sandboxDir);
}

fs.mkdirSync(sandboxDir); // create sandbox directory
process.chdir(sandboxDir); // cd into sandbox directory

Expand Down Expand Up @@ -53,10 +54,30 @@ describe('require(olive)', function() {
var paths = options.paths;

expect(paths).to.have.a.property('src', 'src');
expect(paths).to.have.a.property('tmp', '.tmp');
expect(paths).to.have.a.property('tmp', '.tmp/build');
expect(paths).to.have.a.property('dist', 'new-dist');
});

});

describe('when NODE_ENV=development', function() {

var defaultEnv;

beforeEach(function() {
defaultEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
});

afterEach(function() {
process.env.NODE_ENV = defaultEnv; // restore original NODE_ENV
});

it('getOptions().paths.tmp changes the value to `.tmp/serve`', function() {
var paths = olive.getOptions().paths;
expect(paths).to.have.a.property('tmp', '.tmp/serve');
});

});

});

0 comments on commit 314c560

Please sign in to comment.