Last active
March 21, 2019 16:23
-
-
Save misterdev/af82ac5cf1659a5f89daf3959ff452e0 to your computer and use it in GitHub Desktop.
4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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