Skip to content

Commit

Permalink
Prepare 0.3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Krasnoyarov committed Aug 26, 2016
1 parent 38b3912 commit 3e596f3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 23 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $ npm install --global imagemin-power-cli
## Usage

```shell
Usage
Usage
$ imagemin-power [input] [options]
$ imagemin-power <file> > <output>
$ cat <file> | imagemin-power > <output>
Expand All @@ -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 <path|glob>).
-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
Expand Down
47 changes: 46 additions & 1 deletion __tests__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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) => {
Expand All @@ -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}',
Expand All @@ -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) => {
Expand Down
28 changes: 18 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path|glob>).
-s --silent Reported only errors.
-v, --verbose Reported everything.
Examples
$ imagemin-power images/* --out-dir=build
Expand All @@ -52,6 +53,7 @@ const cli = meow(`
o: 'out-dir',
p: 'plugin',
r: 'recursive',
s: 'silent',
v: 'verbose'
/* eslint-enable id-length */
},
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -271,7 +279,7 @@ const run = (input, options) => {
return Promise.resolve(files);
})
.catch((error) => {
if (opts.verbose) {
if (opts.verbose || opts.silent) {
spinner.fail();
}

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagemin-power-cli",
"version": "0.2.0",
"version": "0.3.0",
"description": "Minify images.",
"keywords": [
"cli",
Expand Down Expand Up @@ -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",
Expand All @@ -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"
},
Expand All @@ -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'",
Expand Down

0 comments on commit 3e596f3

Please sign in to comment.