2012-04-11 93 views

回答

20

流星现在支持create --package命令。

参见the meteor docs

例(替换自己meteor developer account为 “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'); 
}); 

包/ cunneen:富/ foo.js(空文件)

// Write your package code here! 

包/ cunneen:富/ FOO-tests.js

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

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

# cunneen:foo package 

对于一个好的(非常全面的)例子,看看iron-router

+1

'mrt create-package'似乎过时了。使用'流星创造 - 包装包名称' – 2015-07-19 12:31:06

+0

谢谢@JonathanAzulay,我已经更新它。 – cobberboy 2015-07-20 03:46:18

13

注意:软件包开发目前没有记录,API将会更改。你已被警告!

这就是说,它实际上很容易上手:

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

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

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

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

+0

这将是一个非常棒的npm类似的工具;)我正在寻找一种方法来导入我的Meteor项目中的http://momentjs.com/。访问这个库客户端/服务器端的最佳解决方案是什么?感谢您的出色工作! – LarZuK 2012-04-11 23:04:59

+0

令人惊叹! app_root/lib/moment.js和...那就坐?只是......很棒......我没有在doc中找到它,不是吗? – LarZuK 2012-04-11 23:13:16

+1

@ n1mmy我克隆了github的repo,进入了克隆的'meteor'文件夹,下载了一个自定义的jquery构建,并将生成的js文件放入'packages'内的新子文件夹中。我从现有的'jquery'包中复制/粘贴'package.js'文件并编辑它的内容以反映我自定义的'jquery'build的名称。接下来,我进入了我的克隆“流星”文件夹的根目录,并运行了'。/ meteor',并在'dev_bundle.'中获得了'Installed dependency kit v0.1.4'。到现在为止还挺好。但是运行'meteor list'不会显示我的新软件包。思考? – Webdevotion 2012-05-03 07:03:21

6

这日期是6月12日2013年。这是当时的正确答案,仍然是一个替代的解决方案:

就像n1mmy说。它没有证件,你应该使用陨石。

如果你坚持用流星创建一个包装,我发现了一个很好的非官方的方法,但你真的不应该这样做。 Meteor将在即将发布的版本中提供一种创建软件包的方式。

BULDING流星包: https://coderwall.com/p/ork35q

我会做的方式,它是陨石

很明显,你有节点,我假设你有节点包管理器(NPM),所以最好迄今为止制作流星包的方法,就是制作一个陨石智能包。

npm install meteorite 

陨石智能包包含用于创建包 必不可少的两个关键文件 - package.js - smart.json

陨石文件存储在系统登录的用户帐户下:〜/ .meteorite/
但符号链接到您的当前,你创建了一个流星应用:项目/ .meteor /陨石/

样品package.js:

Package.describe({ 
    summary: "User analytics suite for meteor" 
}); 

Package.on_use(function (api) { 
    api.add_files('user_analytics.js', 'client'); 
}); 

样本聪明。JSON

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

如果你需要的信息了,你应该从列表中安装一个地铁包:

mrt list 

然后分析你的应用程序/ .meteor /陨石/目录下的文件。

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

下面是一些有用的链接:

+0

'mrt list'实际上将'list'命令传递给'meteor',所以你会得到智能包,而不是“mrt包”(即那些在大气中) – 2014-01-24 05:50:33

14

见cobberboy的answer below

下面是过时的信息:

见有关流星包装系统信息: https://meteorhacks.com/meteor-weekly-meteor-09-rc-meteor-new-logo-underscore-in-templates.html

**旧的信息**

有是更新的信息关于writing your own package和约repackaging existing 3rd party libraries。虽然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'); } 

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

流星应用程式:在适当的客户机/服务器环境中的一些文件(如package.js中定义的)

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

流星应用:smart.json,你的文件添加到列表包

{ 
    packages:{ 
     "node-my": { 
      "git": "[email protected]:myAccount/node-my.git" 
     } 
    } 
} 

最后运行mrt install在命令行上得到它的安装包.. 呼!

+1

应该先运行'mrt add node-my' 'mrt' – zhaoyou 2014-02-08 09:37:45

+0

我没有看到如何在引用的链接上创建软件包的清晰文档。目前在某个地方做这件事的方式是否有很好的参考? – 2014-12-08 00:36:04

+2

请参阅下面的@cobberboy回答。 OP请将cobberboy所接受的答案更改为该答案。 – 2014-12-09 00:35:06