Allow archiving the current project with composer archive
parent
afcdad4b23
commit
ba375b6867
|
@ -36,7 +36,7 @@ class ArchiveCommand extends Command
|
|||
->setName('archive')
|
||||
->setDescription('Create an archive of this composer package')
|
||||
->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 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', '.'),
|
||||
|
@ -44,9 +44,9 @@ class ArchiveCommand extends Command
|
|||
->setHelp(<<<EOT
|
||||
The <info>archive</info> command creates an archive of the specified format
|
||||
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
|
||||
)
|
||||
|
@ -64,17 +64,21 @@ 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();
|
||||
$factory = new Factory;
|
||||
$archiveManager = $factory->createArchiveManager($config);
|
||||
|
||||
if ($packageName) {
|
||||
$package = $this->selectPackage($io, $packageName, $version);
|
||||
|
||||
if (!$package) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
$package = $this->getComposer()->getPackage();
|
||||
}
|
||||
|
||||
$io->write('<info>Creating the archive.</info>');
|
||||
$archiveManager->archive($package, $format, $dest);
|
||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Downloader\DownloadManager;
|
|||
use Composer\Factory;
|
||||
use Composer\IO\NullIO;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\RootPackage;
|
||||
use Composer\Util\Filesystem;
|
||||
|
||||
/**
|
||||
|
@ -73,19 +74,24 @@ class ArchiveManager
|
|||
throw new \RuntimeException(sprintf('No archiver found to support %s format', $format));
|
||||
}
|
||||
|
||||
// Directory used to download the sources
|
||||
$filesystem = new Filesystem();
|
||||
$packageName = preg_replace('#[^a-z0-9-_.]#i', '-', $package->getPrettyString());
|
||||
$sourcePath = sys_get_temp_dir().'/composer_archiver/'.$packageName;
|
||||
$filesystem->ensureDirectoryExists($sourcePath);
|
||||
|
||||
// Archive filename
|
||||
$filesystem->ensureDirectoryExists($targetDir);
|
||||
$target = realpath($targetDir).'/'.$packageName.'.'.$format;
|
||||
$filesystem->ensureDirectoryExists(dirname($target));
|
||||
|
||||
if ($package instanceof RootPackage) {
|
||||
$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
|
||||
$sourceRef = $package->getSourceReference();
|
||||
|
|
Loading…
Reference in New Issue