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.
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
/**
|
|
* Waggle server installer and launcher.
|
|
*
|
|
* npx <package> install download the server for this system and install it
|
|
* waggle-server start it and open the browser (same as `run`)
|
|
* waggle-server doctor check the installation
|
|
* waggle-server update install this tool's version over the installed one
|
|
* waggle-server uninstall remove the program; the data directory stays
|
|
*
|
|
* The tool is one self-contained script. Install copies it next to the
|
|
* payload, and the shim runs that copy with the payload's own Node.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { formatHelp, parseArgs } from './args.js';
|
|
import { UserError, doctor, install, run, uninstall, type Context } from './commands.js';
|
|
import { currentHost } from './platform.js';
|
|
|
|
declare const __WAGGLE_SERVER_VERSION__: string | undefined;
|
|
|
|
const VERSION: string = typeof __WAGGLE_SERVER_VERSION__ === 'string'
|
|
? __WAGGLE_SERVER_VERSION__
|
|
: (JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')) as { version: string }).version;
|
|
|
|
const MIN_NODE_MAJOR = 20;
|
|
|
|
/** The bundled script can be copied into an install; a TypeScript source cannot run on its own. */
|
|
function launcherSource(): string | null {
|
|
const self = fileURLToPath(import.meta.url);
|
|
return /\.m?js$/.test(self) ? self : null;
|
|
}
|
|
|
|
async function main(): Promise<number> {
|
|
const major = Number(process.versions.node.split('.')[0]);
|
|
if (major < MIN_NODE_MAJOR) {
|
|
console.error(`\n Waggle needs Node.js ${MIN_NODE_MAJOR} or newer to install. This is ${process.versions.node}.\n`);
|
|
return 1;
|
|
}
|
|
|
|
const { command, options, error } = parseArgs(process.argv.slice(2));
|
|
if (error) {
|
|
console.error(`\n ${error}`);
|
|
console.error(formatHelp(VERSION));
|
|
return 1;
|
|
}
|
|
|
|
const ctx: Context = {
|
|
host: currentHost(),
|
|
version: VERSION,
|
|
launcherSource: launcherSource(),
|
|
out: (line) => console.log(line),
|
|
};
|
|
switch (command) {
|
|
case 'help':
|
|
console.log(formatHelp(VERSION));
|
|
return 0;
|
|
case 'version':
|
|
console.log(VERSION);
|
|
return 0;
|
|
case 'install':
|
|
await install(ctx, options);
|
|
return 0;
|
|
case 'update':
|
|
await install(ctx, options, 'update');
|
|
return 0;
|
|
case 'doctor':
|
|
return doctor(ctx, options);
|
|
case 'uninstall':
|
|
return uninstall(ctx, options);
|
|
case 'run':
|
|
return run(ctx, options);
|
|
}
|
|
}
|
|
|
|
main().then(
|
|
(code) => {
|
|
process.exitCode = code;
|
|
},
|
|
(error: unknown) => {
|
|
console.error(`\n ${error instanceof Error ? error.message : String(error)}\n`);
|
|
if (!(error instanceof UserError) && error instanceof Error && error.stack) console.error(error.stack);
|
|
process.exitCode = 1;
|
|
},
|
|
);
|