Skip to content

Commit

Permalink
Merge pull request #687 from i8-pi/cli-relative-path
Browse files Browse the repository at this point in the history
Make relative paths in include work for cli
  • Loading branch information
mde authored Jul 23, 2022
2 parents f6ba7f3 + 2e9e3cd commit fc78c01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

let path = require('path');

let program = require('jake').program;
delete global.jake; // NO NOT WANT
Expand Down Expand Up @@ -149,9 +150,6 @@ function run() {
}
}

// Default to having views relative from the current working directory
opts.views = ['.'];

// Ensure there's a template to render
if (!templatePath) {
throw new Error('Please provide a template path. (Run ejs -h for help)');
Expand Down Expand Up @@ -197,7 +195,8 @@ function run() {
vals[p] = pVals[p];
}

let template = fs.readFileSync(templatePath).toString();
opts.filename = path.resolve(process.cwd(), templatePath);
let template = fs.readFileSync(opts.filename).toString();
let output = ejs.render(template, vals, opts);
if (pOpts.outputFile) {
fs.writeFileSync(pOpts.outputFile, output);
Expand Down
8 changes: 8 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ suite('cli', function () {
assert.equal(o.replace(/\n/g, lf), c);
});

test('relative path in nested include', function () {
let x = path.join('./bin/cli.js');
let u = path.join('test/fixtures/include-simple.ejs');
let o = run(os+x+' '+u);
let c = fs.readFileSync('test/fixtures/include-simple.html', 'utf-8');
assert.equal(o, c);
});

});

0 comments on commit fc78c01

Please sign in to comment.