Skip to content

Validates whether projectName follows npm conventions #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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