The launcher is now a self-contained installer with install, run, update, doctor and uninstall. Install downloads waggle-server-<version>-<target> .tar.gz, checks its SHA-256, unpacks it into a per-user program directory and writes a waggle-server command that runs the tool on the archive's own Node. Nothing is built on the user's machine and the data directory stays WAGGLE_DATA_DIR or ~/.waggle. scripts/build-server-archive.mjs packs the staged desktop sidecar payload with the built web UI and a manifest. The download location waits for the repository decision; until then install takes --from or WAGGLE_RELEASE_BASE_URL (ADR-0009). Removes install.sh, scripts/waggle-server.sh and their CI job, which the installer replaces, and the bin name clash with @waggle/cli.
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
/**
|
|
* Where things live on each system: the release target of this machine, the
|
|
* install directory, the directory for the command shim and the data
|
|
* directory the sidecar uses.
|
|
*/
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
/** The command the installer puts on the PATH. A working name until the product name is decided. */
|
|
export const COMMAND_NAME = 'waggle-server';
|
|
|
|
export interface Host {
|
|
platform: NodeJS.Platform;
|
|
arch: string;
|
|
homedir: string;
|
|
env: NodeJS.ProcessEnv;
|
|
}
|
|
|
|
export function currentHost(): Host {
|
|
return { platform: process.platform, arch: process.arch, homedir: os.homedir(), env: process.env };
|
|
}
|
|
|
|
/** Release targets of v1: Windows x64, macOS on Apple and Intel, Linux x64. */
|
|
const TARGETS: Record<string, string> = {
|
|
'win32-x64': 'windows-x64',
|
|
'darwin-arm64': 'macos-arm64',
|
|
'darwin-x64': 'macos-x64',
|
|
'linux-x64': 'linux-x64',
|
|
};
|
|
|
|
export function releaseTarget(host: Pick<Host, 'platform' | 'arch'>): string | null {
|
|
return TARGETS[`${host.platform}-${host.arch}`] ?? null;
|
|
}
|
|
|
|
export function assetName(version: string, target: string): string {
|
|
return `waggle-server-${version}-${target}.tar.gz`;
|
|
}
|
|
|
|
export function pathApi(platform: NodeJS.Platform): path.PlatformPath {
|
|
return platform === 'win32' ? path.win32 : path.posix;
|
|
}
|
|
|
|
/** Program files, not user data: uninstall removes this directory whole. */
|
|
export function defaultInstallDir(host: Host): string {
|
|
const p = pathApi(host.platform);
|
|
if (host.platform === 'win32') {
|
|
const localAppData = host.env.LOCALAPPDATA || p.join(host.homedir, 'AppData', 'Local');
|
|
return p.join(localAppData, 'Waggle', 'server');
|
|
}
|
|
if (host.platform === 'darwin') {
|
|
return p.join(host.homedir, 'Library', 'Application Support', 'Waggle', 'server');
|
|
}
|
|
const dataHome = host.env.XDG_DATA_HOME || p.join(host.homedir, '.local', 'share');
|
|
return p.join(dataHome, 'waggle', 'server');
|
|
}
|
|
|
|
/**
|
|
* Where the command shim goes. On Windows it stays inside the install
|
|
* directory: the installer never edits the user's PATH, it prints how to.
|
|
*/
|
|
export function defaultBinDir(host: Host, installDir: string): string {
|
|
const p = pathApi(host.platform);
|
|
return host.platform === 'win32' ? p.join(installDir, 'bin') : p.join(host.homedir, '.local', 'bin');
|
|
}
|
|
|
|
/** Same rule as the sidecar's resolveDataDir: WAGGLE_DATA_DIR, else ~/.waggle. */
|
|
export function defaultDataDir(host: Host): string {
|
|
return host.env.WAGGLE_DATA_DIR || pathApi(host.platform).join(host.homedir, '.waggle');
|
|
}
|
|
|
|
export function isOnPath(host: Host, dir: string): boolean {
|
|
const p = pathApi(host.platform);
|
|
const entries = (host.env.PATH ?? host.env.Path ?? '').split(p.delimiter).filter(Boolean);
|
|
const normalize = (value: string) => {
|
|
const resolved = p.resolve(value);
|
|
return host.platform === 'win32' ? resolved.toLowerCase() : resolved;
|
|
};
|
|
return entries.some((entry) => normalize(entry) === normalize(dir));
|
|
}
|