main files
This commit is contained in:
parent
75fed3ecf4
commit
84b12de330
3 changed files with 75 additions and 0 deletions
19
README.md
Normal file
19
README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# mtt(multitool)
|
||||||
|
|
||||||
|
A multi-tool that performs various operations on files within a directory. Currently, it supports the following features.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
`npm insatll -g @riq0h/mtt`
|
||||||
|
|
||||||
|
## `mtt -r`
|
||||||
|
|
||||||
|
Bulk renames filenames within a directory. When launched, `$EDITOR` is called, allowing you to flexibly edit with any editor.
|
||||||
|
|
||||||
|
## `mtt -c`
|
||||||
|
|
||||||
|
Compresses individual files within a directory. If no filenames are specified, all files will be targeted.
|
||||||
|
|
||||||
|
## `mtt -i <files...> -p <value>`
|
||||||
|
|
||||||
|
Resizes image files (`.jpg`, `.jpeg`, `.png`, `.gif`, `.webp`) within a directory. The `-p` option is required to specify the resize ratio.
|
49
src/index.ts
Normal file
49
src/index.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
import { Command } from "commander";
|
||||||
|
import { version, description } from "../package.json";
|
||||||
|
import { renameFiles, compressFiles, resizeImages } from "./lib";
|
||||||
|
|
||||||
|
const program = new Command();
|
||||||
|
|
||||||
|
program.version(version).description(description);
|
||||||
|
|
||||||
|
program
|
||||||
|
.option("-r, --rename", "rename files in bulk. $EDITOR will be launched")
|
||||||
|
.option(
|
||||||
|
"-c, --compress [targets...]",
|
||||||
|
"compress files individually. If no file name is specified, all files in the directory will be targeted",
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"-i, --image <files...>",
|
||||||
|
"resize image files. File name and -p option are required",
|
||||||
|
)
|
||||||
|
.option("-p, --percentage <value>", "specify the resize percentage")
|
||||||
|
.action((options) => {
|
||||||
|
try {
|
||||||
|
if (options.rename) {
|
||||||
|
renameFiles();
|
||||||
|
} else if (options.compress) {
|
||||||
|
compressFiles(options.compress === true ? undefined : options.compress);
|
||||||
|
} else if (options.image) {
|
||||||
|
if (!options.percentage) {
|
||||||
|
throw new Error(
|
||||||
|
"resize percentage must be specified with the -p option for image resizing.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resizeImages(options.image, Number(options.percentage));
|
||||||
|
} else {
|
||||||
|
program.help();
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.error("error:", error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
if (!process.argv.slice(2).length) {
|
||||||
|
program.help();
|
||||||
|
}
|
7
src/lib.ts
Normal file
7
src/lib.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export { renameFiles } from "./commands/rename";
|
||||||
|
export { compressFiles } from "./commands/compress";
|
||||||
|
export { resizeImages } from "./commands/resize";
|
||||||
|
|
||||||
|
export type { RenameOperation } from "./commands/rename";
|
||||||
|
export type { CompressOperation } from "./commands/compress";
|
||||||
|
export type { ResizeOperation } from "./commands/resize";
|
Loading…
Reference in a new issue