It's really useful that we can create new packages directly inside the packages folder of our projects. It can be a useful way to organize individual projects and it also lets us prototype new packages really quickly in the context of an application. But what if we want to reuse our package across projects or make it available to other people? In this episode, I'm going to show you how we can use Git and GitHub to manage packages.
So the first thing I want to do is pull out the package from this project and move it into its own directory. I'll move it into a folder called Custom Packages. And then let's change into that folder. The next thing I'll do is initialize an empty Git repository. And then I'll add my files to it and make my first commit.
Next we'll jump over to GitHub and create the repository. In GitHub I'll double click the New Repository button and I'll call this repository meteor file. And for now I'll make it a private repository. And I'll click Create Repository.
Next I'll grab the git address and head back to our project and add this as a remote. We'll call it Origin and pass the address. And then I'll make my first push to GitHub.
Next, it can be useful to tag our project with versions. So we can tag a particular commit by using the git tag command. And in this case, this is the first sort of beta release. And so we'll tag this is version 0.0.1. And if I type git tag, I can see all of the tags in my project. And now I'll push to GitHub again, but I'll use the tag switch to send up all of the tags as well.
Over in GitHub, once you refresh the page, you can see the project files have been pushed successfully. And if I click over on the tags link, I can see that I have one tag called version 0.0.1.
And so now what we want to do is we want to use the meteor file package in a project. I've navigated back into the file uploader application and I've removed the meteor file package from the packages directory. Meteor doesn't have an official way to publish packages or distribute packages yet. So I'm going to show you how we can use GitHub.
Now one way we can do this is by just downloading the package from GitHub and copying it into the packages directory. But there's a better way that I've found to be pretty useful in my own projects. The first thing I'm going to do is just create a new empty Git repository for my project and add the files and make my first commit.
And the next thing I'm going to do is use git submodule to add another Git repository as a submodule of this one. I'll type git submodule add and then pass the address of the GitHub repository and then where I want it to go. Now if I change into my packages directory, I should see the meteor file project in there.
And one of the cool things about git submodules is that I can use Git commands within the meteor packager or within the submodule itself. So for example, I might say git status or take a look at the tags. And if I wanted to use a particular version or a commit for a particular tag, I could say git check out version 0.0.1. And so this isn't necessarily the cleanest way to deal with versioning, but this lets me clone packages from GitHub very easily and then check out various versions that I want to use for my project.
So let's navigate back into the main project directory and start our meteor server and make sure that we're still able to use the meteor file package. And to make sure it's still working, let's try adding some files and clicking the Upload button. And if I look at my uploads directory, it looks like the files were uploaded successfully.
So even though Meteor doesn't have an official way to publish packages yet, this episode showed how we can just use GitHub and Git to reuse our packages across our own projects or make them available to other people.