Skip to content

Instantly share code, notes, and snippets.

@Rarst
Last active December 1, 2019 19:41
Show Gist options
  • Save Rarst/5a8a65478755539770df653c4575219a to your computer and use it in GitHub Desktop.
Save Rarst/5a8a65478755539770df653c4575219a to your computer and use it in GitHub Desktop.
Robo command to build a release zip for Composer package.
<?php
class RoboFile extends \Robo\Tasks {
/**
* Creates release zip
*
* @param string $package Composer package in vendor/name format.
* @param string $version Version to build.
*/
public function release( $package, $version = 'dev-master' ) {
list( $vendor, $name ) = explode( '/', $package );
if ( empty( $vendor ) || empty( $name ) ) {
return;
}
$this->_mkdir( 'release' );
$this->taskExec( "composer create-project {$package} {$name} {$version}" )
->dir( __DIR__ . '/release' )
->arg( '--prefer-dist' )
->arg( '--no-dev' )
->run();
$this->taskExec( 'composer remove composer/installers --update-no-dev' )
->dir( __DIR__ . "/release/{$name}" )
->run();
$this->taskExec( 'composer dump-autoload --optimize' )
->dir( __DIR__ . "/release/{$name}" )
->run();
$zipFile = "release/{$name}-{$version}.zip";
$this->_remove( $zipFile );
$this->taskPack( $zipFile )
->addDir( $name, "release/{$name}" )
->run();
if ( ! empty( $name ) ) {
$this->_deleteDir( "release/{$name}" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment