Introduction to Meteor Packages
In this post, I create and publish a simple Meteor Package.
My package is color-hex-rgb on github and on atmospherejs.
Contents
-
Create package
-
Implement
-
Test
-
Publish
-
Further Information
1. Create package
meteor create --package
creates a default package.
A Meteor Developer Account is needed in order to run this command
successfully.
remy
is my Meteor Developer Account.
color-hex-rgb
is the package name.
meteor create --package remy:color-hex-rgb
2. Implement
An empty color-hex-rgb.js
is created. I implement 2 functions: hexToRgb and
rgbToHex.
cd color-hex-rgb
vi README.md
vi package.js
vi color-hex-rgb.js
In package.js
, the public functions are declared in Package.onUse:
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.use('ecmascript');
api.addFiles('color-hex-rgb.js');
api.export('hexToRgb');
api.export('rgbToHex');
});
3. Test
In this section, I only test the package in a simple meteor app.
- I create a new app color-hex-rbg-test
- In color-hex-rbg-test, I create the
packages
folder and link with an absolute path my package - I add my package to the app
meteor create color-hex-rbg-test
cd color-hex-rbg-test
mkdir packages
ln -s /Users/remynoulin/meteor/color-hex-rgb packages/remy:color-hex-rgb
meteor add remy:color-hex-rgb
4. Publish
A single command publishes the package:
meteor publish --create
Once a packate version is published, it is possible to update the metadata with the –update:
meteor publish --update
After the package is published, it becomes visible in meteor search
, meteor show
and atmospherejs.
meteor search color-hex-rgb
meteor show remy:color-hex-rgb
meteor show remy:color-hex-rgb@0.0.1
5. Further Information
https://atmospherejs.com/i/publishing