Created
March 5, 2019 14:29
-
-
Save alieslamifard/603cb5258e6a3c40b70f69dba07246a4 to your computer and use it in GitHub Desktop.
yeoman generator
This file contains 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
'use strict'; | |
const Generator = require('yeoman-generator'); | |
const chalk = require('chalk'); | |
const yosay = require('yosay'); | |
module.exports = class extends Generator { | |
// Note: arguments and options should be defined in the constructor. | |
constructor(args, opts) { | |
super(args, opts); | |
// This makes `appname` a required argument. | |
// Define argument. | |
this.argument('arg1', { type: String, required: false }); | |
// Define options | |
this.option('coffee', { type: String, required: false }); | |
// And you can then access it later; e.g. | |
// this.log(this.options.arg1); | |
} | |
prompting() { | |
// Have Yeoman greet the user. | |
this.log(yosay(`Welcome from ${chalk.yellow('KIAN')} development team.`)); | |
const prompts = [ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'component name?' | |
}, | |
{ | |
type: 'confirm', | |
name: 'cool', | |
message: 'Need cool Features?', | |
default: true | |
} | |
]; | |
return this.prompt(prompts).then(props => { | |
// To access props later use this.props.someAnswer; | |
this.props = props; | |
}); | |
} | |
writing() { | |
this.fs.copyTpl(this.templatePath('_index.js'), this.destinationPath('/index.js'), { | |
name: this.props.name | |
}); | |
this.fs.copy( | |
this.templatePath('_index.html'), | |
this.destinationPath('src/component/index.html') | |
); | |
} | |
install() { | |
// This.installDependencies(); | |
} | |
end() { | |
this.log( | |
chalk(`${chalk.blue.bold('WOW!')} Everything is ${chalk.green.bold('Done !')}`) | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment