composer create-project from private repo

前端 未结 5 1355
醉话见心
醉话见心 2020-12-24 13:56

I have a private project hosted on Bit Bucket. I have an SSH key setup. Is there a way I can use the php composer create-project vendor/name path command in the

相关标签:
5条回答
  • 2020-12-24 14:25

    Yes, Composer allows you to add private projects as 'repositories' to your composer.json file. So therefore you can include private projects into another project.

    It provides support for GitHub and Bitbucket (as well as SVN and Mercurial).

    You need to modify your composer.json file to look something like this:

    {
        "repositories": [ {
            "type": "package",
            "package": {
                "name": "TheShiftExchange/test",
                "version": "1.0.0",
                "source": {
                    "url": "https://github.com/TheShiftExchange/test.git",
                    "type": "git",
                    "reference": "master"
                  }
             }
        }],
        "require": {
            "laravel/framework": "4.0.*",
            "TheShiftExchange/test": "1.0.*"
        },
    }
    
    0 讨论(0)
  • 2020-12-24 14:26

    We have Toran Proxy (https://toranproxy.com/) installed as a private packagist, and for that we are able to create projects using command below

    composer create-project vendor/framework --repository-url=http://your-toran-repo-url/repo/private/ --stability=dev project name
    

    Stability version we use if the project is not tagged or you looking for bleeding edge version.

    --stability=dev
    
    0 讨论(0)
  • 2020-12-24 14:43

    Well there are different ways to accomplish this one being the use of a composer repository that is used instead of packagist.org, which is a better more centralized way to manage your private composer packages. The other method is to use a composer.json that incorporates your private repos within your environments, per environment.

    First

    Composer allows you to use private repositories to create projects.

    Like so...

    composer create-project vendor/name path --repository-url=http://repo.yourcomposerrepo.com
    

    Since you won't submit a private package to packagist. That url just needs a packages.json file at minimum, you could use satis or your own packagist if you want a more dynamic solution to the packages.json.

    The method for using composer.json applies to already created projects that will use custom repositories for private packages, not for creating new projects from private repositories. Use the next method if you want to go down a similar route.

    Second

    Configure your private repository into your config.json globally for your environment. Then like normally..

    composer create-project vendor/name path
    
    0 讨论(0)
  • 2020-12-24 14:48

    The way I used to:

    composer create-project vendor/name path --repository="{\"url\": \"https://bitbucket.org/user/project.git\", \"type\": \"vcs\"}" --stability=dev --remove-vcs
    

    Reference: https://getcomposer.org/doc/03-cli.md#create-project

    0 讨论(0)
  • 2020-12-24 14:51

    Since this post has some traction, I thought I'd add another solution which I use. Open up ~/.bash_profile

    and add something like

    function _cmsname {
        composer create-project vendor/package --repository-url=http://private.repo.url.co.uk/ --stability=dev "$1"
    }
    alias cmsname=_cmsname
    

    and the just type cmsname projectname in terminal.

    0 讨论(0)
提交回复
热议问题