Yeoman has established itself as the preeminent code generation framework for web developers. This code-focused course shows how to get started with Yeoman with a focus on building your own custom Yeoman generator.
Yeoman has established itself as the preeminent code generation framework for web developers. Yeoman provides a code generator ecosystem that enables best practices and unparalleled productivity. In this course, we'll see how to quickly get up and running with Yeoman. We will then focus on building our own custom Yeoman generator. This will include working with the Yeoman file system, user interactions, creating sub-generators, testing, and more. By the end of this course, you'll be able to start building your own custom Yeoman generators!
Using Yeoman Generators In this module we'll get up and running with Yeoman and we'll start getting comfortable consuming Yeoman generators. The first thing we'll do is to make sure we have Yeoman installed in our development environment and we'll install our first Yeoman generator. Once we have at least one Yeoman generator installed, we can use it to start scaffolding our first app. Yeoman generators are extremely powerful for creating your initial application skeleton on day one, but Yeoman sub-generators are extremely important because you can use them throughout the lifetime of your project to generate individual files and snippets of code. We'll get an introduction to using Yeoman sub-generators in this module as well.
Creating a Yeoman Generator In this module we are going to create our first Yeoman generator. In fact, from here on out we're going to spend the rest of the course building out our custom Yeoman generator. This module will be the first step in that journey. In the first demo I'm going to create the bare bones structure that we need for our first generator. Then I'll show the base classes that you'll need to understand for Yeoman generators. Next I'll show you how you can differentiate between public and private methods in a Yeoman generator. After that we'll explore the Yeoman running context, which is central to understanding the Yeoman execution pipeline. So with that, let's create our first generator.
Working with the File System In this module we're going to get an introduction to working with the file system with our custom Yeoman generator. Given that Yeoman's primary job is to generate files, working with the file system is one of the most important aspects to understand when working with Yeoman. First we're going to understand how Yeoman implements file paths. We'll use this to understand how to copy files in directories. In addition to just copying files, working with templates is an absolutely essential task with Yeoman because we'll commonly generate the contents of these templates to produce code that is compliant with our project. In addition to copying static files and generating files based on templates, we can also generator completely static files. I'll show an example of how to do this. At the end of this module we'll continue to fill in our generator with many of the artifacts that can most commonly be found being produced from Yeoman generators.
User Interactions In this module we're going to look at how user interactions occur within Yeoman. I'm going to start out showing the handy yosay utility. This utility is nice for simply presenting an introduction message to the user, like a title message for your generator. We'll then look at how arguments can be passed in on the command line. I'll then show how to use options with Yeoman. You can think of Yeoman options as command line switches for customizing generator behavior. Then we'll look at prompts and how we can directly collect information from the user. This information can take many forms, from free form text to even lists, where the user can select one or more choices.
Configuration and Dependencies In this module, we're going to examine Yeoman configuration options and dependency management. We're going to start by looking at how we can extend Yeoman prompts to take advantage of storing configuration information. We'll then look at how we can interact with the Yeoman storage API directly for configuration management. We'll then shift to dependency management, and we'll see how we can get our Yeoman generator to automatically install npm and Bower dependencies as part of the generation process. Finally, we'll look at dependencies in the form of generator composition. With generator composition, we can depend on other generators to provide scaffolding operations within our own generator.
Building a Sub-generator In this module we're going to create our first Yeoman sub-generator. Sub-generators are one of my favorite features of Yeoman, because you can use them throughout the lifetime of your project to scaffold individual pieces of your code. A normal Yeoman generator is great for being able to quickly get your application up and running on day one. But sub-generators are the gift that keeps on giving. You can create individual pieces of your app with consistent standards at any time. In this module we'll start out by looking at the folder structure for a sub-generator. Then we'll implement basic functionality of a sub-generator using a template. Once we get the initial implementation in place, we'll start to customize our sub-generator for user preferences. Then we'll continue customizing using command line options.
Testing Generators In this module we're going to create unit tests for our Yeoman generator. I'm going to start out by showing the file structure that you need to have in place for your unit testing. I'll then show how you test to verify that specific files were produced by your generator. Of course, it's nice to test that your files were created, but you'll also want to verify that the contents inside the files are correct. I'll show you how to test that too. Finally I'll show you how you can test conditional behavior depending on what options are being passed into your generator by the user from the command line.