import { globSync } from "glob";
import { join } from "node:path";
import { writeFileSync, readFileSync } from "node:fs";
import exec from "execa";
import { parse, stringify } from "yaml";

const files = globSync("**/package.json");

for (const file of files) {
	const json = JSON.parse(readFileSync(file));
	json["devDependencies"] = undefined;
	writeFileSync(file, JSON.stringify(json, null, "\t"));
}

const file = join("./", ".yarnrc.yml");
const yarnrc = parse(readFileSync(file, "utf8"));
yarnrc["supportedArchitectures"] = {
	cpu: ["current"],
	libc: ["current"],
	os: ["current"],
};
writeFileSync(file, stringify(yarnrc));

exec("yarn", ["install"], {
	stdout: process.stdout,
	stderr: process.stderr,
});
