Skip to content

Commit b34c431

Browse files
committed
feat(docs): fetch docs from monorepository branches
1 parent 659cd04 commit b34c431

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+107
-8399
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.tempest
22
node_modules/
33
vendor/
4+
docs-clone/
45
/public/main.css
56
/package-lock.json
67
.env
@@ -18,4 +19,4 @@ tempest-access.log
1819
vite-tempest
1920
public/build/
2021
database.sqlite
21-
database-old.sqlite
22+
database-old.sqlite

deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ php8.4 tempest migrate:up --force
1515
php8.4 tempest static:clean --force
1616

1717
# Build front-end
18+
php8.4 tempest docs:pull --no-interaction
1819
php8.4 tempest command-palette:index
1920
/home/forge/.bun/bin/bun run build
2021
php8.4 tempest cache:clear --force

src/Web/Documentation/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content/*
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Support\Filesystem;
10+
11+
use function Tempest\root_path;
12+
use function Tempest\Support\path;
13+
14+
final class PullDocumentationCommand
15+
{
16+
private const CLONE_DIRECTORY = 'clone';
17+
private const DOCS_DIRECTORY = 'docs';
18+
19+
public function __construct(
20+
private readonly Console $console,
21+
) {}
22+
23+
#[ConsoleCommand('docs:pull')]
24+
public function __invoke(?Version $version = null)
25+
{
26+
$versions = $version ? [$version] : Version::cases();
27+
28+
$this->console->header('Cloning documentation');
29+
30+
foreach ($versions as $version) {
31+
$this->console->task(
32+
label: "Fetching {$version->getBranch()}",
33+
handler: fn () => $this->fetchVersionDocumentation($version),
34+
);
35+
}
36+
37+
$this->console->writeln();
38+
$this->console->success('Documentation fetched successfully.');
39+
}
40+
41+
private function fetchVersionDocumentation(Version $version): void
42+
{
43+
$versionedDocsDirectory = root_path('src/Web/Documentation/content/', $version->getUrlSegment());
44+
$temporaryDirectory = root_path('docs-clone');
45+
46+
Filesystem\ensure_directory_empty($versionedDocsDirectory);
47+
Filesystem\ensure_directory_empty($temporaryDirectory);
48+
49+
$this->run(
50+
command: sprintf(
51+
'git clone --no-checkout --depth=1 --filter=tree:0 -b %s https://github.com/tempestphp/tempest-framework %s',
52+
$version->getBranch(),
53+
self::CLONE_DIRECTORY,
54+
),
55+
cwd: $temporaryDirectory,
56+
);
57+
58+
$this->run(
59+
command: 'git sparse-checkout set --no-cone /' . self::DOCS_DIRECTORY,
60+
cwd: path($temporaryDirectory, self::CLONE_DIRECTORY),
61+
);
62+
63+
$this->run(
64+
command: 'git checkout',
65+
cwd: path($temporaryDirectory, self::CLONE_DIRECTORY),
66+
);
67+
68+
Filesystem\move(path($temporaryDirectory, self::CLONE_DIRECTORY, self::DOCS_DIRECTORY), $versionedDocsDirectory, overwrite: true);
69+
Filesystem\delete_directory($temporaryDirectory);
70+
}
71+
72+
private function run(string $command, string $cwd): string
73+
{
74+
$process = Process::fromShellCommandline($command, $cwd);
75+
$process->run();
76+
77+
if (! $process->isSuccessful()) {
78+
throw new RuntimeException($process->getErrorOutput());
79+
}
80+
81+
return $process->getOutput();
82+
}
83+
}

src/Web/Documentation/Version.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ enum Version: string
88
{
99
use IsEnumHelper;
1010

11-
case VERSION_1 = '1.x';
11+
case VERSION_1 = 'main';
12+
case VERSION_2 = '2.x';
1213

13-
public static function default(): self
14+
public function getBranch(): string
1415
{
15-
return self::VERSION_1;
16+
return match ($this) {
17+
self::VERSION_1 => 'main',
18+
self::VERSION_2 => '2.x',
19+
};
20+
}
21+
22+
public function getUrlSegment(): string
23+
{
24+
return match ($this) {
25+
self::VERSION_1 => 'main',
26+
self::VERSION_2 => '2.x',
27+
};
1628
}
1729

1830
public static function tryFromString(?string $case): ?static
@@ -22,4 +34,9 @@ public static function tryFromString(?string $case): ?static
2234
default => self::tryFrom($case),
2335
};
2436
}
37+
38+
public static function default(): self
39+
{
40+
return self::VERSION_1;
41+
}
2542
}

src/Web/Documentation/content/1.x/.gitkeep

Whitespace-only changes.

src/Web/Documentation/content/1.x/0-getting-started/01-introduction.md

Lines changed: 0 additions & 193 deletions
This file was deleted.

0 commit comments

Comments
 (0)