Skip to content

Commit

Permalink
Add propererror handling for config
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza9472 committed Oct 12, 2021
1 parent f4689d1 commit 990cd8c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
})
.check((argv) => {

//Input
if(argv.i){

//Input
if(!fs.existsSync(argv.i)){
throw new Error("Input path must be a file or directory");
}
}

//Output
if(argv.o != outputDir){
else if(argv.o != outputDir){
if(fs.existsSync(argv.o)){
if(!fs.lstatSync(argv.o).isDirectory()){
throw new Error("Output path points to a file. Output directory must be valid")
Expand All @@ -71,12 +71,11 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
else throw new Error("Output directory must be valid");
}


if(argv.c){
//Config
else if(argv.c){

if(isJSON(process.argv[3])){

//Config
if(!fs.existsSync(argv.c)){
throw new Error("JSON file path does not exist");
}
Expand All @@ -91,6 +90,9 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
throw new Error("The passed file should be of JSON format")
}
}
else {
throw new Error("A config file(.JSON) or an input file is required");
}

return true;
})
Expand Down

0 comments on commit 990cd8c

Please sign in to comment.