getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
632 stars 94 forks source link

How to distribute Herbert based plugin? #80

Closed phredeye closed 4 years ago

phredeye commented 8 years ago

Let's say I want to make a plugin and distribute it on the Wordpress codex, or even sell it as a premium plugin from my own website. Considering a large percentage of Wordpress users do not use or don't have the ability to use composer, what is a sane method or best practice for deploying plugins built with Herbert?

The only thing I can think of is to commit the vendor directory to my git repo and distrubute it with the plugin, but for a number of obvious reasons this doesn't seem ideal.

Also, what about conflicts with other composer based plugins that might require the same libraries? What about deployment side by side with other herbert based plugins?

arippberger commented 8 years ago

+1 for this question.

The only way I can think of is committing the vendor directory. As for conflicts, you could run a find and replace, adding a prefix. Obviously not ideal as it you'd essentially be restricted to that version of the library (until/unless you update and run another find/replace).

roest01 commented 8 years ago

My idea is to commit only composer.json and composer.lock. Then use a build server (f.e jenkins) and build a .zip file with vendor inside which can be delivered by YahnisElsts/plugin-update-checker or a premium updater.

Build Scrip can be simple:

git checkout yourRepo myPluginDirectory
composer.phar install
zip -r plugin.zip myPluginDirectory -x .*
JacobDorman commented 8 years ago

Not sure about distributing via the wordpress plugin directory, but I've been including herbert plugins using a main composer.json requiring composer/installers and adding

"type": "wordpress-plugin",

to the herbert plugin's composer.json

I've changed /plugin.php to do some ugly detection of the correct vendor directory to use. Would love to know a better way:

// Prefer our vendordir
$vendor_dir = __DIR__ . '/vendor/';

if ( file_exists( $vendor_dir . '/autoload.php' ) ) {
    require_once $vendor_dir . '/autoload.php';
    require_once $vendor_dir . '/getherbert/framework/bootstrap/autoload.php';
} else {
    if ( ! defined( 'WP_CLI' ) && class_exists( '\Composer\Autoload\Classloader' ) ) {
        $reflector  = new ReflectionClass( '\Composer\Autoload\Classloader' );
        $vendor_dir = str_replace( 'composer/ClassLoader.php', '', $reflector->getFileName() );

        // composer autoloader already done, so just
        require_once $vendor_dir . '/getherbert/framework/bootstrap/autoload.php';
    }
}

// Store vendor dir
if ( function_exists( 'herbert' ) ) {
    herbert()->instance( 'vendor_dir', $vendor_dir );
}
jeremyzahner commented 8 years ago

@onnimonni This is clearly related to #115 since publishing the plugin to the Wordpress plugin directory would make it easy to distribute it (even via composer). Do you agree?