SharePoint Framework development tips: create shortcut(s) for your common SharePoint Framework generator commands

This is a small tip for anybody who hates typing yo @microsoft/sharepoint because it's too long and error-prone (or you're lazy like me :)). Check out below animation: 

What if we can simply type sp in order to scaffold the project? Well, we are in 2019 and of course, it's possible :) 

NOTE: Solution windows users only. Sorry MacOs :(. I'm pretty sure there is an alternative for Mac as well, but I'm not a Mac user.

 Create a new .cmd file with your desired command

You can go ahead and create a new folder in your user's directory or simply in drive's root, for example, c:\Aliases. Now create a new file called sp.cmd inside that folder. 

Put any commands you need in that file, i.e.:

yo @microsoft/sharepoint

or something more sophisticated like 

yo @microsoft/sharepoint --framework "react" --component-type "webpart" --skip-install --environment "spo" --skip-feature-deployment true

Add your path to system environment variables

Now to make your command available globally in any console you should update your Path environment variable with just created path, i.e. c:\Aliases

Open Edit the system environment variables dialog:

Click on Environment Variables:

Then you will have an option to edit current user variables or system (these changes will be applied to all users). Let's edit system variables:

Click on New to create a new variable and insert a path to your folder, c:\Aliases in my case:

We've done!

Let's test it

Now open any command prompt and type sp. As a result, yo @microsoft/sharepoint command will be executed. The good thing is that you can create as many additional files inside that directory as you wish. For example, add a new file called sp-react.cmd and insert:

yo @microsoft/sharepoint --framework "react" --component-type "webpart" --skip-install --environment "spo" --skip-feature-deployment true

which scaffolds new react spfx web part. You don't even have to reopen your cmd, simply run sp-react in command prompt and you web part will be scaffolded. 

As you see, you can use the same approach for other types of aliases, not only for SPFx ones.