Skip to content
Permalink
Browse files

Rename `output` option to `destination`

  • Loading branch information...
sindresorhus committed Jun 30, 2019
1 parent cc0171e commit 8dd5a1472d77345808807c888322a816b97fc37e
Showing with 14 additions and 14 deletions.
  1. +2 −2 index.js
  2. +2 −2 readme.md
  3. +10 −10 test.js
@@ -12,15 +12,15 @@ const junk = require('junk');
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);

const handleFile = async (sourcePath, {output, plugins = []}) => {
const handleFile = async (sourcePath, {destination, plugins = []}) => {
if (plugins && !Array.isArray(plugins)) {
throw new TypeError('The `plugins` option should be an `Array`');
}

let data = await readFile(sourcePath);
data = await (plugins.length > 0 ? pPipe(...plugins)(data) : data);

let destinationPath = output ? path.join(output, path.basename(sourcePath)) : undefined;
let destinationPath = destination ? path.join(destination, path.basename(sourcePath)) : undefined;
destinationPath = (fileType(data) && fileType(data).ext === 'webp') ? replaceExt(destinationPath, '.webp') : destinationPath;

const returnValue = {
@@ -19,7 +19,7 @@ const imageminPngquant = require('imagemin-pngquant');
(async () => {
const files = await imagemin(['images/*.{jpg,png}'], {
output: 'build/images',
destination: 'build/images',
plugins: [
imageminJpegtran(),
imageminPngquant({
@@ -50,7 +50,7 @@ File paths or [glob patterns](https://github.com/sindresorhus/globby#globbing-pa

Type: `object`

##### output
##### destination

Type: `string`

20 test.js
@@ -87,27 +87,27 @@ test('return processed buffer even it is a bad optimization', async t => {

test('output at the specified location', async t => {
const temp = tempy.directory();
const outputTemp = tempy.directory();
const destinationTemp = tempy.directory();
const buffer = await readFile(path.join(__dirname, 'fixture.jpg'));

await makeDir(temp);
await writeFile(path.join(temp, 'fixture.jpg'), buffer);

const files = await imagemin(['fixture.jpg', `${temp}/*.jpg`], {
output: outputTemp,
destination: destinationTemp,
plugins: [imageminJpegtran()]
});

t.true(fs.existsSync(files[0].destinationPath));
t.true(fs.existsSync(files[1].destinationPath));

await del([temp, outputTemp], {force: true});
await del([temp, destinationTemp], {force: true});
});

test('set webp ext', async t => {
const temp = tempy.file();
const files = await imagemin(['fixture.jpg'], {
output: temp,
destination: temp,
plugins: [imageminWebp()]
});

@@ -117,7 +117,7 @@ test('set webp ext', async t => {

test('ignores junk files', async t => {
const temp = tempy.directory();
const outputTemp = tempy.directory();
const destinationTemp = tempy.directory();
const buffer = await readFile(path.join(__dirname, 'fixture.jpg'));

await makeDir(temp);
@@ -126,15 +126,15 @@ test('ignores junk files', async t => {
await writeFile(path.join(temp, 'fixture.jpg'), buffer);

await t.notThrowsAsync(imagemin([`${temp}/*`], {
output: outputTemp,
destination: destinationTemp,
plugins: [imageminJpegtran()]
}));

t.true(fs.existsSync(path.join(outputTemp, 'fixture.jpg')));
t.false(fs.existsSync(path.join(outputTemp, '.DS_Store')));
t.false(fs.existsSync(path.join(outputTemp, 'Thumbs.db')));
t.true(fs.existsSync(path.join(destinationTemp, 'fixture.jpg')));
t.false(fs.existsSync(path.join(destinationTemp, '.DS_Store')));
t.false(fs.existsSync(path.join(destinationTemp, 'Thumbs.db')));

await del([temp, outputTemp], {force: true});
await del([temp, destinationTemp], {force: true});
});

test('glob option', async t => {

0 comments on commit 8dd5a14

Please sign in to comment.
You can’t perform that action at this time.