feat(installer): add runtime manager core library
This commit is contained in:
parent
a3ca82bb5a
commit
0f33a653d3
3 changed files with 56 additions and 1 deletions
41
src/lib/runtime-manager.ts
Normal file
41
src/lib/runtime-manager.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import path from 'node:path';
|
||||
|
||||
const SEMVER_PATTERN = /^v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
||||
|
||||
function ensureNonEmpty(value: string, field: string): string {
|
||||
const normalized = value.trim();
|
||||
if (!normalized) {
|
||||
throw new Error(`${field} must be a non-empty string`);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function normalizeVersion(version: string): string {
|
||||
const normalized = ensureNonEmpty(version, 'version');
|
||||
if (!SEMVER_PATTERN.test(normalized)) {
|
||||
throw new Error(`version must be semver-compatible: ${version}`);
|
||||
}
|
||||
return normalized.startsWith('v') ? normalized.slice(1) : normalized;
|
||||
}
|
||||
|
||||
export function resolveInstallHome(env: NodeJS.ProcessEnv): string {
|
||||
const home = env.BB_INSTALL_HOME ?? env.HOME ?? env.USERPROFILE;
|
||||
return ensureNonEmpty(home ?? '', 'install home');
|
||||
}
|
||||
|
||||
export function getRuntimePaths(home: string, version: string) {
|
||||
const installHome = ensureNonEmpty(home, 'home');
|
||||
const normalizedVersion = normalizeVersion(version);
|
||||
const beadboardHome = path.join(installHome, '.beadboard');
|
||||
const runtimeBase = path.join(beadboardHome, 'runtime');
|
||||
|
||||
return {
|
||||
installHome,
|
||||
beadboardHome,
|
||||
runtimeBase,
|
||||
runtimeRoot: path.join(runtimeBase, normalizedVersion),
|
||||
runtimeCurrentMetadata: path.join(runtimeBase, 'current.json'),
|
||||
shimDir: path.join(beadboardHome, 'bin'),
|
||||
shimNames: ['bb', 'beadboard'] as const,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue