Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #10

Merged
merged 45 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
00c90f9
Install fdir
343dev Sep 22, 2024
b20869e
Replace fast-glob with fdir
343dev Sep 22, 2024
2d5da0c
Uninstall fast-glob
343dev Sep 22, 2024
0e6dcde
Improve index.js
343dev Sep 23, 2024
29cfadb
Rename prepareFilePaths to prepareInputFilePaths
343dev Sep 24, 2024
f93b8cb
Rename prepareOutputPath to prepareOutputDirectoryPath
343dev Sep 24, 2024
28e4e2c
Rename convert & optimize functions arguments
343dev Sep 24, 2024
375c689
Improve optimize function
343dev Sep 24, 2024
ff954ce
Add lib/constants.js
343dev Sep 25, 2024
74ce5c7
Improve convert function
343dev Sep 25, 2024
063a285
Move lossless optimization notice to index.js
343dev Sep 25, 2024
b5576c9
Add notice about Animated AVIF is not supported
343dev Sep 25, 2024
0dc02cc
Change image optimization workflow
343dev Sep 25, 2024
1bb84e4
Change image convert workflow
343dev Sep 25, 2024
b02519b
Fix progress bar in convert mode
343dev Sep 26, 2024
09bdb8f
Add interactive progress log
343dev Sep 26, 2024
126325e
Change "File already exists" message type from "error" to "info" and …
343dev Sep 27, 2024
0be51df
Rename calcRatio to calculateRatio
343dev Sep 28, 2024
fba685e
Remove lib/check-config-path.js
343dev Sep 28, 2024
1e5f4c3
Rename checkFileExists in checkPathAccessibility
343dev Sep 28, 2024
c27a3e8
Remove default export from colorize
343dev Sep 28, 2024
609727c
Remove default export from createProgressBarContainer
343dev Sep 28, 2024
e7b61de
Create DEFAULT_CONFIG_FILENAME constant
343dev Sep 28, 2024
bac2c12
Improve findConfig
343dev Sep 28, 2024
4106ba1
Improve formatBytes
343dev Sep 28, 2024
49b6b36
Remove default export from getPlural
343dev Sep 28, 2024
d07ef4a
Improve log
343dev Sep 28, 2024
6be4f6d
Improve optionsToArguments
343dev Sep 29, 2024
3d992ad
Remove default export from parseImageMetadata
343dev Sep 29, 2024
8f67772
Improve prepareInputFilePaths
343dev Sep 29, 2024
e66ef40
Improve prepareOutputDirectoryPath
343dev Sep 29, 2024
1113206
Add programOptions helper
343dev Sep 30, 2024
2d3ce92
Improve showTotal
343dev Sep 30, 2024
b56e899
Fix output to custom directory
343dev Oct 1, 2024
081a879
Improve findConfig and rename to findConfigFilePath
343dev Oct 1, 2024
32048c6
Remove prepareWriteFilePath
343dev Oct 1, 2024
59a2dba
Remove default export from convert
343dev Oct 1, 2024
826496d
Remove default export from optimize
343dev Oct 1, 2024
f60649b
Move convert.js to project root
343dev Oct 1, 2024
c951ef4
Move optimize.js to project root
343dev Oct 1, 2024
2ed50e4
Bump fdir from 6.3.0 to 6.4.0
343dev Oct 2, 2024
cf23f5e
Bump lint-staged from 15.2.8 to 15.2.10
343dev Oct 2, 2024
05ab71e
Update MIGRATION.md
343dev Oct 3, 2024
c239efb
Update CHANGELOG.md
343dev Oct 3, 2024
dfb1bd9
9.0.0
343dev Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve showTotal
343dev committed Sep 30, 2024
commit 2d3ce929f8a33f98cc40796c907a6361ea183981
4 changes: 1 addition & 3 deletions lib/convert.js
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ import { getPlural } from './get-plural.js';
import {
LOG_TYPES,
log,
logEmptyLine,
logProgress,
logProgressVerbose,
} from './log.js';
import { optionsToArguments } from './options-to-arguments.js';
import { parseImageMetadata } from './parse-image-metadata.js';
import prepareWriteFilePath from './prepare-write-file-path.js';
import { programOptions } from './program-options.js';
import showTotal from './show-total.js';
import { showTotal } from './show-total.js';

export default async function convert({
inputFilePaths,
@@ -112,7 +111,6 @@ export default async function convert({
progressBarContainer.update(); // Prevent logs lost. See: https://github.com/npkgz/cli-progress/issues/145#issuecomment-1859594159
progressBarContainer.stop();

logEmptyLine();
showTotal(totalSize.before, totalSize.after);
}

4 changes: 1 addition & 3 deletions lib/optimize.js
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ import { getPlural } from './get-plural.js';
import {
LOG_TYPES,
log,
logEmptyLine,
logProgress,
logProgressVerbose,
} from './log.js';
import { optionsToArguments } from './options-to-arguments.js';
import { parseImageMetadata } from './parse-image-metadata.js';
import prepareWriteFilePath from './prepare-write-file-path.js';
import { programOptions } from './program-options.js';
import showTotal from './show-total.js';
import { showTotal } from './show-total.js';

export default async function optimize({
inputFilePaths,
@@ -73,7 +72,6 @@ export default async function optimize({
progressBarContainer.update(); // Prevent logs lost. See: https://github.com/npkgz/cli-progress/issues/145#issuecomment-1859594159
progressBarContainer.stop();

logEmptyLine();
showTotal(totalSize.before, totalSize.after);
}

14 changes: 7 additions & 7 deletions lib/show-total.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { calculateRatio } from './calculate-ratio.js';
import { formatBytes } from './format-bytes.js';
import { log } from './log.js';
import { log, logEmptyLine } from './log.js';

export default function showTotal(before, after) {
export function showTotal(before, after) {
const ratio = calculateRatio(before, after);
const saved = formatBytes(before - after);

if (ratio > 0) {
log(`Yay! You saved ${saved} (${ratio}%)`);
} else {
log('Done!');
}
logEmptyLine();
log(ratio > 0
? `Yay! You saved ${saved} (${ratio}%)`
: 'Done!',
);
}
6 changes: 3 additions & 3 deletions tests/show-total.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { jest } from '@jest/globals';

import showTotal from '../lib/show-total.js';
import { showTotal } from '../lib/show-total.js';

test('Savings size and compression ratio are displayed', () => {
const fileSize = 1_048_576;

console.log = jest.fn();

showTotal(fileSize, fileSize / 2);
expect(console.log.mock.calls[0][1]).toBe('Yay! You saved 512 KB (50%)');
expect(console.log.mock.calls[1][1]).toBe('Yay! You saved 512 KB (50%)');

console.log.mockRestore();
});
@@ -19,7 +19,7 @@ test('Savings size and compression ratio are not displayed', () => {
console.log = jest.fn();

showTotal(fileSize, fileSize * 2);
expect(console.log.mock.calls[0][1]).toBe('Done!');
expect(console.log.mock.calls[1][1]).toBe('Done!');

console.log.mockRestore();
});