refactor: restructure bastion as pnpm monorepo (@lab/shared, @lab/bastion, @lab/cli)

- Split into 3 workspace packages: shared (types/constants), bastion (server), cli
- CLI binary renamed from "bastion" to "lab"
- Cross-package imports via @lab/shared and @lab/bastion workspace references
- Extracted BastionConfig, BastionState, HardwareInfo types into @lab/shared
- Added APP_NAME/APP_VERSION constants
- tsconfig.base.json with project references for build ordering
- Root workspace scripts: build, test, typecheck, clean

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Michal
2026-03-17 11:05:41 +00:00
parent 937c01f5d9
commit 64533b2dcf
40 changed files with 344 additions and 143 deletions

View File

@@ -0,0 +1,20 @@
{
"name": "@lab/shared",
"version": "0.1.0",
"private": true,
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "tsc --build",
"clean": "rimraf dist",
"test": "vitest",
"test:run": "vitest run"
}
}

View File

@@ -0,0 +1,4 @@
// Application-wide constants.
export const APP_NAME = "lab";
export const APP_VERSION = "0.1.0";

View File

@@ -0,0 +1,9 @@
export type {
HardwareInfo,
InstallConfig,
InstalledInfo,
BastionState,
BastionConfig,
} from "./types/index.js";
export { APP_NAME, APP_VERSION } from "./constants/index.js";

View File

@@ -0,0 +1,28 @@
// Configuration types for the bastion server.
export interface BastionConfig {
fedoraVersion: string;
arch: string;
httpPort: number;
timezone: string;
locale: string;
bastionDir: string;
domain: string;
dhcpMode: "proxy" | "full";
dhcpRangeStart: string;
dhcpRangeEnd: string;
// Flags
skipDnsmasq?: boolean | undefined;
skipArtifacts?: boolean | undefined;
// Derived at runtime
iface: string;
serverIp: string;
network: string;
gateway: string;
sshKeys: string[];
adminUser: string;
fedoraMirror: string;
tftpDir: string;
httpDir: string;
stateFile: string;
}

View File

@@ -0,0 +1,8 @@
export type {
HardwareInfo,
InstallConfig,
InstalledInfo,
BastionState,
} from "./state.js";
export type { BastionConfig } from "./config.js";

View File

@@ -0,0 +1,40 @@
// State types for discovered machines, install queue, and installed machines.
export interface HardwareInfo {
mac: string;
product: string;
board: string;
serial: string;
manufacturer: string;
cpu_model: string;
cpu_cores: number;
memory_gb: number;
arch: string;
disks: Array<{ name: string; size_gb: number; model: string }>;
nics: Array<{ name: string; mac: string; state: string }>;
first_seen: string;
last_seen: string;
}
export interface InstallConfig {
hostname: string;
disk: string;
role: "worker" | "infra";
queued_at: string;
progress?: string;
progress_at?: string;
progress_detail?: string;
}
export interface InstalledInfo {
hostname: string;
role: string;
ip: string;
installed_at: string;
}
export interface BastionState {
discovered: Record<string, HardwareInfo>;
install_queue: Record<string, InstallConfig>;
installed: Record<string, InstalledInfo>;
}

View File

@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
},
"include": ["src/**/*.ts"]
}

View File

@@ -0,0 +1,8 @@
import { defineProject } from 'vitest/config';
export default defineProject({
test: {
name: 'shared',
include: ['tests/**/*.test.ts'],
},
});