Make relative paths in include work for cli

This commit is contained in:
Thomas Chung
2022-07-13 01:23:07 +10:00
parent f6ba7f3a60
commit 2e9e3cd4ba
2 changed files with 11 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
*
*/
let path = require('path');
let program = require('jake').program;
delete global.jake; // NO NOT WANT
@@ -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)');
@@ -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);

View File

@@ -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);
});
});