Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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": "[email protected]"
    }
  ],
  "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?

like image 332
nzifnab Avatar asked Mar 27 '14 19:03

nzifnab


2 Answers

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": "[email protected]"
    }
  ],
  "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"
    }
like image 97
Steve Avatar answered Sep 26 '22 21:09

Steve


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": "[email protected]"
    }
  ],
  "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.

like image 30
nzifnab Avatar answered Sep 23 '22 21:09

nzifnab