import { insertRelease } from "../src/server/dbal/dbal";
import { ManifestType } from "../src/server/types";
import { getCarts } from "../src/server/util/carts";
import fs from "fs/promises";
import path from "path";

const doRelease = async (dir: string) => {
	const manifest = JSON.parse(await fs.readFile(path.join(dir, "picobook.json"), "utf8"));
	
	if (!ManifestType.Check(manifest)) {
		return false;
	}

	const carts = await getCarts(dir, manifest.carts);

	await insertRelease({
		manifest,
		carts,
	});
}

if (process.argv[2]) {
	// console.log(process.argv[3]);
	await doRelease(process.argv[3]);
} else {
	console.log("must pass in a path to a repo");
}