Skip to content

Commit 6d97ab5

Browse files
committed
feat: add no files error
1 parent cc87adc commit 6d97ab5

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "appthinning",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Make app thinner. Help you find large files and compress png, gif, jpg, jpeg, svg files.",
55
"main": "index.js",
66
"bin": {

src/error/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class ImageOptimNotInstalledError extends AppthinningError {
5353
}
5454
}
5555

56+
class NoFilesNeedError extends AppthinningError {
57+
constructor() {
58+
super(9, "No files need to be processed.")
59+
}
60+
}
61+
5662
module.exports = {
5763
AppthinningError,
5864
ProjectParamError,
@@ -62,5 +68,6 @@ module.exports = {
6268
TinyPngError,
6369
TinyPngValidateError,
6470
ImageOptimError,
65-
ImageOptimNotInstalledError
71+
ImageOptimNotInstalledError,
72+
NoFilesNeedError
6673
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ middlewareCenter.handleRequest(ctx).then(function(data){
2727

2828
function commander() {
2929
program
30-
.version("0.2.3")
30+
.version("0.2.4")
3131
.option("-d, --dir <String>", "project directory.")
3232
.option(
3333
"-t, --types <String>",

src/middlewares/largeFile/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Config = require("../../config/index")
22
const colors = require("colors")
33
const LargeFileFinder = require("./largeFileFinder")
4-
const {ProjectParamError} = require("../../error")
4+
const {ProjectParamError, NoFilesNeedError} = require("../../error")
55

66
async function largeFile(ctx, next) {
77
const program = ctx.program
@@ -19,8 +19,8 @@ async function largeFile(ctx, next) {
1919
}
2020

2121
let type = Config.defaultType
22-
if (program.type) {
23-
type = program.type.toString()
22+
if (program.types) {
23+
type = program.types.toString()
2424
}
2525

2626
console.log(colors.yellow("finding large files..."))
@@ -32,6 +32,10 @@ async function largeFile(ctx, next) {
3232
)
3333
ctx.files = result
3434

35+
if (ctx.files.length < 1) {
36+
return Promise.reject(new NoFilesNeedError())
37+
}
38+
3539
await next()
3640
}
3741

0 commit comments

Comments
 (0)