Comparing version 1.0.0 to 1.1.0
20
cli.js
@@ -33,2 +33,7 @@ #!/usr/bin/env node | ||
type: 'boolean', | ||
}) | ||
.option('a', { | ||
alias: 'avoid', | ||
describe: 'Avoid specific suffix', | ||
type: 'string', | ||
}).argv | ||
@@ -40,9 +45,12 @@ | ||
} | ||
dirmages(argv.dir, { width: argv.w, heigth: argv.h, suffix: argv.s }).then( | ||
() => { | ||
if (!argv.quiet) { | ||
spinner.succeed(`Transforming images done`) | ||
} | ||
dirmages(argv.dir, { | ||
width: argv.w, | ||
heigth: argv.h, | ||
suffix: argv.s, | ||
avoidRepeat: argv.a.trim() === '' ? true : argv.a.trim(), | ||
}).then((total) => { | ||
if (!argv.quiet) { | ||
spinner.succeed(`Transformed ${total} images successfully`) | ||
} | ||
) | ||
}) | ||
} |
22
index.js
@@ -8,4 +8,11 @@ const readdirp = require('readdirp') | ||
dir, | ||
{ width = null, heigth = null, options = {}, suffix = '-alt' } = {} | ||
{ | ||
width = null, | ||
heigth = null, | ||
options = {}, | ||
suffix = '-alt', | ||
avoidRepeat = false, | ||
} = {} | ||
) { | ||
let total = 0 | ||
try { | ||
@@ -18,5 +25,16 @@ for await (const { fullPath } of readdirp(dir)) { | ||
const dest = join(dir, `${name}${suffix}${ext}`) | ||
await sharp(fullPath).resize(width, heigth, options).toFile(dest) | ||
if ( | ||
!avoidRepeat || | ||
(avoidRepeat && | ||
!name.endsWith( | ||
typeof avoidRepeat === 'string' ? avoidRepeat : suffix | ||
)) | ||
) { | ||
await sharp(fullPath).resize(width, heigth, options).toFile(dest) | ||
total++ | ||
} | ||
} | ||
} | ||
return total | ||
} catch (err) { | ||
@@ -23,0 +41,0 @@ console.log(err) |
{ | ||
"name": "dirmage", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Lionel Tzatzkin <elrumordelaluz@hotmail.com> (https://elrumordelaluz.com/)", |
2514
92