[refactor] [s]: update prompt validate

This commit is contained in:
Thadeu Cotts
2020-11-26 16:12:02 -03:00
parent 6e3a2f06c7
commit 269912ad93

View File

@@ -19,28 +19,15 @@ let projectPath = "";
program program
.name(package.name) .name(package.name)
.version(package.version) .version(package.version)
/**
* TODO
* Add Options
* Add Example Options
* Add templates
*/
.arguments("[dir]") .arguments("[dir]")
.usage(`${chalk.yellow("[dir]")}`) .usage(`${chalk.yellow("[dir]")}`)
.description({ .description({
dir: "Directory to be used on install Portal.js", dir: "Directory to be used on install Portal.js",
}) })
.action((name) => (projectPath = name)) .action((name) => (projectPath = name))
.option('--use-npm') .option("--use-npm")
.allowUnknownOption()
.parse(process.argv); .parse(process.argv);
// print a fancy Portal.js in the terminal
console.log(
chalk.yellow(
figlet.textSync('Portal.Js', {horizontalLayout: 'full'})
)
);
/** /**
* Method to ask a custon name if was not passed as parameter * Method to ask a custon name if was not passed as parameter
* returns the value passed from terminal input * returns the value passed from terminal input
@@ -52,8 +39,15 @@ async function promptPath() {
message: "Choose a name to your project", message: "Choose a name to your project",
initial: "", initial: "",
validate: (name) => { validate: (name) => {
//TODO Method to validate valid path name projectPath = name
return true; if(isPathInUse(projectPath)){
return `${chalk.yellow(
"Path " +
chalk.redBright(projectPath) +
" is already in use and is not empty."
)}`
}
return true
}, },
}); });
} }