0.4.1 • Published 9 years ago

yeoman-easily v0.4.1

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
9 years ago

yeoman-easily NPM version Build Status Dependency Status Coverage percentage

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 call easily.prompt(prompts) instead of the this.prompt(prompts, ...) - Can automatically skip prompts if an option with the same name is present. It will instead copy the value of existing this.option[field] into this.props[field]. - Can register common prompts via easily.learnPrompts(prompts) and allow looking up prompts by name while calling easily.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) and easily.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 wraps this.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

License

Apache-2.0 © Krist Wongsuphasawat

0.4.1

9 years ago

0.4.0

9 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1-2

10 years ago

0.0.1-1

10 years ago

0.0.1-0

10 years ago