Skip to content

Commit 6d9f79c

Browse files
committed
feat: add symlink command
1 parent dfbb2b5 commit 6d9f79c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/Web/Documentation/PullDocumentationCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __invoke(?Version $version = null): ExitCode
4444

4545
$this->console->writeln();
4646
$this->console->success('Documentation fetched successfully.');
47+
4748
return ExitCode::SUCCESS;
4849
}
4950

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace App\Web\Documentation;
4+
5+
use RuntimeException;
6+
use Symfony\Component\Process\Process;
7+
use Tempest\Console\Console;
8+
use Tempest\Console\ConsoleCommand;
9+
use Tempest\Console\ExitCode;
10+
use Tempest\Support\Filesystem;
11+
12+
use function Tempest\root_path;
13+
14+
final readonly class SymlinkDocumentationCommand
15+
{
16+
public function __construct(
17+
private Console $console,
18+
) {}
19+
20+
#[ConsoleCommand('docs:symlink')]
21+
public function __invoke(string $path = '../tempest-framework'): ExitCode
22+
{
23+
$from = root_path($path, '/docs');
24+
$to = root_path('src/Web/Documentation/content/1.x');
25+
26+
$this->console->header('Symlinking documentation');
27+
28+
if (! Filesystem\exists($from)) {
29+
$this->console->error("The source path does not exist (tried {$from}).");
30+
31+
return ExitCode::ERROR;
32+
}
33+
34+
if (Filesystem\is_symbolic_link($to) || Filesystem\is_file($to)) {
35+
$this->console->task(
36+
label: "Removing existing symlink at {$to}.",
37+
handler: fn () => $this->run('rm -rf ' . escapeshellarg($to)),
38+
);
39+
}
40+
41+
$this->console->task(
42+
label: "Creating symlink from {$from} to {$to}.",
43+
handler: fn () => $this->run('ln -s ' . escapeshellarg($from) . ' ' . escapeshellarg($to)),
44+
);
45+
46+
$this->console->writeln();
47+
$this->console->success('Symlink created successfully.');
48+
49+
return ExitCode::SUCCESS;
50+
}
51+
52+
private function run(string $command): string
53+
{
54+
$process = Process::fromShellCommandline($command);
55+
$process->run();
56+
57+
if (! $process->isSuccessful()) {
58+
throw new RuntimeException($process->getErrorOutput());
59+
}
60+
61+
return $process->getOutput();
62+
}
63+
}

0 commit comments

Comments
 (0)