composer上发布项目Packgist

  • 使用composer创建一个项目的基本流程:
    1.创建 composer.json,并添加依赖到的扩展包;
    2.运行 composer install,安装扩展包并生成 composer.lock;
    3.提交 composer.lock 到代码版本控制器中,如:git;
  • 准备:
GitHub帐号
Composer程序(确认你已经安装)
Packagist帐号(用GITHUB账号登录)
  • Github
    例如我的项目地址:
    https://github.com/zlqbookGM/house.git
    已经部署到Github上的项目:获取你的项目地址,将项目克隆到本地。
    未部署:将你项目上传到Github上,并获取你这个项目的地址。
  • composer本地操作
  1. 本地初始化conposer.json
    $ cd ~/path/...
    $ composer init
  2. 初始化composer文件,推送修改到github,如果你项目在github,这一步刻意忽略。
  • packgist
  1. 镜像包发布到packgist
    使用Github账户登录Packgist,由于本身composer就是从github发展而来的。
    找到submit,用你的项目仓库地址将镜像包发布提交。

  2. 配置GitHub和Packagist之间的自动更新钩子,根据向导,复制自己的packagist的api token,然后去GitHub配置好仓库的钩子服务(此处在测试器,github集成与服务已经逐渐弃用)

  • 本地测试与测试安装包
    $ cd ~/work/path/
    $ composer require zlqbookGM/hello dev-master
    结果:
D:\phpStudy\PHPTutorial\WWW>composer create-project zlqbook/housespider
Installing zlqbook/housespider (0.1.0)
  - Installing zlqbook/housespider (0.1.0): Downloading (100%)
Created project in D:\phpStudy\PHPTutorial\WWW\housespider
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 65 installs, 0 updates, 0 removals
  - Installing yiisoft/yii2-composer (2.0.6): Loading from cache
  - Installing bower-asset/jquery (3.2.1): Loading from cache
  - Installing bower-asset/bootstrap (v3.3.7): Loading from cache
/*成功部分省略*/
codeception/base suggests installing codeception/specify (BDD-style code blocks)
codeception/base suggests installing flow/jsonpath (For using JSONPath in REST module)
codeception/base suggests installing league/factory-muffin (For DataFactory module)
codeception/base suggests installing league/factory-muffin-faker (For Faker support in DataFactory module)
codeception/base suggests installing phpseclib/phpseclib (for SFTP option in FTP Module)
codeception/base suggests installing stecman/symfony-console-completion (For BASH autocompletion)
codeception/base suggests installing symfony/phpunit-bridge (For phpunit-bridge support)
Generating autoload files
  • 为项目添加outload属性
    psr-4自动加载规范,了解其他加载规范,查询PHP-FIG
    {
        "psr-4": { "Rivsen\\Demo\\": "src" }
    },

看一个具体的composer.json文件:

{
    "name": "zlqbook/housespider",
    "description": "douban spdider base Yii 2 ",
    "keywords": ["yii2", "framework", "advanced", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
// 支持,这些信息会在packgist项目首页显示
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
  /*依赖*/
    "require": { 
        "php": ">=5.4.0",
        "yiisoft/yii2": "~2.0.6",
        "yiisoft/yii2-bootstrap": "~2.0.0",
        "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
    },
    "require-dev": {
        "yiisoft/yii2-debug": "~2.0.0",
        "yiisoft/yii2-gii": "~2.0.0",
        "yiisoft/yii2-faker": "~2.0.0",
        "codeception/base": "^2.2.3",
        "codeception/verify": "~0.3.1"
    },
    "config": {
        "process-timeout": 1800,
        "fxp-asset": {
            "enabled": false
        }
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
}
  • Github包版本管理:
    创建一个版本,通过github和packgist链接,更新到Packgist库中。
    版本命名规则:命名方法
/*创建分支*/
$ cd ~/work/github/hello-world
$ git branch
//创建分支 0.1
git checkout -b 0.1
//提交分支
$ git add .
$ git commit -m 'update readme'
$ git push origin 0.1
发布版本
$ git tag 0.1.0
$ git push --tags

你可能感兴趣的:(composer上发布项目Packgist)