Allow archiving the current project with composer archive
parent
afcdad4b23
commit
ba375b6867
|
@ -36,7 +36,7 @@ class ArchiveCommand extends Command
|
||||||
->setName('archive')
|
->setName('archive')
|
||||||
->setDescription('Create an archive of this composer package')
|
->setDescription('Create an archive of this composer package')
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputArgument('package', InputArgument::REQUIRED, 'The package to archive'),
|
new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project'),
|
||||||
new InputArgument('version', InputArgument::OPTIONAL, 'The package version to archive'),
|
new InputArgument('version', InputArgument::OPTIONAL, 'The package version to archive'),
|
||||||
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
|
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar or zip', 'tar'),
|
||||||
new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
|
new InputOption('dir', false, InputOption::VALUE_REQUIRED, 'Write the archive to this directory', '.'),
|
||||||
|
@ -44,9 +44,9 @@ class ArchiveCommand extends Command
|
||||||
->setHelp(<<<EOT
|
->setHelp(<<<EOT
|
||||||
The <info>archive</info> command creates an archive of the specified format
|
The <info>archive</info> command creates an archive of the specified format
|
||||||
containing the files and directories of the Composer project or the specified
|
containing the files and directories of the Composer project or the specified
|
||||||
package and writes it to the specified directory.
|
package in the specified version and writes it to the specified directory.
|
||||||
|
|
||||||
<info>php composer.phar archive [--format=zip] [--dir=/foo] package version</info>
|
<info>php composer.phar archive [--format=zip] [--dir=/foo] [package] [version]</info>
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
|
@ -64,16 +64,20 @@ EOT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function archive(IOInterface $io, $packageName, $version = false, $format = 'tar', $dest = '.')
|
public function archive(IOInterface $io, $packageName = false, $version = false, $format = 'tar', $dest = '.')
|
||||||
{
|
{
|
||||||
$config = Factory::createConfig();
|
$config = Factory::createConfig();
|
||||||
$factory = new Factory;
|
$factory = new Factory;
|
||||||
$archiveManager = $factory->createArchiveManager($config);
|
$archiveManager = $factory->createArchiveManager($config);
|
||||||
|
|
||||||
$package = $this->selectPackage($io, $packageName, $version);
|
if ($packageName) {
|
||||||
|
$package = $this->selectPackage($io, $packageName, $version);
|
||||||
|
|
||||||
if (!$package) {
|
if (!$package) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$package = $this->getComposer()->getPackage();
|
||||||
}
|
}
|
||||||
|
|
||||||
$io->write('<info>Creating the archive.</info>');
|
$io->write('<info>Creating the archive.</info>');
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Downloader\DownloadManager;
|
||||||
use Composer\Factory;
|
use Composer\Factory;
|
||||||
use Composer\IO\NullIO;
|
use Composer\IO\NullIO;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
use Composer\Package\RootPackage;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,19 +74,24 @@ class ArchiveManager
|
||||||
throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
|
throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directory used to download the sources
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
$packageName = preg_replace('#[^a-z0-9-_.]#i', '-', $package->getPrettyString());
|
$packageName = preg_replace('#[^a-z0-9-_.]#i', '-', $package->getPrettyString());
|
||||||
$sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName;
|
|
||||||
$filesystem->ensureDirectoryExists($sourcePath);
|
|
||||||
|
|
||||||
// Archive filename
|
// Archive filename
|
||||||
$filesystem->ensureDirectoryExists($targetDir);
|
$filesystem->ensureDirectoryExists($targetDir);
|
||||||
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
||||||
$filesystem->ensureDirectoryExists(dirname($target));
|
$filesystem->ensureDirectoryExists(dirname($target));
|
||||||
|
|
||||||
// Download sources
|
if ($package instanceof RootPackage) {
|
||||||
$this->downloadManager->download($package, $sourcePath, true);
|
$sourcePath = realpath('.');
|
||||||
|
} else {
|
||||||
|
// Directory used to download the sources
|
||||||
|
$sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName;
|
||||||
|
$filesystem->ensureDirectoryExists($sourcePath);
|
||||||
|
|
||||||
|
// Download sources
|
||||||
|
$this->downloadManager->download($package, $sourcePath, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the archive
|
// Create the archive
|
||||||
$sourceRef = $package->getSourceReference();
|
$sourceRef = $package->getSourceReference();
|
||||||
|
|
Loading…
Reference in New Issue