Skip to content

Commit

Permalink
Handle relative paths given
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Apr 14, 2022
1 parent bc7d97b commit e2de0ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 29 additions & 6 deletions src/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use Elephox\Files\Directory;
use Elephox\Files\File;
use Elephox\Files\FileAlreadyExistsException;
use Elephox\Files\Path;
use Elephox\Logging\Contract\Logger;
use InvalidArgumentException;
use RuntimeException;
use Throwable;

class PublishCommand implements CommandHandler
{
Expand All @@ -30,17 +32,27 @@ public function configure(CommandTemplateBuilder $builder): void
$builder
->name('plane:publish')
->optional('parts', implode(',', self::DEFAULT_PARTS), 'The parts to publish (' . implode(', ', self::AVAILABLE_PARTS) . ')')
->optional('dockerDest', $this->env->root->getDirectory('docker')->getPath(), 'The directory to publish the docker files to.')
->optional('binDest', $this->env->root->getDirectory('bin')->getPath(), 'The directory to publish the Plane binary to.')
->optional('dockerDest', 'docker', 'The directory to publish the docker files to.')
->optional('binDest', 'bin', 'The directory to publish the Plane binary to.')
->optional('overwrite', false, 'Overwrite existing files')
;
}

public function handle(CommandInvocation $command): int|null
{
$parts = explode(',', $command->getArgument('parts')->value);
$dockerDestination = new Directory($command->getArgument('dockerDest')->value);
$binDestination = new Directory($command->getArgument('binDest')->value);
if (Path::isRooted($command->getArgument('dockerDest')->value)) {
$dockerDestination = new Directory($command->getArgument('dockerDest')->value);
} else {
$dockerDestination = $this->env->root->getDirectory($command->getArgument('dockerDest')->value);
}

if (Path::isRooted($command->getArgument('binDest')->value)) {
$binDestination = new Directory($command->getArgument('binDest')->value);
} else {
$binDestination = $this->env->root->getDirectory($command->getArgument('binDest')->value);
}

$overwrite = filter_var($command->getArgument('overwrite'), FILTER_VALIDATE_BOOL);

foreach ($parts as $part) {
Expand Down Expand Up @@ -83,7 +95,18 @@ private function publishDocker(Directory $destination, bool $overwrite): void
throw new RuntimeException('Destination files are already present. Use --overwrite to force publishing the docker files.', previous: $e);
}

$composeFile = $this->env->root->getFile('docker-compose.yml');
$composeFile->putContents(str_replace(['./vendor/elephox/plane/runtimes/8.1'], [$destination->getPath()], $composeFile->getContents()));
try {
$composeFile = $this->env->root->getFile('docker-compose.yml');
$composeFile->putContents(
preg_replace(
'/^\.\/vendor\/elephox\/plane\/runtimes\/.+$/',
$destination->getPathRelative($this->env->root),
$composeFile->getContents()
)
);
} catch (Throwable) {
$this->logger->error("Failed to update docker-compose.yml");
$this->logger->error("You will need to update the docker-compose.yml file manually to point to the new Plane docker files at $destination");
}
}
}

0 comments on commit e2de0ef

Please sign in to comment.