-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import { spawn } from "node:child_process"; | ||
import { dirname, join } from "node:path"; | ||
import { once } from "node:events"; | ||
import { join, dirname } from "node:path"; | ||
import { existsSync } from "node:fs"; | ||
const file = join(dirname(process.argv[1]), "main.ts"); // 👈 CHANGE ME! | ||
const subprocess = spawn(`exec "$__FILE"`, { | ||
shell: "bash", | ||
stdio: "inherit", | ||
env: { ...process.env, __FILE: file }, | ||
}); | ||
await once(subprocess, "spawn"); | ||
subprocess.on("exit", (x) => process.exit(x)); | ||
const response = await fetch("https://deno.com/versions.json"); | ||
const json = await response.json(); | ||
const tag = json.cli.find((x) => x.startsWith("v1.")); | ||
const version = tag.slice(1); | ||
const DENO_INSTALL = join( | ||
process.env.RUNNER_TOOL_CACHE, | ||
"deno", | ||
version, | ||
process.arch, | ||
); | ||
if (!existsSync(DENO_INSTALL)) { | ||
const subprocess1 = spawn( | ||
`curl -fsSL https://deno.land/x/install/install.sh | sh -s "$tag"`, | ||
{ shell: "bash", env: { ...process.env, DENO_INSTALL, tag } }, | ||
); | ||
await once(subprocess1, "exit"); | ||
} | ||
const subprocess2 = spawn( | ||
join(DENO_INSTALL, "bin", "deno"), | ||
["run", "-Aq", file], | ||
{ stdio: "inherit" }, | ||
); | ||
await once(subprocess2, "spawn"); | ||
subprocess2.on("exit", (x) => process.exit(x)); |