packagist 源_在Packagist for Composer上列出软件包

packagist 源

By now I’m sure you’ve seen first-hand how Composer can help manage dependencies; I’ve grown quite fond of it myself, using it for the downloadable code samples on GitHub for our articles. Readers can peruse through just the relevant source code on GitHub if they like, and a quick git clone and composer install can get them the code and all the dependencies necessary to play with the code locally. But what about taking it to the next level?

到目前为止,我确定您已经亲眼目睹了Composer如何帮助管理依赖关系。 我本人对此非常喜欢,将其用于GitHub上可下载的代码示例以用于我们的文章。 读者可以根据需要仔细阅读GitHub上的相关源代码,快速进行git clonecomposer install可以为他们获取代码以及在本地使用该代码所必需的所有依赖项。 但是,将其提升到一个新水平呢?

You’ve created an awesome library, and now you’re ready to open source it and share it with the world. Hopefully someone else can benefit from your work, and maybe you’ll even receive a bug report or patch to make the library even better. But none of that can happen unless people can find it… and the modern way is increasingly becoming through Composer and Packagist.

您已经创建了一个很棒的库,现在可以将其开源并与世界分享。 希望其他人可以从您的工作中受益,也许您甚至会收到错误报告或补丁,以使库变得更好。 但是除非人们找到了,否则这一切都不会发生……而且现代方法正越来越通过Composer和Packagist成为。

In this article I’ll show you what information is needed in your composer.json file and how to list your library on Packagist so others can easily find it.

在本文中,我将向您展示composer.json文件中需要哪些信息,以及如何在Packagist上列出您的库,以便其他人可以轻松找到它。

composer.json文件 (The composer.json File)

Composer’s documentation states that every project is a package. Indeed, your project is just an anonymous package in the eyes of Composer, whether it’s a library, full-fledged application, or whatever else in between.

Composer的文档指出,每个项目都是一个程序包。 实际上,在Composer看来,您的项目只是一个匿名程序包,无论它是库,成熟的应用程序,还是介于两者之间的任何其他程序。

As soon as you have a composer.json in a directory, that directory is a package. […] The only difference between your project and libraries is that your project is a package without a name.

在目录中一旦有了composer.json,该目录就是一个包。 […]您的项目和库之间的唯一区别是您的项目是一个没有名称的程序包。

So, an important first step is to set a name for your package. Package names are made by combining a vendor name and project name, for example psr/log or laravel/framework. What should you use as your vendor name? A good choice is your GitHub username.

因此,重要的第一步是为您的包裹设置一个名称。 软件包名称是通过组合供应商名称和项目名称来形成的,例如psr / loglaravel / framework 。 您应该使用什么作为供应商名称? 一个不错的选择是您的GitHub用户名。

While that’s all you really need, it’s a good idea to specify some addition information in your library’s composer.json file, such as a brief description of the package, its homepage, the license, and author information.

尽管这是您真正需要的全部,但是最好在库的composer.json文件中指定一些附加信息,例如对该软件包的简短说明,其主页,许可证和作者信息。

"name": "tboronczyk/testlib",
"description": "A simple test library",
"homepage": "https://github.com/tboronczyk/testlib",
"license": "WTFPL",
"authors": [
    {
        "name": "The TestLib Team",
        "homepage": "https://github.com/tboronczyk/testlib/graphs/contributors"
    }
]

I’ve seen many project list multiple individual entries for each author, probably since this is what’s presented in the documentation as an example, but I prefer the above practice of listing the name as a team and providing a link to the contributors graph on GitHub, this way everyone receives credit and you won’t have to constantly update your composer.json file.

我已经看到许多项目为每个作者列出了多个单独的条目,可能是因为这是文档中作为示例提供的内容,但是我更喜欢上面的做法,将名称作为一个团队列出并提供指向GitHub上的贡献者图的链接,这样每个人都会获得好评,您将不必不断更新composer.json文件。

It’s also important to specify the requirements for your library. We’re familiar with the require section as a place to list other packages our code depends on, and obviously this doesn’t change if your library has third-party dependencies. But it can also be used to specify “platform packages”.

指定库的要求也很重要。 我们很熟悉require部分,因为它可以列出我们的代码所依赖的其他软件包,并且如果您的库具有第三方依赖项,那么这显然不会改变。 但是它也可以用来指定“平台软件包”。

Platform packages are not actual packages that are installable through Composer, but rather a means of specifying requirements for the execution environment, such as the minimum version of PHP needed, or any PHP extensions that are needed.

平台软件包不是可通过Composer安装的实际软件包,而是一种指定执行环境要求的方法,例如所需的最低PHP版本或所需的任何PHP扩展。

"require": {
    "php": ">=5.3",
    "ext-zip": "*",
    "ext-fileinfo": "*",
    "phpunit/phpunit": "3.1.*"
}

在Packagist上上市 (Listing on Packagist)

Once you have your library’s code committed to GitHub, you’ll want to list it on Packagist so others can find it and easily download it. Luckily, Packagist makes it super easy to advertise your library. Go to packagist.org and click the giant green Submit Package button in the top right corner. If you’re not logged in already, you’ll be taken to a login form first, but ultimately you’ll end up on the package submission page.

将库的代码提交到GitHub后,您将希望在Packagist上列出它,以便其他人可以找到它并轻松下载。 幸运的是,Packagist可以非常轻松地为您的图书馆做广告。 转到packagist.org ,然后单击右上角的绿色巨型提交包按钮。 如果您尚未登录,将首先进入登录表单,但最终您将进入包提交页面。

packagist-1

Enter the URL to your project on GitHub and click the Check button. Packagist will validate the address and then provide you with a giant Submit button to click. Voila! It’s as simple as that.

输入您在GitHub上的项目的URL,然后单击“检查”按钮。 Packagist将验证地址,然后为您提供一个巨大的Submit按钮以供单击。 瞧! 就这么简单。

Packagist crawls your GitHub repository for branches and the composer.json file, and displays the information on your library’s package page.

Packagist会在GitHub存储库中搜寻分支和composer.json文件,并在库的包页面上显示信息。

packagist-2

Allow me to bring your attention to the notice on the package page that warns the package is not auto-updated because you don’t have the Packagist hook enabled on GitHub. Auto updating is a good thing since Packagist will make the latest revisions available as you update your code and commit it to GitHub. So, let’s get this taken care of.

请允许我引起您注意软件包页面上的通知,该通知警告该软件包不会自动更新,因为您没有在GitHub上启用Packagist挂钩。 自动更新是一件好事,因为Packagist将在您更新代码并将其提交到GitHub时提供最新的修订。 所以,让我们照顾好它。

First, click the link that’s your username at the top right corner of Pacakgist to go to your account page. There you’ll find your API token, and brief instructions on setting up the Service hook.

首先,点击Pacakgist右上角的用户名链接,以转到您的帐户页面。 在这里,您将找到您的API令牌,以及有关设置服务挂钩的简要说明。

Second, head over to your repository’s page on GitHub and click the Settings menu item.

其次,转到GitHub上存储库的页面,然后单击“设置”菜单项。

packagist-3

Select Service Hooks from the side menu, pick Packagist from the list of hooks, and then supply your information in the form. You’ll definitely need to provide your API token that was listed on your Packagist account page, and your username on Packagist if it isn’t the same as your GitHub username, but you can leave the Domain field blank. Then click the checkbox labeled “Activate” and submit the details.

从侧面菜单中选择“服务挂钩”,从挂钩列表中选择Packagist,然后在表格中提供您的信息。 您绝对需要提供在Packagist帐户页面上列出的API令牌,以及如果您的用户名与GitHub用户名不同,则在Packagist上提供用户名,但您可以将Domain字段保留为空白。 然后单击标记为“激活”的复选框并提交详细信息。

packagist-4

结论 (Conclusion)

Listing your package on Packagist so that it can be downloaded easily through Composer by other developers is easy, although many people might think it difficult because they’ve never done it before. Hopefully this article will help you take your Composer usage to the next level, because it really is little more than providing a name for the package and clicking a giant green button. Now go on, share that great code you’ve been working so hard on with the rest of the world!

在Packagist上列出您的软件包,以便其他开发人员可以通过Composer轻松下载该软件包,尽管许多人可能认为这很困难,因为他们以前从未这样做过。 希望本文将帮助您将Composer的使用提高到一个新的水平,因为它实际上只不过是为软件包提供名称并单击一个巨大的绿色按钮。 现在继续,与世界其他地方分享您一直在努力工作的出色代码!

Image via Fotolia

图片来自Fotolia

翻译自: https://www.sitepoint.com/listing-packages-on-packagist-for-composer/

packagist 源

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值