Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Validate element name, close GH-34
Browse files Browse the repository at this point in the history
  • Loading branch information
robdodson committed Feb 7, 2015
1 parent 974e743 commit fd95fbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lodash": "^2.4.1",
"ncp": "^1.0.1",
"rimraf": "^2.2.8",
"validate-element-name": "^1.0.0",
"yeoman-generator": "^0.17.0",
"yosay": "^1.0.0"
},
Expand Down
17 changes: 12 additions & 5 deletions seed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var _ = require('lodash');
var yeoman = require('yeoman-generator');
var path = require('path');
var yosay = require('yosay');
var elementNameValidator = require('validate-element-name');
var chalk = require('chalk');

module.exports = yeoman.generators.Base.extend({
constructor: function () {
Expand All @@ -25,12 +27,17 @@ module.exports = yeoman.generators.Base.extend({
},
validate: function () {
this.elementName = this['element-name'];
if (this.elementName.indexOf('-') === -1) {
this.emit('error', new Error(
'Element name must contain a dash "-"\n' +
'ex: yo polymer:seed my-element'
));
var result = elementNameValidator(this.elementName);

if (!result.isValid) {
this.emit('error', new Error(chalk.red(result.message)));
}

if (result.message) {
console.warn(chalk.yellow(result.message + '\n'));
}

return true;
},
checkForDanger: function () {
var done = this.async();
Expand Down

0 comments on commit fd95fbf

Please sign in to comment.