const fs = require("node:fs");
const execa = require("execa");
const { join } = require("node:path");

(async () => {
	fs.rmSync(join(__dirname, "/../packages/backend/built"), {
		recursive: true,
		force: true,
	});
	fs.rmSync(join(__dirname, "/../packages/backend/node_modules"), {
		recursive: true,
		force: true,
	});

	fs.rmSync(join(__dirname, "/../packages/backend/native-utils/built"), {
		recursive: true,
		force: true,
	});
	fs.rmSync(join(__dirname, "/../packages/backend/native-utils/node_modules"), {
		recursive: true,
		force: true,
	});

	fs.rmSync(join(__dirname, "/../packages/calckey-js/built"), {
		recursive: true,
		force: true,
	});
	fs.rmSync(join(__dirname, "/../packages/calckey-js/node_modules"), {
		recursive: true,
		force: true,
	});

	fs.rmSync(join(__dirname, "/../built"), { recursive: true, force: true });
	fs.rmSync(join(__dirname, "/../node_modules"), {
		recursive: true,
		force: true,
	});

	execa("pnpm", ["store", "prune"], {
		cwd: join(__dirname, "/../"),
		stdio: "inherit",
	});

	execa("cargo", ["clean"], {
		cwd: join(__dirname, "/../packages/backend/native-utils"),
		stdio: "inherit",
	});
})();