Files
bun.sh/examples/spawn.ts
Jarred Sumner 9388b3f825 Add a zig fmt action (#2277)
* Add a zig fmt action

* add failing file

* Setup prettier better

* Update prettier-fmt.yml

* Fail on error

* Update prettier-fmt.yml

* boop

* boop2

* tar.gz

* Update zig-fmt.yml

* Update zig-fmt.yml

* Update zig-fmt.yml

* Update zig-fmt.yml

* Update zig-fmt.yml

* boop

* Update prettier-fmt.yml

* tag

* newlines

* multiline

* fixup

* Update zig-fmt.yml

* update it

* fixup

* both

* w

* Update prettier-fmt.yml

* prettier all the things

* Update package.json

* zig fmt

*  

* bump

* .

* quotes

* fix prettier ignore

* once more

* Update prettier-fmt.yml

* Update fallback.ts

* consistentcy

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-03-02 19:02:10 -08:00

49 lines
1.1 KiB
TypeScript

import { spawn, which } from "bun";
import { rmSync } from "fs";
import { basename } from "path";
const repo = process.argv.at(3) || "TheoBr/vercel-vite-demo";
const target = basename(repo) + "-main";
console.log("Downloading", repo, "to", "/tmp/" + target);
const archive = await fetch(`https://github.com/${repo}/archive/refs/heads/main.tar.gz`);
// remove the directory if it already exists locally
rmSync("/tmp/" + target, { recursive: true, force: true });
const tar = spawn({
cmd: ["tar", "-xzf", "-"],
stdin: archive.body,
stderr: "inherit",
stdout: "inherit",
cwd: "/tmp",
});
await tar.exited;
// if vercel isn't installed, install it
if (!which("vercel")) {
console.log("Installing vercel...");
const installer = spawn(["bun", "install", "-g", "vercel"], {
stderr: "inherit",
stdout: "inherit",
stdin: "inherit",
});
await installer.exited;
if (!which("vercel")) {
throw new Error("Failed to install Vercel CLI");
}
}
const { exited: deployed } = spawn({
cmd: ["vercel", "deploy", "--yes", "--public", target],
stdio: ["inherit", "inherit", "inherit"],
cwd: "/tmp",
});
await deployed;