import { $ } from "bun"; import { Array, Option, Order, pipe } from "effect"; import { readdir } from "node:fs/promises"; const launchContainers = async (): Promise => { return await $`podman compose up -d`.text(); }; const getLatestDbExport = async (): Promise => { return pipe( await readdir(`../db`), (paths: ReadonlyArray) => Array.sort(paths, Order.string), (sortedPaths: ReadonlyArray) => Array.last(sortedPaths), (last: Option.Option) => Option.getOrThrowWith(last, () => new Error("Aucun export de BDD n'est disponible.")), ); }; const importLatestDbInWordpressContainer = async (exportPath: string) => { await $`podman exec -it haikuatelier.fr-wordpress fish -c "cd web && wp --allow-root db import ${exportPath}"`; }; try { // S'assure que les conteneurs soient lancées. await launchContainers(); const latestExportPath: string = `../db/${await getLatestDbExport()}`; console.log(`Dernier export : ${latestExportPath}`); // Exécute l'opération d'import dans le conteneur WordPress via wp-cli. await importLatestDbInWordpressContainer(latestExportPath); } catch (error: unknown) { if (error instanceof $.ShellError) { console.error(`Commande échouée avec code d'erreur: ${error.exitCode}`); console.log(error.stdout.toString()); console.log(error.stderr.toString()); } else { console.error(error); } }