import { cp, mkdir, rm } from "node:fs/promises"; import { join } from "node:path"; import { $ } from "bun"; const root = process.cwd(); const packageJson = JSON.parse(await Bun.file(join(root, "package.json")).text()) as { version: string }; const version = packageJson.version; const name = `gitea-github-theme-v${version}`; const releaseRoot = join(root, "release"); const packageRoot = join(releaseRoot, name); await rm(releaseRoot, { recursive: true, force: true }); await mkdir(join(packageRoot, "custom", "public", "assets", "css"), { recursive: true }); await mkdir(join(packageRoot, "custom", "templates"), { recursive: true }); await mkdir(join(packageRoot, "custom", "options"), { recursive: true }); await cp(join(root, "dist", "theme-github-dev.css"), join(packageRoot, "custom", "public", "assets", "css", "theme-github-dev.css")); await cp( join(root, "dist", "theme-github-dev-dark.css"), join(packageRoot, "custom", "public", "assets", "css", "theme-github-dev-dark.css"), ); await cp(join(root, ".gitea", "custom", "templates"), join(packageRoot, "custom", "templates"), { recursive: true }); await cp(join(root, ".gitea", "custom", "options"), join(packageRoot, "custom", "options"), { recursive: true }); await cp(join(root, "README.md"), join(packageRoot, "README.md")); await $`tar -C ${releaseRoot} -czf ${releaseRoot}/${name}.tar.gz ${name}`; if (process.platform === "win32") { await $`powershell -NoProfile -Command Compress-Archive -Path ${packageRoot} -DestinationPath ${join(releaseRoot, `${name}.zip`)} -Force`; } else { await $`zip -qr ${join(releaseRoot, `${name}.zip`)} ${name}`.cwd(releaseRoot); } const artifacts = [`${name}.tar.gz`, `${name}.zip`]; const checksumLines = []; for (const artifact of artifacts) { const file = Bun.file(join(releaseRoot, artifact)); const hash = new Bun.CryptoHasher("sha256"); hash.update(await file.arrayBuffer()); checksumLines.push(`${hash.digest("hex")} ${artifact}`); } await Bun.write(join(releaseRoot, "checksums.txt"), `${checksumLines.join("\n")}\n`); console.log(`packaged release ${name}`);