Skip to content

Commit

Permalink
fix(cli): require file with absolute path
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
stevemao committed Sep 4, 2015
1 parent 831c960 commit 7f68b3e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fs = require('fs');
var meow = require('meow');
var tempfile = require('tempfile');
var _ = require('lodash');
var join = require('path').join;
var resolve = require('path').resolve;

var cli = meow({
help: [
Expand Down Expand Up @@ -84,19 +84,19 @@ var outStream;

try {
if (flags.context) {
templateContext = require(join(process.cwd(), flags.context));
templateContext = require(resolve(process.cwd(), flags.context));
}

if (flags.gitRawCommitsOpts) {
gitRawCommitsOpts = require(join(process.cwd(), flags.gitRawCommitsOpts));
gitRawCommitsOpts = require(resolve(process.cwd(), flags.gitRawCommitsOpts));
}

if (flags.parserOpts) {
parserOpts = require(join(process.cwd(), flags.parserOpts));
parserOpts = require(resolve(process.cwd(), flags.parserOpts));
}

if (flags.writerOpts) {
writerOpts = require(join(process.cwd(), flags.writerOpts));
writerOpts = require(resolve(process.cwd(), flags.writerOpts));
}
} catch (err) {
console.error('Failed to get file. ' + err);
Expand Down
24 changes: 24 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,30 @@ describe('cli', function() {
});
});

it('--writer-opts should work with relative path', function(done) {
var cp = spawn(cliPath, ['--writer-opts', '../../test/fixtures/writer-opts.js'], {
stdio: [process.stdin, null, null]
});

cp.stdout
.pipe(concat(function(chunk) {
expect(chunk.toString()).to.equal('template');
done();
}));
});

it('--writer-opts should work with absolute path', function(done) {
var cp = spawn(cliPath, ['--writer-opts', __dirname + '/fixtures/writer-opts.js'], {
stdio: [process.stdin, null, null]
});

cp.stdout
.pipe(concat(function(chunk) {
expect(chunk.toString()).to.equal('template');
done();
}));
});

it('should be verbose', function(done) {
var cp = spawn(cliPath, ['-v', '-p', 'no'], {
stdio: [process.stdin, null, null]
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/writer-opts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
mainTemplate: '{{date2}}template'
};

0 comments on commit 7f68b3e

Please sign in to comment.