Skip to content

Commit

Permalink
Validate project name in generator to ensure it's a valid npm package…
Browse files Browse the repository at this point in the history
… name (#298)
  • Loading branch information
latentflip authored and doug-wade committed Jun 21, 2016
1 parent 947ea1a commit 65f7b38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/generator-react-server/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var validatePackageName = require('validate-npm-package-name');

module.exports = yeoman.Base.extend({
prompting: function () {
Expand All @@ -13,7 +14,18 @@ module.exports = yeoman.Base.extend({
type: 'input',
name: 'name',
message: 'What would you like to call your app?',
default: this.appname
default: this.appname.trim().replace(/\s+/g, '-'),
validate: function (name) {
var validation = validatePackageName(name);
var warnings = validation.warnings || [];
var errors = validation.errors || [];

if (validation.validForNewPackages) {
return true;
}

return warnings.concat(errors).join('\n');
}
}, {
type: 'confirm',
name: 'dockerCfg',
Expand Down
1 change: 1 addition & 0 deletions packages/generator-react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
],
"dependencies": {
"chalk": "^1.0.0",
"validate-npm-package-name": "^2.2.2",
"yeoman-generator": "^0.23.0",
"yosay": "^1.0.0"
},
Expand Down

0 comments on commit 65f7b38

Please sign in to comment.