Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
4.7 kB · 153 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154#!/usr/bin/env bun/** * Fixture lifecycle CLI. * * bun run test:pushwork-sync:fixture init <name> Copy fixture into a workspace + pushwork init. * bun run test:pushwork-sync:fixture reset <name> Wipe and re-init. * bun run test:pushwork-sync:fixture sync <name> pushwork sync inside a workspace. * bun run test:pushwork-sync:fixture url <name> Print the root URL of an initialized workspace. * bun run test:pushwork-sync:fixture status Show every fixture's state. */
import { getHarnessConfig, type HarnessConfig } from '../support/env.ts'import { getServerStatus } from '../support/server.ts'import { initFixture, listFixtureNames, listFixtureStatuses, readFixtureRootUrl, syncFixture,} from '../support/pushwork.ts'
const HELP = `\Usage: test:pushwork-sync:fixture <command> [args]
Commands: init <name> Copy fixture into a fresh workspace and run pushwork init. Refuses to overwrite — use 'reset' (or --force) to clobber. reset <name> Equivalent to 'init <name> --force'. sync <name> Run pushwork sync inside an initialized workspace. url <name> Print the root Automerge URL of an initialized workspace. status List every fixture with its current state.
Fixtures live under tests/integration/pushwork-sync/fixtures/<name>/.Workspaces live under .dev-state/pushwork-sync/workspaces/<name>/.`
async function main() { const [command, ...args] = process.argv.slice(2) const config = getHarnessConfig()
switch (command) { case 'init': await runInit(config, args, { allowExisting: false }) break case 'reset': await runInit(config, args, { allowExisting: true }) break case 'sync': runSync(config, args) break case 'url': runUrl(config, args) break case 'status': runStatus(config) break case undefined: case '-h': case '--help': process.stdout.write(HELP) break default: process.stderr.write(`Unknown command: ${command}\n\n${HELP}`) process.exit(2) }}
async function runInit( config: HarnessConfig, args: string[], { allowExisting }: { allowExisting: boolean },) { const name = args[0] if (!name) { process.stderr.write( `Missing fixture name.\n` + `Available: ${listFixtureNames().join(', ') || '(none)'}\n`, ) process.exit(2) }
// Validate the sync server is up before we touch the filesystem. const status = getServerStatus(config) if (!status.running) { process.stderr.write( `Sync server is not running.\n` + `Start it first: bun run test:pushwork-sync:server:up\n`, ) process.exit(1) }
const force = allowExisting || args.includes('--force') const { workspaceDir, rootUrl, fixtureName } = initFixture(config, name, { force })
process.stdout.write( `Initialized fixture '${fixtureName}'.\n` + ` Workspace: ${workspaceDir}\n` + ` Sync URL: ${config.syncServerUrl}\n` + ` Root URL: ${rootUrl}\n` + `\n` + `To open in Reams:\n` + ` 1. In another terminal, run:\n` + ` VITE_SYNC_SERVER_URL=${config.syncServerUrl} bun run dev\n` + ` 2. Open ${config.devServerUrl}\n` + ` 3. In the browser DevTools console, run:\n` + ` localStorage.setItem('reams:vault-root-url', '${rootUrl}')\n` + ` location.reload()\n` + `\n` + `(An in-app 'open vault by URL' affordance will replace step 3 in a future change.)\n`, )}
function runSync(config: HarnessConfig, args: string[]) { const name = args[0] if (!name) { process.stderr.write('Missing fixture name.\n') process.exit(2) } syncFixture(config, name) process.stdout.write(`Synced fixture '${name}'.\n`)}
function runUrl(config: HarnessConfig, args: string[]) { const name = args[0] if (!name) { process.stderr.write('Missing fixture name.\n') process.exit(2) } process.stdout.write(readFixtureRootUrl(config, name) + '\n')}
function runStatus(config: HarnessConfig) { const statuses = listFixtureStatuses(config) if (statuses.length === 0) { process.stdout.write('No fixtures defined under tests/integration/pushwork-sync/fixtures/.\n') return } for (const s of statuses) { const tag = s.initialized ? 'initialized' : s.hasWorkspace ? 'workspace-exists-but-not-initialized' : 'not-initialized' process.stdout.write(` ${s.name} [${tag}]`) if (s.rootUrl) process.stdout.write(` ${s.rootUrl}`) process.stdout.write('\n') }}
main().catch((err: Error) => { process.stderr.write(`${err.stack ?? err.message}\n`) process.exit(1)})