Files
ruflo/v3/@claude-flow/cli/scripts/prepare-publish.mjs
T
randRuFlo 11cc8cd648 feat(cli,console): ruflo tui --plain, exit 2 without a terminal, bundle staged for publish, esbuild declared (ADR-489 A-E)
- E: `ruflo tui --plain` prints one plain frame and exits 0; without a TTY and
  without --plain it prints a one-line hint on stderr and exits 2 (no frame).
  Tests for terminal, non-terminal, --plain in a terminal, no raw mode, and
  through the command with the real bundle.
- A: esbuild is a declared root devDependency (^0.27.2, already locked).
- B: v3/@claude-flow/cli/scripts/prepare-publish.mjs builds and stages
  plugins/ruflo-console/dist/tui.mjs so a registry install runs `ruflo tui`.
  Measured: +449,345 bytes on the CLI tarball.
- ADR-489: status Accepted; section 8 records decisions A-E (C: Swarm, Events,
  Missions, Room; D: Codex read-only by default, no danger-full-access, OpenRouter
  https-only to openrouter.ai + convoTargets hosts). Repairs a corrupted table row
  that had pasted copies of the file head into the ADR.
- README: a short ruflo tui section.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-10-11 14:07:28 -04:00

71 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
import { cp, mkdir, rm } from 'node:fs/promises';
import { spawnSync } from 'node:child_process';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { stageInternalRuntimeBundles } from '../../../../scripts/stage-internal-runtime-bundles.mjs';
const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const repoRoot = resolve(packageDir, '..', '..', '..');
const pluginsDir = join(packageDir, 'plugins');
// `dist` is intentionally ignored by Git, so publishing without a build can
// create a tarball whose declared entry point does not exist. Build the only
// emitted project reference CLI needs (`@claude-flow/swarm`) and then CLI.
// Do not use `tsc --build`: it recursively rebuilds unrelated optional
// workspace packages whose development-only dependencies are not required to
// package this CLI.
const compiler = join(packageDir, 'node_modules', 'typescript', 'bin', 'tsc');
for (const buildDir of [resolve(packageDir, '..', 'swarm'), packageDir]) {
const build = spawnSync(process.execPath, [compiler], {
cwd: buildDir,
stdio: 'inherit',
});
if (build.error) throw build.error;
if (build.status !== 0) {
throw new Error(`TypeScript release build failed for ${buildDir} with exit code ${build.status ?? 'unknown'}`);
}
}
await stageInternalRuntimeBundles(packageDir);
await cp(join(repoRoot, 'README.md'), join(packageDir, 'README.md'));
await rm(pluginsDir, { recursive: true, force: true });
await mkdir(pluginsDir, { recursive: true });
await cp(
join(repoRoot, 'plugins', 'ruflo-metaharness'),
join(pluginsDir, 'ruflo-metaharness'),
{ recursive: true },
);
// ADR-489: `ruflo tui` loads one bundled file from the CLI's own install
// (plugins/ruflo-console/dist/tui.mjs, see src/commands/tui.ts). Build it from
// the plugin's source with the repo's esbuild and stage only that file, so the
// registry install runs the console and the tarball carries no console source.
const tuiBundle = join(pluginsDir, 'ruflo-console', 'dist', 'tui.mjs');
const tuiBuild = spawnSync(
process.execPath,
[join(repoRoot, 'plugins', 'ruflo-console', 'scripts', 'build-tui.mjs'), '--outfile', tuiBundle],
{ cwd: repoRoot, stdio: 'inherit' },
);
if (tuiBuild.error) throw tuiBuild.error;
if (tuiBuild.status !== 0) {
throw new Error(`build-tui.mjs failed with exit code ${tuiBuild.status ?? 'unknown'}`);
}
for (const script of [
'generate-catalog-manifest.mjs',
'sign-helpers.mjs',
'verify-helpers.mjs',
]) {
const result = spawnSync(process.execPath, [join(packageDir, 'scripts', script)], {
cwd: packageDir,
stdio: 'inherit',
});
if (result.error) throw result.error;
if (result.status !== 0) {
throw new Error(`${script} failed with exit code ${result.status ?? 'unknown'}`);
}
}