import { basename } from 'node:path'; import { readConfig, resolveSource } from "./config.js"; import { readSettings } from "./pageContext.js"; /** * Resolve the target server, document path, credentials, and local dest directory. * * If source is provided → resolveSource for serverUrl, credentials. * Otherwise → read settings.json for documentPath, readConfig for credentials. * dest: explicit destination → basename of path → server hostname → '.' * * Shared across all push/pull utilities. */ export async function resolveTarget(ctx, log, source, destination) { let serverUrl; let documentPath; let username; let password; let auth; if (source) { const resolved = await resolveSource(ctx, log, source); serverUrl = resolved.serverUrl; documentPath = resolved.documentPath; username = resolved.username; password = resolved.password; auth = resolved.auth; } else { const existingSettings = await readSettings(); if (!existingSettings?.path) { throw new Error('No source argument and no settings.json found in current directory'); } documentPath = existingSettings.path; const config = await readConfig(ctx, log); serverUrl = config.serverUrl; username = config.username; password = config.password; auth = Buffer.from(`${username}:${password}`).toString('base64'); } const pathBase = basename(documentPath); const dest = destination ?? (source ? pathBase || new URL(serverUrl).hostname : '.'); return { serverUrl, documentPath, username, password, auth, dest }; } //# sourceMappingURL=resolveTarget.js.map