From 2e9e3cd4ba4bf81f961de129266c572ff0b6f756 Mon Sep 17 00:00:00 2001 From: Thomas Chung Date: Wed, 13 Jul 2022 01:23:07 +1000 Subject: [PATCH] Make relative paths in include work for cli --- bin/cli.js | 7 +++---- test/cli.js | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 0feab0b4..cb11aa4c 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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); diff --git a/test/cli.js b/test/cli.js index 81b1d5e9..31c33dc1 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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); + }); + });