Skip to content

Commit d5f309a

Browse files
committed
feat: add --with-uploads option to deploy command
1 parent cd5a0c2 commit d5f309a

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/Command/Import/ImportUploadsCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ protected function configure()
9898
->setDescription('Import files to the environment uploads directory')
9999
->addArgument('path', InputArgument::REQUIRED, 'The path to the files to import')
100100
->addOption('environment', null, InputOption::VALUE_REQUIRED, 'The environment to upload files to', 'staging')
101+
->addOption('force', null, InputOption::VALUE_NONE, 'Force the import to run')
101102
->addOption('size', null, InputOption::VALUE_REQUIRED, 'The number of files to process at a time', '20');
102103
}
103104

@@ -114,13 +115,13 @@ protected function perform(InputInterface $input, OutputInterface $output)
114115
throw new InvalidArgumentException('Cannot have a "size" smaller than 1');
115116
}
116117

117-
if (!$output->confirm('Importing files will overwrite any existing file in the environment uploads directory. Do you want to proceed?')) {
118+
if (!$this->getBooleanOption($input, 'force') && !$output->confirm('Importing files will overwrite any existing file in the environment "uploads" directory. Do you want to proceed?')) {
118119
return;
119120
}
120121

121122
$this->tempDirectory = $this->createTempDirectory();
122123

123-
$output->info(sprintf('Starting file import to "<comment>%s</comment>" environment', $environment));
124+
$output->info(sprintf('Starting file import to the "<comment>%s</comment>" environment "uploads" directory', $environment));
124125

125126
$progressBar = new ProgressBar($output);
126127
$progressBar->setFormat("Importing file (<comment>%filename%</comment>)\nTotal files imported: <comment>%total%</comment>\n");
@@ -156,7 +157,7 @@ protected function perform(InputInterface $input, OutputInterface $output)
156157
$progressBar->advance();
157158
});
158159

159-
$output->info(sprintf('Files imported successfully to "<comment>%s</comment>" environment', $environment));
160+
$output->info(sprintf('Files imported successfully to the "<comment>%s</comment>" environment "uploads" directory', $environment));
160161
}
161162

162163
/**

src/Command/Project/DeployProjectCommand.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
use Symfony\Component\Console\Exception\RuntimeException;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Input\InputOption;
1920
use Tightenco\Collect\Support\Collection;
21+
use Ymir\Cli\ApiClient;
22+
use Ymir\Cli\CliConfiguration;
23+
use Ymir\Cli\Command\Import\ImportUploadsCommand;
2024
use Ymir\Cli\Console\OutputInterface;
25+
use Ymir\Cli\ProjectConfiguration\ProjectConfiguration;
2126

2227
class DeployProjectCommand extends AbstractProjectDeploymentCommand
2328
{
@@ -35,6 +40,23 @@ class DeployProjectCommand extends AbstractProjectDeploymentCommand
3540
*/
3641
public const NAME = 'project:deploy';
3742

43+
/**
44+
* The build "uploads" directory.
45+
*
46+
* @var string
47+
*/
48+
private $uploadsDirectory;
49+
50+
/**
51+
* Constructor.
52+
*/
53+
public function __construct(ApiClient $apiClient, CliConfiguration $cliConfiguration, ProjectConfiguration $projectConfiguration, string $uploadsDirectory, array $deploymentSteps = [])
54+
{
55+
parent::__construct($apiClient, $cliConfiguration, $projectConfiguration, $deploymentSteps);
56+
57+
$this->uploadsDirectory = $uploadsDirectory;
58+
}
59+
3860
/**
3961
* {@inheritdoc}
4062
*/
@@ -44,7 +66,8 @@ protected function configure()
4466
->setName(self::NAME)
4567
->setDescription('Deploy project to an environment')
4668
->setAliases([self::ALIAS])
47-
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to deploy to', 'staging');
69+
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to deploy to', 'staging')
70+
->addOption('with-uploads', null, InputOption::VALUE_NONE, 'Import the "uploads" directory during the deployment');
4871
}
4972

5073
/**
@@ -54,9 +77,14 @@ protected function createDeployment(InputInterface $input, OutputInterface $outp
5477
{
5578
$environment = $this->getStringArgument($input, 'environment');
5679
$projectId = $this->projectConfiguration->getProjectId();
80+
$withUploadsOption = $this->getBooleanOption($input, 'with-uploads');
5781

5882
$this->invoke($output, ValidateProjectCommand::NAME, ['environments' => $environment]);
59-
$this->invoke($output, BuildProjectCommand::NAME, ['environment' => $environment]);
83+
$this->invoke($output, BuildProjectCommand::NAME, array_merge(['environment' => $environment], $withUploadsOption ? ['--with-uploads' => null] : []));
84+
85+
if ($withUploadsOption) {
86+
$this->invoke($output, ImportUploadsCommand::NAME, ['path' => $this->uploadsDirectory, '--environment' => $environment, '--force' => null]);
87+
}
6088

6189
$deployment = $this->apiClient->createDeployment($projectId, $environment, $this->projectConfiguration);
6290

0 commit comments

Comments
 (0)