Yeoman for beginners

  • Tutorial


There are such programs and utilities, using which the user cries out: “I don’t know how I could live without this tool before!” In my opinion, the Yeoman console utility  , written in Node.JS , belongs to the category of such indispensable tools. Why?

So, for starters, let's decide which program code Yeoman generates .

There is such a concept in programming - scaffolding (from the English scaffold - "scaffolding"). It means the automatic construction of the project structure. I could be wrong, but as memory suggests, it was first used in Ruby on Rails . There was a special team in Rails that generated code for controllers and models.

What is the essence of this function? The work of a programmer outside of creative take-offs and ingenious research is quite the same. It most often consists in making your own corrections to the implementation of the desired functionality in the already established framework of the library, framework or engine.

Thus, the first step in creating something new in any system is to reproduce the basic template of one or another design, which is laid in its foundation. For example, if you build your site within the framework of the chosen framework, for example Laravel in PHP , you will create controllers, models, migrations, seeders and so on in any way.

What do the generators built into the framework offer us? Get rid of the routine operation of duplicating source texts. However, this ability to generate a framework of application parts is not integrated into every system. Needless to say, in such popular old-timers like WordPress there is nothing like this yet.

Therefore, in the summer of 2012 the world saw the application, which is discussed in this material.

Meet:



The program site is quite informative:
http://yeoman.io
On it you can find a lot of useful information.
Here, for example, is a typical setup scheme for a modern developer’s workspace:



  • Generate application skeleton using Yeoman
  • Install additional scripts using Bower
  • We start the web server and related useful utilities using Grunt (or Gulp , which was written about a couple of days ago )

Let’s learn the basics of working with Yeoman so that anyone who has not yet seen this program in action would understand its need for a daily workflow.

Installation


In short, our faithful helper is called yo .
Therefore, its installation is as follows:

 sudo npm i -g yo # сокращённо npm install yo -g

 You must execute this code, as you already understood, in the terminal window:



That's it, the installation is complete on this.
Let's run this program now and see what it can do.

Beginning of work


Since we used the option  -gwhen installing from the package manager  npm, our faithful assistant YeoMan  installed globally. That is, it can be called from anywhere, whatever the current directory of your Terminal is.
Otherwise, you would have to run the program only from the directory in which the installation program was run.

We start the program by simply calling the command  yoin the Terminal and see what it can do:



As you can see,  YeoMan  meets the author of the article, greeting by name. Further, the program suggests launching one of the previously installed generators.
About how they are installed, a little later.
Let's choose one of them for a while and see how it works.
Starting the WordPress Generator :



This generator installs the latest version of WordPress.
Before installation, he asks us to answer a number of questions - the site address, database settings, and so on:



Installing the latest version from Git :



Writing files:



Shutting down:


Thus, in  less than a minute , Yeoman did the work that we used to spend at least a few minutes and many mouse clicks on.

Generator Installation


As you can see from the above, Yeoman is just a shell, an interface that implements a variety of generators.
How to search and install the generators themselves?
It is possible through the official website:



http://yeoman.io/generators/
And it is also possible through the console:




Conclusion


The purpose of this publication was to demonstrate the work of  Yeoman  and to awaken the reader's interest in automating the development process. Indeed, in the end, the more you think about optimization and use useful tools, the more free time you have for personal needs.
Let that part of the work, the time of which we can spend on the family, be done by machines. And  Yeoman  is a great helper in this regard.
Study, try, rejoice with us.
The official website of the program:
http://yeoman.io

PS The material is intended for those who have not yet used Yeoman for any reason.
If you use this program, please comment in the comments about your preferences and experience working with it - it will be useful for everyone to find out.

Also popular now: