Skip to content

Commit

Permalink
closes Hashnode#42 validate projectName 👍
Browse files Browse the repository at this point in the history
Minor refactor
  • Loading branch information
jamesgeorge007 committed Feb 17, 2019
1 parent 2919c5f commit 171274a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"elegant-spinner": "^1.0.1",
"log-update": "^2.3.0",
"shelljs": "^0.8.2",
"validate-npm-package-name": "^3.0.0",
"writefile": "^0.2.8"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/commands/main-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import chalk from 'chalk';
import elegantSpinner from 'elegant-spinner';
import logUpdate from 'log-update';
import variants from '../../variants.json';
import validate from 'validate-npm-package-name';

require('shelljs/global');

Expand All @@ -23,6 +24,16 @@ if (program.args.length > 1) {
exit(1);
}

const validationResult = validate(program.args[0]);
if (!validationResult.validForNewPackages) {
console.error(
`Could not create a project called ${chalk.red(
`"${program.args[0]}"`
)} because of npm naming restrictions:`
);
exit(1);
}

if (program.args.length === 1) {
if (test('-d', program.args[0])) {
console.log(chalk.red(`${program.args[0]} directory already exits! Please choose some another name!!!`));
Expand Down

0 comments on commit 171274a

Please sign in to comment.