-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself-install.cs
More file actions
78 lines (64 loc) · 2.93 KB
/
self-install.cs
File metadata and controls
78 lines (64 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#region Purpose
// Development CLI for TimeWarp.Terminal repository operations
#endregion
// ═══════════════════════════════════════════════════════════════════════════════
// SELF INSTALL COMMAND
// ═══════════════════════════════════════════════════════════════════════════════
// AOT compiles and installs the dev CLI to ./bin
namespace DevCli;
/// <summary>
/// AOT compile and install dev CLI to ./bin
/// </summary>
[NuruRoute("self-install", Description = "AOT compile and install dev CLI to ./bin")]
internal sealed class SelfInstallCommand : ICommand<Unit>
{
internal sealed class Handler : ICommandHandler<SelfInstallCommand, Unit>
{
private readonly ITerminal Terminal;
public Handler(ITerminal terminal)
{
Terminal = terminal;
}
public async ValueTask<Unit> Handle(SelfInstallCommand command, CancellationToken ct)
{
string repoRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", ".."));
// Verify we're in the right place
if (!File.Exists(Path.Combine(repoRoot, "timewarp-terminal.slnx")))
{
repoRoot = Path.GetFullPath(Directory.GetCurrentDirectory());
if (!File.Exists(Path.Combine(repoRoot, "timewarp-terminal.slnx")))
{
throw new InvalidOperationException("Could not find repository root (timewarp-terminal.slnx not found)");
}
}
string binDir = Path.Combine(repoRoot, "bin");
Directory.CreateDirectory(binDir);
string devCliPath = Path.Combine(repoRoot, "tools", "dev-cli", "dev.cs");
string outputPath = Path.Combine(binDir, "dev");
Terminal.WriteLine("Building dev CLI with AOT compilation...");
Terminal.WriteLine($"Source: {devCliPath}");
Terminal.WriteLine($"Output: {outputPath}");
// Publish AOT
int exitCode = await Shell.Builder("dotnet")
.WithArguments("publish", devCliPath, "-c", "Release", "-o", binDir, "-p:PublishAot=true", "--self-contained")
.WithWorkingDirectory(repoRoot)
.RunAsync();
if (exitCode != 0)
{
throw new InvalidOperationException("AOT compilation failed!");
}
// Make executable on Unix
if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
await Shell.Builder("chmod")
.WithArguments("+x", outputPath)
.RunAsync();
}
Terminal.WriteLine($"\n✓ dev CLI installed to: {outputPath}");
Terminal.WriteLine("\nTo use it:");
Terminal.WriteLine(" ./bin/dev --help # Run directly");
Terminal.WriteLine(" direnv allow # Or add to PATH via .envrc");
return Unit.Value;
}
}
}