简体   繁体   English

Composer安装自定义包的路径

[英]Composer install path for custom package

I've read other questions about this topic and I just can't seem to get this to work. 我已经阅读了关于这个主题的其他问题,我似乎无法让这个工作。 I'm trying to get a download of cforms as a custom package to install into wp-content/plugins/cforms . 我正在尝试下载cforms作为自定义包以安装到wp-content/plugins/cforms I've gotten this to work for the other packages that wpackagist supplies, and even some custom plugins developed in-house. 我已经将这个用于wpackagist耗材的其他软件包,甚至是内部开发的一些自定义插件。

Here's what I have: 这就是我所拥有的:

{
  "name": "mycompany/wordpress-install",
  "description": "Themes and plugins for our wordpress install.",
  "authors": [
    {
        "name": "Me",
        "email": "example@example.net"
    }
  ],
  "require": {
    "deliciousdays/cforms": "14.5.2"
  },
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "deliciousdays/cforms",
        "version": "14.5.2",
        "dist": {
          "url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
          "type": "zip"
        }
      }
    }
  ],
  "extra": {
    "installer-paths": {
      "wp-content/plugins/cforms": ["deliciousdays/cforms"]
    }
  }
}

It's downloading cforms fine, but it's still putting it into vendor/deliciousdays/cforms when I want it in (obviously) wp-content/plugins/cforms . 它正在下载cforms,但是当我想要它(很明显) wp-content/plugins/cforms时,它仍然会把它放到vendor/deliciousdays/cforms wp-content/plugins/cforms What am I doing wrong? 我究竟做错了什么?

Try using this composer.json, it includes Wordpress (v3.9 as of right now). 尝试使用这个composer.json,它包括Wordpress(现在的v3.9)。

It uses fancyguy/webroot-installer to install to certain directories. 它使用fancyguy / webroot-installer安装到某些目录。

This file is meant to be in the root wordpress directory. 此文件应位于root wordpress目录中。 The extra section shows the "webroot-dir" to be "."; 额外部分显示“webroot-dir”为“。”; This will install into current directory, (Do not use "/" or "./"), if you would like it to install into a specific directory simply change "." 这将安装到当前目录中,(不要使用“/”或“./”),如果您希望将其安装到特定目录中,只需更改“。” to the name of the directory you'd like to install to. 到您要安装到的目录的名称。

"extra": {
    "webroot-dir": ".",
    "webroot-package": "wordpress"
}

So after running this file you should have the normal wordpress structure with cforms placed in the wp-content/plugins directory, to install a theme, you can copy the cforms section and change the type to "wordpress-theme" to have it installed into the themes directory. 所以在运行这个文件后你应该有正常的wordpress结构,并在wp-content / plugins目录中放置cforms,安装主题,你可以复制cforms部分并将类型更改为“wordpress-theme”以将其安装到主题目录。

I'm by no means an expert with composer, but I was able to get this working correctly. 我绝不是作曲家的专家,但我能够正常工作。

{
  "name": "mycompany/wordpress-install",
  "description": "Themes and plugins for our wordpress install.",
  "authors": [
    {
        "name": "Me",
        "email": "example@example.net"
    }
  ],
  "repositories": [
    {
        "type": "composer",
        "url": "http://wpackagist.org"
    },
    {
        "type": "package",
        "package": {
            "name": "wordpress",
            "type": "webroot",
            "version": "3.9",
            "dist": {
                "type": "zip",
                "url": "https://github.com/WordPress/WordPress/archive/3.9.zip"
            }
        }
    },
    {
        "type": "package",
        "package": {
            "name": "cforms",
            "type": "wordpress-plugin",
            "version": "14.5.2",
            "dist": {
                "url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
                "type": "zip"
             }
        }
    }
 ],
    "require": {
      "php": ">=5.3.0",
      "composer/installers": "~1.0",
      "wordpress": "3.9",
      "fancyguy/webroot-installer": "1.0.0",
      "wpackagist/wordpress-seo": "*",
      "cforms": "14.5.2"
    },
    "extra": {
        "webroot-dir": ".",
        "webroot-package": "wordpress"
    }

}

Note that using wpackagist, you can view a list of installable plugins/themes at these links: 请注意,使用wpackagist,您可以在以下链接中查看可安装插件/主题的列表:

http://plugins.svn.wordpress.org/ http://plugins.svn.wordpress.org/

http://themes.svn.wordpress.org/ http://themes.svn.wordpress.org/

If you would like to include plugins from the Wordpress Plugin Respository, you can add them in easily. 如果您想要包含Wordpress插件存储库中的插件,您可以轻松添加它们。 For instance, if you wanted to add the Yoast Wordpress SEO plugin, you would add the following to require (Note that you need to know the slug of the plugin to add it): 例如,如果你想添加Yoast Wordpress SEO插件,你可以添加以下要求(注意你需要知道插件的slug来添加它):

    "require": {
      "php": ">=5.3.0",
      "composer/installers": "~1.0",
      "wordpress": "3.9",
      "fancyguy/webroot-installer": "1.0.0",
      "wpackagist/wordpress-seo": "*",
      "cforms": "14.5.2"
    }

it happens I have got an answer for you, because I ran into the same problem. 碰巧我得到了一个答案,因为我遇到了同样的问题。 Clearly, there is a big demand now to custom install packages. 显然,现在对自定义安装包有很大的需求。

The composer/installers ONLY work on defined frameworks and CMS(s), but doesn't work for normal composer packages. composer/installers仅适用于已定义的框架和CMS,但不适用于普通的作曲家程序包。

I have implemented this composer plugin to install packages into user (custom) defined folders you can just include it in your composer.json, follow the example and tell me if you have more questions :) 我已经实现了这个作曲家插件来将软件包安装到用户(自定义)定义的文件夹中,你可以将它包含在你的composer.json中,按照示例告诉我你是否还有更多问题:)

https://github.com/mnsami/composer-custom-directory-installer https://github.com/mnsami/composer-custom-directory-installer

composer-custom-directory-installer 作曲家定制目录的安装程序

A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder. 一个composer插件,用于在vendor文件夹中的默认编写器默认安装路径之外的自定义目录中安装不同类型的编写器包。

This is not another composer-installer library for supporting non-composer package types ie application .. etc. This is only to add the flexability of installing composer packages outside the vendor folder. 这不是另一个用于支持非作曲家包类型的composer-installer库,即application等。这只是为了增加在供应商文件夹之外安装作曲家包的灵活性。 This package only supports composer package types, 这个包只支持composer包类型,

https://getcomposer.org/doc/04-schema.md#type https://getcomposer.org/doc/04-schema.md#type

The type of the package. 包的类型。 It defaults to library. 它默认为库。

Package types are used for custom installation logic. 包类型用于自定义安装逻辑。 If you have a package that needs some special logic, you can define a custom type. 如果您的软件包需要一些特殊逻辑,则可以定义自定义类型。 This could be a symfony-bundle, a wordpress-plugin or a typo3-module. 这可能是symfony-bundle,wordpress-plugin或typo3-module。 These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type. 这些类型都将特定于某些项目,并且需要提供能够安装该类型的包的安装程序。

How to use 如何使用

  • Include the composer plugin into your composer.json require section:: 包括作曲家插件到您的composer.json require部分::
"require":{
    "php": ">=5.3",
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "monolog/monolog": "*"
  }
  • In the extra section define the custom directory you want to the package to be installed in:: extra部分中定义要安装到的程序包的自定义目录::
  "extra":{
    "installer-paths":{
      "./monolog/": ["monolog/monolog"]
    }

by adding the installer-paths part, you are telling composer to install the monolog package inside the monolog folder in your root directory. 通过添加installer-paths部分,您告诉作曲家在根目录中的monolog文件夹中安装monolog包。

  • As an added new feature, we have added more flexibility in defining your download directory same like the composer/installers , in other words you can use variables like {$vendor} and {$name} in your installer-path section: 作为一项新增功能,我们在定义下载目录方面增加了更多灵活性,就像编辑器composer/installers ,换句话说,您可以在installer-path部分中使用{$vendor}{$name}等变量:
"extra": {
    "installer-paths": {
        "./customlibs/{$vendor}/db/{$name}": ["doctrine/orm"]
    }
}

the above will manage to install the doctrine/orm package in the root folder of your project, under customlibs . 以上将设法在customlibs下的项目的根文件夹中安装doctrine/orm包。

Note 注意

Composer type: project is not supported in this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition , to be required by another package. Composer type: project此安装程序不支持该type: project ,因为类型为project包只能与symfony/framework-standard-edition等应用程序shell一起使用,这是另一个包所需要的。

Finally figured it out after trying lots of different things. 最后在尝试了很多不同的事情后想出来了。 I think I was missing two things: 我想我错过了两件事:

In the package declaration I changed it to have the "type": "wordpress-plugin" , and then in the requires I had to add "composers/installers": "~1.0" like so (also note that the extra was removed entirely): 在包装声明中我将其更改为"type": "wordpress-plugin" ,然后在要求中我必须添加"composers/installers": "~1.0"就像这样(还要注意extra完全被删除) ):

{
  "name": "mycompany/wordpress-install",
  "description": "Themes and plugins for our wordpress install.",
  "authors": [
    {
        "name": "Me",
        "email": "example@example.net"
    }
  ],
  "require": {
    "composer/installers": "~1.0.0",
    "deliciousdays/cforms": "14.5.2"
  },
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "deliciousdays/cforms",
        "version": "14.5.2",
        "type": "wordpress-plugin",
        "dist": {
          "url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
          "type": "zip"
        }
      }
    }
  ]
}

I still have been unable to figure out how to get a custom package to install to a directory of my choosing even with the composer/installers require in there. 我仍然无法弄清楚如何将自定义包安装到选择的目录中,即使在那里有composer/installers require。 It just seems to ignore everything until I've added a type to the object, and then it forces it to download into the location defined by that type, based on how composer/installers decided to map it . 它似乎忽略了所有内容,直到我向对象添加了一个类型,然后根据composer/installers决定映射它的方式强制它下载到该类型定义的位置。

But I think this will work for now... If anyone knows how to make it download into, say, "myfolder/something/cforms" I'll accept your answer. 但我认为这将暂时有效......如果有人知道如何下载,比如"myfolder/something/cforms"我会接受你的回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM