If you have followed my last tutorial how to create a custom yeoman generator you are probably asking yourself how to make your yeoman generator public available for everyone. The solution for this is a node package module, which everyone can install via npm install yourpackage. As I don’t want to setup a useless project, I will explain how to submit a package by having a look at one of my generators, the Python Bottle generator for yeoman. You can find the sources at github.
Setup your NPM account
If you have never published anything to npm, you need to setup your credentials first. So first, add these information and add a user. You will be asked for some more details when you enter the last line, so fill out all the needed fields.
npm set init.author.name "My name" npm set init.author.email "email@example.com" npm set init.author.url "http://epicpage.com" npm adduser
Setup the npm files
First of all, navigate to the top level of your project and start a new module with:
This will ask you for many things about the project, like the name, description, license and git repository. Enter the details and a package.json will be created for you. Now take a look at my Python Bottle generator package.json. Make sure you have entered the correct git repository URL and the “main” file is declared correctly. In my case, it will run the app/index.ejs which is the main file of the yeoman-generator.
It’s important for a yeoman-generator to have the “yeooman-generator” added as a keyword. More information on yeoman.io
Check if everything is fine and submit
To see if there are missing dependencies, you can install another little helper:
npm install -g pakmanager
The pakmanager will help you to check your npm project for missing or useless dependencies. So run it once:
Inspect the output, and if there are errors add the missing dependencies or remove if there are unused imports. If everything is finished, you can submit your package:
npm publish ./
Congratulations on your first published node package module!
If you encounter any problems leave me a comment and don’t forget to follow me on twitter @schlimmson
Get the free 7 day Ionic 4 Crash Course to learn how to:
- Get started with Ionic
- Build a Tab Bar navigation
- Make HTTP calls to a REST API
- Store Data inside your app
- Use Cordova plugins
- Style your Ionic app
The course is free, so there's nothing you can lose!