johnpbloch / wordpress

A fork of WordPress with Composer support added. Branches, tags, and trunk synced from upstream every 15 minutes.
https://packagist.org/packages/johnpbloch/wordpress
602 stars 102 forks source link

what am i doing wrong, running composer update/install is destructive #8

Closed vesper8 closed 9 years ago

vesper8 commented 9 years ago

Hi there,

I just started using git with wordpress and initially I included everything in my git repo which I quickly found out was a bad idea. Then I found out about this package.. and about wpackagist.org which is awesome.. I am now moving to using composer for most of my plugins and for managing wordpress including both initial installation and updating.

Here's what I'm not getting. There are some files inside my wordpress installation that I want to be versionned in git. Notably there's my child theme folder.. my genesis framework folder.. and the wp-config.php

Right now everytime I run composer install / update it deletes all my files and then installs the files from this package. Which is not what I want. What is the proper workflow for this? Should I download the wordpress files in a completely seperate folder and then run a cp -r to my actual public folder as part of my deployment script?

Or is there a way to tell composer to leave files that are not part of the package alone and not delete them?

Please let me know so I can get the best possible WP/Git/Composer workflow going.

Thanks!

johnpbloch commented 9 years ago

Hey there! I'm glad you're giving this package a go.

It sounds to me like you're trying to use the standard installation setup for WordPress, which has all of your site's customizations, etc. inside of it. That's pretty much the standard setup for the majority of WordPress sites. As you've noticed, it is essentially impossible to manage your WordPress site with Composer using this setup because it overwrites your themes and plugins when WordPress updates. If you want to use this setup, you can still use Composer to manage your plugin and theme dependencies, but you'll still have to handle updating WordPress yourself, and core will still need to be tracked in your version control repository.

Fortunately there's another option. WordPress supports using a custom location for your wp-content directory. What this would allow you to do is to put WordPress into a subdirectory and have a completely separate wp-content directory that's outside of WordPress core. That's the setup I've found to work the best with Composer. To see an example, check out my starter project (I keep everything inside the public directory).

I definitely recommend the latter method if you're interested in managing your site's dependencies with Composer. Just be aware that it is more demanding to manage a site structured like that. Certain plugins might not play nicely with such a setup and it can have unintended consequences that come along from moving files around when there might not be rewrites and/or redirects set up to handle them.

vesper8 commented 9 years ago

hey thanks for the detailed reply! That does sound like a decent solution to have the wp-content be outside of the wp tree.. but i'm not sure i see the real benefit in doing that if it causes some problems sometimes. I came up with a different solution which so far seems to work very well. I'm installing wp-core to a different folder and simply running a copy script on post-install and post-update like so:

  "extra": {
    "wordpress-install-dir": "wp",
    "installer-paths" : {
         "public/wp-content/plugins/{$name}" : ["type:wordpress-plugin"],
         "public/wp-content/mu-plugins/{$name}": ["type:wordpress-muplugin"],
         "public/wp-content/themes/{$name}" : ["type:wordpress-theme"]
    }   
  },
  "scripts": {
    "post-install-cmd": [
      "cp -r wp/* public/"
    ],
    "post-update-cmd": [
      "cp -r wp/* public/"
    ]
  }  

this does a little needless copying everytime my deployment script runs.. but that doesn't seem too expensive

thanks for showing me your other starter package though, and it led me to look at a few other packages you have.. some good stuff there! i need to learn more about multisite right now and take my game up because my current project will one day involve the need to spin up lots of sites on-demand and with ease and using composer combined with multisite and a few custom scripts seems like it could do a very nice job

johnpbloch commented 9 years ago

Sounds to me like an efficient solution to your problem. :)