简体   繁体   中英

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 . I've gotten this to work for the other packages that wpackagist supplies, and even some custom plugins developed in-house.

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 . What am I doing wrong?

Try using this composer.json, it includes Wordpress (v3.9 as of right now).

It uses fancyguy/webroot-installer to install to certain directories.

This file is meant to be in the root wordpress directory. The extra section shows the "webroot-dir" to be "."; 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.

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:

http://plugins.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. 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):

    "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.

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 :)

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.

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. This package only supports composer package types,

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. 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::
"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":{
    "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.

  • 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:
"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 .

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.

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):

{
  "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. 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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