如何构buildMeteor智能包

如何构build一个meteor list中将出现的Meteor智能包 ?

Building Atmosphere软件包是有据可查的 ,但是build立Meteor软件包却不是。

Meteor现在支持一个create --package命令。

查看meteor文档 。

示例(将您自己的meteor开发者帐号replace为“cunneen”):

 meteor create --package cunneen:foo 

输出:

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'); }); 

packages / cunneen:foo / foo.js(空文件)

 // Write your package code here! 

包/ cunneen:富/富-tests.js

 // Write your tests here! // Here is an example. Tinytest.add('example', function (test) { test.equal(true, true); }); 

packages / cunneen:foo / README.md(空文件)

 # cunneen:foo package 

对于一个很好的(非常全面的)例子,看看铁路由器 。

请参阅下面的 cobberboy的答案

以下是过时的信息:

查看有关新型meteor包装系统的信息: https : //meteorhacks.com/meteor-weekly-meteor-09-rc-meteor-new-logo-underscore-in-templates.html

**更旧的信息**

有关于编写自己的软件包和关于重新包装现有的第三方库的更新信息。 虽然API不会稳定到1.0,所以准备做很多改变。

我已经包括锅炉板,以帮助瓦特/一次成为一个节点和一个meteor可用库。 这花了我相当长的一段时间才弄明白,欢迎提出build议。

包:/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'); } 

包:/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'] }); 

meteor应用程序:在正确的客户端/服务器上下文中的一些文件(如package.js中定义的)

 var my = new My('a property'); my.doStuff(); // console logs 'hello world' on the server 

meteor应用程序:smart.json,将您的文件添加到软件包列表

 { packages:{ "node-my": { "git": "git@github.com:myAccount/node-my.git" } } } 

最后在命令行上运行mrt install来安装它。Whew!

注:包开发目前没有logging,API将会改变。 你已经被警告!

也就是说,这实际上很容易开始:

首先,git克隆一个meteor回购的副本。 在/ packages中创build一个新的目录。 将一个package.js文件放在目录中(请参阅其他软件包中的示例)。 现在你有一个包!

接下来,运行您的结帐meteor脚本(不是由安装程序安装)。 从结帐运行时,脚本将在结帐中使用本地软件包目录。 当你改变你的包中的代码时,它甚至会重新加载。

通过其他软件包查看示例,了解API的用途。

编辑:在第三方软件包方面取得了很大进展。 查看http://oortcloud.github.com/meteorite/和https://atmosphere.meteor.com/

EventedMind在这个主题上有一个很好的截屏。

这是2013年6月12日。这是当时正确的答案,而且还是一个替代解决scheme:

像n1mmy说的。 这是无证的,你应该使用陨石。

如果你坚持用meteor创造一个包装,我发现了一个很好的非官方的方法,但你真的不应该这样做。 Meteor将会在即将发布的版本中推出一些软件包。

构buildmeteor包: https : //coderwall.com/p/ork35q

我会这样做的方式是与陨石

显然你有节点,我假设你有节点包pipe理器(NPM),所以你最好的方式来做meteor包到目前为止,是做一个陨石的智能包。

 npm install meteorite 

陨石智能包包含2个关键的文件创build必不可less – package.js – smart.json

陨石文件存储在您的系统下login用户帐户:〜/ .meteorite /
但符号链接到您当前创buildmeteor应用程序的地方: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'); }); 

示例smart.json

 { "name": "User analytics", "description": "User Analytics", "homepage": "http://yourHomepage.com", "author": "Eric Leroy", "version": "0.1", "git": "https://github.com/yipyo", "packages" : {} } 

如果你需要更多的信息,你应该从列表中安装一个mrt包:

 mrt list 

然后分析你的app / .meteor / meteorite /目录下的文件。

希望这有助于,并继续发展未来最好的语言。

这里有一些有用的链接:

  • http://www.eventedmind.com/ – 杰出的教程解释meteor的核心概念
  • 发布Atmosphere包
  • 非官方meteor常见问题
  • 与meteor制作聊天室应用程序