Giter VIP home page Giter VIP logo

yogini's Introduction

yogini

npm version

yogini is a prompt-driven scaffolding system. It makes it easy to create and maintain personal boilerplates that evolve over time.

What makes yogini different?

  • Prompt-driven (via Inquirer) with simple, declarative prompt configuration (example)
  • Embedded file-copying logic (via prefixnotes), e.g. {useSass}main.scss
  • Templating with striate, a superset of ejs with better handling of multi-line blocks

Generators created by yogini are yeoman generators, so they can be published and consumed like any other yeoman generator. You do not need to understand yeoman to use yogini.

Install

npm install -g yo                 # install yeoman
npm install -g generator-yogini   # install yogini

Quick Start

1. Create your generator

mkdir generator-mygen             # create a directory for your new generator
cd generator-mygen            
yo yogini                         # generate a blank yogini generator
npm link                          # alias your generator to your globally
                                  # installed npm modules so that you can run
                                  # it with yeoman.

2. Use your generator

mkdir mygen1                      # create a directory for your new project
cd mygen1
yo mygen                          # generate a new project

Architecture

Would you like some generator with your generator?

yogini features a 4-level architecture:

  • yo - Ye ol' scaffolding framework. Does all the hard work, like a good yeoman. Kind of a pain to work with as a developer.
  • yogini - Ye fancy yo wrapper that makes it easier to create, evolve, and maintain your generator.
  • generator-mygen - Your personal generator. Name it whatever you want. Typically you'll have a single generator and use its powerful conditional prompts to control which files are copied for the desired project type.
  • mygen1 - A cute little offspring from generator-mygen. A fresh, new project!

Building your generator

An initial yogini generator produces only a blank README, so you have to customize it to generate something useful.

TLDR;

  • Drop files into app/templates. All files from this directory will be copied into your project directory when you run the generator.
  • Edit the Inquirer prompts in app/yogini.json. These will determine which files get copied (via prefixnotes) and what code gets copied (via striate).

1. Yogini file

Sample yogini.json file:

{
  "prompts": [
    {
      "type": "confirm",
      "name": "js",
      "message": "Does your project use Javascript?",
    },
    {
      "type": "confirm",
      "name": "css",
      "message": "Does your project use css?",
    }
  }
}

The above yogini.json file would prompt you with two questions every time you run your generator and store the answers in js and css variables. These variables drive the main two aspects of scaffolding: file copying and templating.

Advanced

You can use a yogini.js file and define a parse function which allows you to transform or add to the user-provided answers to the prompts:

module.exports = {

  parse: (answers, prompts) => ({
    authorName: 'Raine Revere',
    authorUrl: 'https://github.com/raineorshine',
    license: 'ISC',
    username: 'raineorshine',
    ...answers,
    camelize,
    prettyArray,
  }),

  prompts: [
    ...
  ]

}

The prompts field also accepts a function which gets passed the generator instance:

{
  "prompts": ({ env }) => [
    {
      "type": "text",
      "name": "directory",
      "default": env.cwd
    }
  }
}

2. File Copying

You can control which files in /app/templates get copied into your new project by prefixing filenames with expressions that include prompt variables.

.
├── index.html
├── {js}scripts
│   └── main.js
└── {css}styles
    └── main.css

In the above example, the scripts folder will only be copied if js (as declared in yogini.json) is true, and the styles folder will only be copied if css is true.

  • Empty expressions are a great way to include system and hidden files in your templates folder without them having an effect until they are copied:

    • {}package.json
    • {}.gitignore
  • If a folder name only consists of an expression, all files will be copied to the parent folder:

    main.js
    {js}
      ├── 1.js
      ├── 2.js
      └── 3.js

          ⇨

    main.js
    1.js
    2.js
    3.js
  • Expressions can be any Javascript expression that evaluates to boolean:

    {js && gulp}gulpfile.js

See prefixnote for the nitty-gritty.

3. Templating

yogini uses striate, a superset of ejs, to control which code gets generated within the files. The answers given to the prompts in yogini.json are available as variables within the scope of your template files.

<!DOCTYPE html>
<html>
<head>
  >> if(css) {
  <link rel='Stylesheet' type='text/css' href='styles/main.css'>
  >> }
</head>
<body>
  >> if(js) {
  <script src='scripts/main.js'></script>
  >> }
</body>
</html>

You can see a complete yogini generator with prompts, file prefixes, and templating at generator-yogini-sample.

License

ISC © Raine Revere

yogini's People

Contributors

raineorshine avatar gitter-badger avatar

Stargazers

Jonathan Ling avatar Nace Logar avatar Sabin Tudor avatar Iain Simmons avatar  avatar Edwin Zaniar Putra avatar Kevin Suggitt avatar Alexander Romano avatar Peter MacDonald avatar Blake E avatar Nick McCurdy avatar Tyler Trotter avatar Stephen Richardson  avatar Christian Bagley avatar Mitchell Wulfman avatar

Watchers

James Cloos avatar  avatar

yogini's Issues

broken with yo v1.5.0

I came here for a simple generator sample. When I install Yoga using yo version 1.5.0 I get the following:

? 'Allo Mark! What would you like to do? Yoga

Make sure you are in the directory you want to scaffold into.
This generator can also be run with: yo yoga

No yoga file found. Proceeding with simple copy.

     _-----_
    |       |    .-----------------------.
    |--(o)--|    |      Bye from us!     |
   `---------´   |       Chat soon.      |
    ( _´U`_ )    |      Yeoman team      |
    /___A___\    |    http://yeoman.io   |
     |  ~  |     '-----------------------'
   __'.___.'__   
 ´   `  |° ´ Y ` 

events.js:141
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'prompts' of undefined
    at module.exports.generators.Base.extend.prompting (/home/mark/.node/lib/node_modules/generator-yoga/app/index.js:81:40)
    at /home/mark/.node/lib/node_modules/generator-yoga/node_modules/yeoman-generator/lib/base.js:429:16
    at processImmediate [as _immediateCallback] (timers.js:383:17)
mark@ichikawa:~/devel/bee-do/research/yeoman/exp_yoga$ yo --version
1.5.0

Remove files

I have a boilerplate that works in the opposite of usually.
I have a full package where i replace stuff but also i need to delete files from it, so there is a way from the json file to remove a file that option is not flagged?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.