diff --git a/src/cli.js b/src/cli.js index 9bf00b7..eaf28e6 100644 --- a/src/cli.js +++ b/src/cli.js @@ -30,7 +30,7 @@ if (!commander.url) { const rawOutputPath = commander.output || 'output.png'; const outputPath = path.resolve(process.cwd(), rawOutputPath); -const outputFile = path.extname(outputPath) === '.png' ? outputPath : `${outputPath}.png`; +const outputFile = path.extname(outputPath) === '.png' ? outputPath : path.resolve(outputPath, 'output.png'); winston.info(`Capturing ${chalk.cyan(commander.url)}`); winston.info(`Writing to ${chalk.cyan(outputFile)}`); diff --git a/src/index.js b/src/index.js index e647c85..24bf8ef 100644 --- a/src/index.js +++ b/src/index.js @@ -14,12 +14,13 @@ const OPTIONS = { shotSize: { width: 'all', height: 'all' } }; * @param {string} outputPath The outputPath where the image should be written to * @returns {Promise} A promise that will create the image and returns the absolute path. */ export default (url: string, outputPath: string) => { - const absoluteOutputPath = path.resolve(process.cwd(), outputPath); + const aop = path.resolve(process.cwd(), outputPath); + const output = path.extname(aop) === '.png' ? aop : path.resolve(aop, 'output.png'); return new Promise((resolve, reject) => { if (isUrl(url)) { - webshot(url, absoluteOutputPath, OPTIONS, (err) => { + webshot(url, output, OPTIONS, (err) => { if (err) { reject(err); } - resolve(absoluteOutputPath); + resolve(output); }); } else { reject('Invalid url provided.'); } });