0.4.1 • Published 8 years ago
yeoman-easily v0.4.1
yeoman-easily
This library was created to facilitate the following tasks when creating a generator with Yeoman:
- Confirmation:
- Can ask for confirmation before proceeding in one line.
easily.confirmBeforeStart(message)
-easily.checkForConfirmation()
simply returns the result. - Prompting:
- Handle storing user's input from the prompts into
this.props
. Just calleasily.prompt(prompts)
instead of thethis.prompt(prompts, ...)
- Can automatically skip prompts if an option with the same name is present. It will instead copy the value of existingthis.option[field]
intothis.props[field]
. - Can register common prompts viaeasily.learnPrompts(prompts)
and allow looking up prompts by name while callingeasily.prompt()
. This can save a lot of time if you create multiple generators that ask similar questions. - Composing: with another generator, either local or external
- Simplify the syntax to
easily.composeWithLocal(name, namespace, options)
andeasily.composeWithExternal(package, namespace, options)
- File handling:
- Provide functions for mass copying both static and dynamic files based on glob pattern. See
easily.copyFiles(...)
- Provide I/O functions that wrapsthis.fs.xxx
and also resolve template and destination directory. - Method chaining: yeoman-easily was created with chaining in mind and support method chaining for fluent coding.
Installation
$ npm install --save yeoman-easily
Example Usage
'use strict';
var ye = require('yeoman-easily');
var Easily = ye.Easily;
var commonPrompts = ye.prompts;
var chalk = require('chalk');
module.exports = Easily.createGenerator({
prompting: function () {
return this.easily
.greet('Welcome to the awesome generator!')
.confirmBeforeStart('Would you like to use bower?')
.learnPrompts(commonPrompts)
.prompt([
'name',
'description',
'authorName',
'authorEmail',
'authorUrl',
'githubAccount'
], true);
},
writing: function () {
if (this.easily.checkForConfirmation()) {
this.easily
.extendJSONWithTemplate(
'__package.json',
'package.json',
this.props
)
.extendJSONWithTemplate(
'__bower.json',
'bower.json',
this.props
)
.copyFiles('**/*', {
ignore: '**/__*',
dynamicFiles: [
'src/index.html',
'README.md'
],
props: props
})
.composeWithExternal(
'generator-summon/generators/github',
'summon:github',
{
skipGreeting: true,
name: this.props.name,
githubAccount: this.props.githubAccount
}
);
}
},
install: function () {
this.installDependencies();
}
});
More resources
- See full API documentation
- An example generator that uses yeoman-easily heavily is generator-summon
- For convenience, you can use generator-easily instead of the standard generator-generator to create a new generator or subgenerator. The created generator/subgenerator will include code for using yeoman-easily by default.
License
Apache-2.0 © Krist Wongsuphasawat