Raw
1 import { access, lstat, mkdtemp } from "fs/promises"
2 import path, { sep } from "path"
3 import { tmpdir } from "os"
4
5 export async function isFile(filePath: string): Promise<boolean> {
6 try {
7 return (await lstat(path.resolve(filePath))).isFile()
8 } catch (err) {
9 console.log(err)
10 return false
11 }
12 }
13
14 export async function exists(filePath: string): Promise<boolean> {
15 try {
16 await access(path.resolve(filePath))
17 return true
18 } catch (err) {
19 return false
20 }
21 }
22
23 export const getTmpDirectory = async () => {
24 /**
25 * RUNNER_TEMP: GitHub action, the path to a temporary directory on the runner.
26 */
27 const tmpDir = process.env["RUNNER_TEMP"] ?? tmpdir()
28 return await mkdtemp(`${tmpDir}${sep}`)
29 }