cob*_*boy 21
Meteor现在支持create --package命令.
请参阅流星文档.
示例(用您自己的流星开发者帐户替换"cunneen"):
meteor create --package cunneen:foo
Run Code Online (Sandbox Code Playgroud)
输出:
cunneen:foo: created in your app
结果:
包/ cunneen:富/ package.js
Package.describe({
name: 'cunneen:foo',
version: '0.0.1',
// Brief, one-line summary of the package.
summary: '',
// URL to the Git repository containing the source code for this package.
git: '',
// By default, Meteor will default to using README.md for documentation.
// To avoid submitting documentation, set this field to null.
documentation: 'README.md'
});
Package.onUse(function(api) {
api.versionsFrom('1.0.3.1');
api.addFiles('cunneen:foo.js');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('cunneen:foo');
api.addFiles('cunneen:foo-tests.js');
});
Run Code Online (Sandbox Code Playgroud)
packages/cunneen:foo/foo.js(空文件)
// Write your package code here!
Run Code Online (Sandbox Code Playgroud)
包/ cunneen:富/富-tests.js
// Write your tests here!
// Here is an example.
Tinytest.add('example', function (test) {
test.equal(true, true);
});
Run Code Online (Sandbox Code Playgroud)
packages/cunneen:foo/README.md(空文件)
# cunneen:foo package
Run Code Online (Sandbox Code Playgroud)
对于一个好的(非常全面的)示例,请看一下铁路由器.
Mik*_*raf 14
以下是过时的信息:
有关新的流星包装系统的信息,请访问:https: //meteorhacks.com/meteor-weekly-meteor-09-rc-meteor-new-logo-underscore-in-templates.html
**旧信息**
有关于编写自己的包以及重新打包现有第三方库的更新信息.虽然API在1.0之前不会稳定,所以要做好许多改动的准备.
我已经包含了锅炉板,以帮助它同时使它成为一个节点和一个流星可用的库.这花了我很长时间才弄明白,接受建议.
包:/lib/my.js
if (typeof Meteor === 'undefined) {
// Not Running In Meteor (nodejs code)
// example NPM/Node Dependencies that we'll use
var async = require('async');
var debug = require('debug')('my:package');
var mongodb = require('mongodb');
var http = require('http');
} else {
// Running as Meteor Package
var async = Npm.require('async');
var debug = Npm.require('debug')('my:package');
var mongodb = Npm.require('mongodb');
// node core module 'http'
// use Npm.require to require node core modules
// but doesnt need Npm.depends in the package.js file
var http = Npm.require('http');
}
var constructor = function(property1) {
this.property1 = property1; // or whatever in your constructor.
};
if (typeof Meteor === 'undefined') {
// Export it node style
My = exports = module.exports = constructor; // Limit scope to this nodejs file
} else {
// Export it meteor style
My = constructor; // Make it a global
}
// Proceed defining methods / properties as usual.
My.prototype.doStuff = function() { console.log('hello world'); }
Run Code Online (Sandbox Code Playgroud)
包:/package.js
Package.describe({
summary: "My Meteor Package"
});
/**
* Ex: Some NPM Dependencies
*/
Npm.depends({
'async': '0.2.9',
'debug': '0.7.2',
'mongodb': '1.3.18'
});
/**
* On use we'll add files and export our tool
*/
Package.on_use(function (api) {
/**
* Add all the files, in the order of their dependence (eg, if A.js depends on B.js, B.js must be before A.js)
*/
api.add_files([
'lib/my.js' // <-- include all the necessary files in the package
],
'server'); // Can be 'server', 'client' , ['client','server']
/**
* Only expose the My constructor, only export if meteor > 0.6.5
*/
api.export && api.export(['My'], 'server'); // 1st arg can be array of exported constructors/objects, 2nd can be 'server', 'client', ['client', 'server']
});
Run Code Online (Sandbox Code Playgroud)
meteor app:正确的客户端/服务器上下文中的一些文件(在package.js中定义)
var my = new My('a property');
my.doStuff(); // console logs 'hello world' on the server
Run Code Online (Sandbox Code Playgroud)
meteor app:smart.json,将你的文件添加到包列表中
{
packages:{
"node-my": {
"git": "git@github.com:myAccount/node-my.git"
}
}
}
Run Code Online (Sandbox Code Playgroud)
最后mrt install在命令行上运行,让它安装包.. 哇!
n1m*_*mmy 13
注意:程序包开发目前未记录,API将更改.你被警告了!
这就是说,它实际上很容易上手:
首先,git克隆流星回购的副本.在/ packages中创建一个新目录.将package.js文件放在目录中(有关示例,请参阅其他包).现在你有了一个包裹!
接下来,从结帐中运行meteor脚本(不是安装程序安装的脚本).从结帐运行时,脚本将使用结帐时的本地包目录.当您更改包中的代码时,它甚至会重新加载.
查看其他软件包中的示例,并了解API的功能.
编辑:在第三方包方面取得了很大进展.查看http://oortcloud.github.com/meteorite/和https://atmosphere.meteor.com/
这是在2013年6月12日.这是当时的正确答案,仍然是一个替代解决方案:
就像n1mmy说的那样.它没有记录,你应该使用陨石.
如果你坚持用流星创建一个包,我发现了一个很好的非官方操作方法,但你真的不应该这样做.Meteor将推出一种在即将发布的版本中创建软件包的方法.
Bulding Meteor包:https: //coderwall.com/p/ork35q
我这样做的方法是使用陨石
显然你有节点,我假设你有节点包管理器(npm),所以你制作流星包的最佳方法是制作一个陨石智能包.
npm install meteorite
Run Code Online (Sandbox Code Playgroud)
Meteorite智能软件包包含2个创建软件包所必需的密钥文件 - package.js - smart.json
陨石文件存储在您的系统登录用户帐户下:〜/ .meteorite/
但符号链接到您创建流星应用程序的当前位置:project/.meteor/meteorite /
示例package.js:
Package.describe({
summary: "User analytics suite for meteor"
});
Package.on_use(function (api) {
api.add_files('user_analytics.js', 'client');
});
Run Code Online (Sandbox Code Playgroud)
示例smart.json
{
"name": "User analytics",
"description": "User Analytics",
"homepage": "http://yourHomepage.com",
"author": "Eric Leroy",
"version": "0.1",
"git": "https://github.com/yipyo",
"packages" : {}
}
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,您应该从列表中安装mrt包:
mrt list
Run Code Online (Sandbox Code Playgroud)
然后分析app/.meteor/meteorite /目录下的文件.
希望这会有所帮助,并继续开发未来的最佳语言.
以下是一些有用的链接: