Skip to content

Instantly share code, notes, and snippets.

@misterdev
Last active March 21, 2019 16:23
Show Gist options
  • Save misterdev/af82ac5cf1659a5f89daf3959ff452e0 to your computer and use it in GitHub Desktop.
Save misterdev/af82ac5cf1659a5f89daf3959ff452e0 to your computer and use it in GitHub Desktop.
4
const Generator = require('yeoman-generator');
// => We include InputValidate
const { List, Input, InputValidate } = require('@webpack-cli/webpack-scaffold');
module.exports = class WebpackGenerator extends Generator {
/* ... */
prompting() {
// => We create a validator function that takes the user input as parameter
const validateName = (value) => {
// => If it contains space it's not a valid name
if (value.indexOf(' ') > 0) {
// => We return a message for the user
return 'Invalid name: spaces are not allowed, try again';
} else {
// => Otherwise, it's valid, we can continua
return true;
}
}
return this.prompt([
// => We replace Input with InputValidate
// => and we pass the validator function as third parameter => => =>
InputValidate('name', 'How do you want to name your project? (my-vue-project)', validateName),
Input('inFolder', 'Which folder will your source code be in? (src)'),
/* ... */
])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment