Skip to content

Commit

Permalink
validate multiple arguments if provided 🚀
Browse files Browse the repository at this point in the history
Exclude options while validating 🎉

Fix linting errors 🚧

remove unwanted typecasting 🚧
  • Loading branch information
jamesgeorge007 committed Feb 2, 2019
1 parent af339ec commit c2eef4b
Show file tree
Hide file tree
Showing 2 changed files with 485 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,42 @@ const errorLogFilePatterns = [
];

let projectName;
const args = process.argv.slice(2);

const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('<project-directory>')
.usage(`${chalk.green('<project-directory>')} [options]`)
.action(name => {
projectName = name;

// Computing number of arguments given excluding options
let argsLength = 0;

args.map(item => {

if (item === '--scripts-version') {
argsLength--;
}

if (!item.startsWith('-')){
argsLength++;
}
});

if (argsLength > 1){

console.log(
chalk.yellow(
`\n You have provided more that one argument for <project-directory>.`
)
);

console.log(
`\n Run ${chalk.cyan(`create-react-app --help`)} to see all options.`
);
process.exit(1);
}
})
.option('--verbose', 'print additional logs')
.option('--info', 'print environment debug info')
Expand Down

0 comments on commit c2eef4b

Please sign in to comment.