Skip to content

Instantly share code, notes, and snippets.

@alieslamifard
Created March 5, 2019 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alieslamifard/603cb5258e6a3c40b70f69dba07246a4 to your computer and use it in GitHub Desktop.
Save alieslamifard/603cb5258e6a3c40b70f69dba07246a4 to your computer and use it in GitHub Desktop.
yeoman generator
'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