|
| 1 | +const Generator = require('yeoman-generator'); |
| 2 | +const validate = require('./validate'); |
| 3 | + |
| 4 | +module.exports = class extends Generator { |
| 5 | + |
| 6 | + initializing() { |
| 7 | + this.log('OSS Project Generator'); |
| 8 | + this.log(); |
| 9 | + } |
| 10 | + |
| 11 | + prompting() { |
| 12 | + const done = this.async(); |
| 13 | + const store = true; |
| 14 | + |
| 15 | + const prompts = [ |
| 16 | + { |
| 17 | + type: 'input', |
| 18 | + name: 'project', |
| 19 | + message: 'What is the name of your project', |
| 20 | + default: 'awesome-project' |
| 21 | + }, |
| 22 | + { |
| 23 | + type: 'input', |
| 24 | + name: 'description', |
| 25 | + message: 'What is the description of your project', |
| 26 | + default: 'An awesome project' |
| 27 | + }, |
| 28 | + { |
| 29 | + type: 'input', |
| 30 | + name: 'name', |
| 31 | + message: 'What is your name', |
| 32 | + validate: validate.validateName, |
| 33 | + store: store |
| 34 | + }, |
| 35 | + { |
| 36 | + type: 'input', |
| 37 | + name: 'email', |
| 38 | + message: 'What is your email', |
| 39 | + validate: validate.validateEmail, |
| 40 | + store: store |
| 41 | + }, |
| 42 | + { |
| 43 | + type: 'input', |
| 44 | + name: 'username', |
| 45 | + message: 'What is your GitHub username', |
| 46 | + validate: validate.validateUsername, |
| 47 | + store: store |
| 48 | + } |
| 49 | + ]; |
| 50 | + |
| 51 | + this.prompt(prompts).then((props) => { |
| 52 | + this.props = props; |
| 53 | + done(); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + writing() { |
| 58 | + this.log('Generating project...'); |
| 59 | + this.log(); |
| 60 | + |
| 61 | + const files = require('./files'); |
| 62 | + |
| 63 | + const templates = { |
| 64 | + project: this.props.project, |
| 65 | + description: this.props.description, |
| 66 | + name: this.props.name, |
| 67 | + email: this.props.email, |
| 68 | + username: this.props.username, |
| 69 | + year: new Date().getFullYear() |
| 70 | + }; |
| 71 | + |
| 72 | + files.forEach((file) => { |
| 73 | + this.fs.copyTpl( |
| 74 | + this.templatePath(file), |
| 75 | + this.destinationPath(file), |
| 76 | + templates |
| 77 | + ); |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + install() { |
| 82 | + this.installDependencies({ bower: false }); |
| 83 | + } |
| 84 | + |
| 85 | + end() { |
| 86 | + this.log(); |
| 87 | + this.log('Successfully generated!'); |
| 88 | + } |
| 89 | +}; |
0 commit comments