diff --git a/CHANGELOG.md b/CHANGELOG.md index 697d644..3f24932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ -# Head +# 0.3.0 +- Added: `silent` argument reported only errors. +- Changed: `verbose` argument reported anything. +- Chore(package): use `^` instead `~` for `babel-preset-es2015` package. +- Chore(package): use `^` instead `~` for `babel-preset-stage-0"` package. - Chore(package): remove extra `files` from `package.json`. +- Chore(package): update a minimal version of `remark-cli` from `1.0.0` to `2.0.0`. +- Chore(package): update a minimal version of `remark-lint` from `4.0.0` to `5.0.0`. +- Chore(package): use `remark-preset-lint-itgalaxy` instead `remark-lint-config-itgalaxy`. - Chore: rename `LICENSE.md` to `LICENSE`. # 0.2.0 diff --git a/README.md b/README.md index 7a6557d..c44f232 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ $ npm install --global imagemin-power-cli ## Usage ```shell -Usage + Usage $ imagemin-power [input] [options] $ imagemin-power > $ cat | imagemin-power > @@ -31,11 +31,13 @@ Usage -d, --cwd Current working directory. -p, --plugin Override the default plugins. -o, --out-dir Output directory. - -v, --verbose Report errors only. -r, --recursive Run the command recursively. -i, --ignore-errors Not stop on errors (it works with only with ). + -s --silent Reported only errors. + -v, --verbose Reported everything. + + Examples: - Examples $ imagemin-power images/* --out-dir=build $ imagemin-power foo.png > foo-optimized.png $ cat foo.png | imagemin-power > foo-optimized.png diff --git a/__tests__/cli.js b/__tests__/cli.js index a533cec..87be18e 100644 --- a/__tests__/cli.js +++ b/__tests__/cli.js @@ -140,6 +140,7 @@ test('optimize a PNG use glob pattern and with verbose', async (t) => { const afterOptimizeData = await fsP.readFile('fixtures/tmp/test.png'); t.regex(output.stderr, /Minifying image "fixtures\/test.png"/); + t.regex(output.stderr, /Successfully compressed images: 1. Unsuccessfully compressed images: 0. Total images: 1./); t.true(afterOptimizeData.length < beforeOptimizeData.length); }); @@ -162,6 +163,10 @@ test('output error on corrupt images use glob pattern and verbose', async (t) => t.true(output.code === 1); t.regex(output.stderr, /Error: Corrupt JPEG data/); + t.notRegex( + output.stderr, + /Successfully compressed images: 0. Unsuccessfully compressed images: 1. Total images: 1./ + ); }); test('optimize a corrupt image use verbose and ignore-errors', async (t) => { @@ -176,6 +181,46 @@ test('optimize a corrupt image use verbose and ignore-errors', async (t) => { t.regex(output.stderr, /Unsuccessfully compressed images: 1/); }); +test('optimize a corrupt image and a normal image use verbose and ignore-errors', async (t) => { + const output = await execa('../cli.js', [ + 'fixtures/test-corrupt.jpg', + 'fixtures/test.jpg', + '--out-dir=fixtures/tmp', + '--verbose', + '--ignore-errors' + ]); + + t.regex(output.stderr, /Minifying image "fixtures\/test-corrupt.jpg"/); + t.regex(output.stderr, /Error: Corrupt JPEG data/); + t.regex(output.stderr, /Minifying image "fixtures\/test.jpg"/); + t.regex(output.stderr, /Successfully compressed images: 1. Unsuccessfully compressed images: 1. Total images: 2./); +}); + +test('optimize a corrupt image use silent and ignore-errors', async (t) => { + const output = await execa('../cli.js', [ + 'fixtures/test-corrupt.jpg', + '--silent', + '--ignore-errors' + ]); + + t.regex(output.stderr, /Minifying image "fixtures\/test-corrupt.jpg"/); + t.regex(output.stderr, /Error: Corrupt JPEG data/); +}); + +test('optimize a corrupt image and a normal image use silent and ignore-errors', async (t) => { + const output = await execa('../cli.js', [ + 'fixtures/test-corrupt.jpg', + 'fixtures/test.jpg', + '--out-dir=fixtures/tmp', + '--silent', + '--ignore-errors' + ]); + + t.regex(output.stderr, /Minifying image "fixtures\/test-corrupt.jpg"/); + t.regex(output.stderr, /Error: Corrupt JPEG data/); + t.notRegex(output.stderr, /Successfully compressed images: 1. Unsuccessfully compressed images: 1. Total images: 2./); +}); + test('optimize images use verbose and ignore-errors', async (t) => { const output = await execa('../cli.js', [ 'fixtures/test.{jpg,png,webp,gif,svg}', @@ -189,7 +234,7 @@ test('optimize images use verbose and ignore-errors', async (t) => { t.regex(output.stderr, /Minifying image "fixtures\/test.webp"/); t.regex(output.stderr, /Minifying image "fixtures\/test.gif"/); t.regex(output.stderr, /Minifying image "fixtures\/test.svg"/); - t.regex(output.stderr, /Successfully compressed images: 5/); + t.regex(output.stderr, /Successfully compressed images: 5. Unsuccessfully compressed images: 0. Total images: 5./); }); test('support plugins', async (t) => { diff --git a/cli.js b/cli.js index c452adf..9a7ced0 100755 --- a/cli.js +++ b/cli.js @@ -34,9 +34,10 @@ const cli = meow(` -d, --cwd Current working directory. -p, --plugin Override the default plugins. -o, --out-dir Output directory. - -v, --verbose Report errors only. -r, --recursive Run the command recursively. -i, --ignore-errors Not stop on errors (it works with only with ). + -s --silent Reported only errors. + -v, --verbose Reported everything. Examples $ imagemin-power images/* --out-dir=build @@ -52,6 +53,7 @@ const cli = meow(` o: 'out-dir', p: 'plugin', r: 'recursive', + s: 'silent', v: 'verbose' /* eslint-enable id-length */ }, @@ -146,7 +148,9 @@ const run = (input, options) => { cwd: process.cwd(), // Info support multiple plugins plugin: DEFAULT_PLUGINS, - recursive: false + recursive: false, + silent: false, + verbose: false }, options); const dataSource = opts.config || path.resolve('./.imagemin.js'); @@ -176,11 +180,13 @@ const run = (input, options) => { let spinner = null; - if (opts.verbose) { - spinner = ora( - 'Starting minifying images...' - ); - spinner.start(); + if (opts.verbose || opts.silent) { + spinner = ora(); + + if (opts.verbose) { + spinner.text = 'Starting minifying images...'; + spinner.start(); + } } /* istanbul ignore if */ @@ -238,12 +244,14 @@ const run = (input, options) => { }, (error) => { if (opts.ignoreErrors) { - if (opts.verbose) { + if (opts.verbose || opts.silent) { failCounter++; spinner.text = `Minifying image "${filepath}" ` - + `(${successCounter + failCounter} of ${total})...\nError: ${error.stack}...`; + + `(${successCounter + + failCounter} of ${total})...\nError: ${error.stack}...`; spinner.fail(); + spinner.text = 'Minifying images...'; spinner.start(); } @@ -271,7 +279,7 @@ const run = (input, options) => { return Promise.resolve(files); }) .catch((error) => { - if (opts.verbose) { + if (opts.verbose || opts.silent) { spinner.fail(); } diff --git a/package.json b/package.json index d1b2066..a7f04e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "imagemin-power-cli", - "version": "0.2.0", + "version": "0.3.0", "description": "Minify images.", "keywords": [ "cli", @@ -51,8 +51,8 @@ "ava": "^0.16.0", "babel-cli": "^6.11.0", "babel-core": "^6.13.0", - "babel-preset-es2015": "~6.13.0", - "babel-preset-stage-0": "~6.5.0", + "babel-preset-es2015": "^6.13.0", + "babel-preset-stage-0": "^6.5.0", "babel-register": "^6.9.0", "coveralls": "^2.11.0", "eslint": "^3.0.0", @@ -71,9 +71,9 @@ "npm-run-all": "^3.0.0", "nyc": "^8.1.0", "pify": "^2.3.0", - "remark-cli": "^1.0.0", - "remark-lint": "^4.0.0", - "remark-lint-config-itgalaxy": "^1.0.0", + "remark-cli": "^2.0.0", + "remark-lint": "^5.0.0", + "remark-preset-lint-itgalaxy": "^1.0.0", "replace-ext": "^1.0.0", "rimraf": "^2.5.2" }, @@ -86,8 +86,8 @@ "scripts": { "coveralls": "nyc report --reporter=text-lcov | coveralls", - "lint:eslint": "eslint . --ignore-pattern '**/__tests__/**' --ignore-path .gitignore --color", - "lint:remark": "remark '{**/*,*}.md' -r ./node_modules/remark-lint-config-itgalaxy/index.js -i .gitignore -f -q", + "lint:eslint": "eslint . --ignore-pattern '**/__tests__/**' --ignore-path .gitignore", + "lint:remark": "remark '{**/*,*}.md' -i .gitignore -f -q", "lint": "npm-run-all -l -p lint:**", "ava": "nyc ava --verbose '**/__tests__/*.js'",