Graphical PDS migrator for AT Protocol
at main 1.4 kB view raw
1import consola from "consola"; 2import { TestEnvironment } from "../utils/test-env.ts"; 3import { CredentialSession } from "@atproto/api"; 4import { TEST_CONFIG } from "../utils/config.ts"; 5 6async function main() { 7 const env = await TestEnvironment.create(); 8 9 const session = new CredentialSession(new URL(env.sourcePds.url)); 10 11 const result = await session.createAccount({ 12 handle: TEST_CONFIG.handle, 13 password: TEST_CONFIG.password, 14 email: TEST_CONFIG.email, 15 }); 16 17 const fs = await import("fs/promises"); 18 const envPath = "../.env"; 19 20 try { 21 const envContent = (await fs.readFile(envPath, "utf8").catch(() => "")) || 22 ""; 23 if (!envContent.includes(`PLC_URL=${env.plc.url}`)) { 24 await fs.writeFile( 25 envPath, 26 `${envContent}PLC_URL=${env.plc.url}\n`, 27 "utf8", 28 ); 29 consola.info(`PLC_URL set to ${env.plc.url} in .env file`); 30 } else { 31 consola.info(`PLC_URL is already set to ${env.plc.url} in .env file`); 32 } 33 } catch (error) { 34 consola.error("Failed to update .env file", error); 35 throw error; 36 } 37 38 consola.success("Test environment created successfully"); 39 consola.info(`PLC running at ${env.plc.url}`); 40 consola.info(`Source PDS running at ${env.sourcePds.url}`); 41 consola.info(`Target PDS running at ${env.targetPds.url}`); 42 consola.info(`Login as 👤 ${result.data.did} 🔑 ${TEST_CONFIG.password}`); 43} 44 45main();