Move fileExistsSync to utils

This commit is contained in:
Peter Evans 2020-07-18 17:55:42 +09:00
parent f4ee4a8333
commit 794518a553
4 changed files with 39 additions and 164 deletions

View file

@ -1,4 +1,5 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import * as path from 'path'
export function getInputAsArray(
@ -111,3 +112,28 @@ export function parseDisplayNameEmail(
email: email
}
}
export function fileExistsSync(path: string): boolean {
if (!path) {
throw new Error("Arg 'path' must not be empty")
}
let stats: fs.Stats
try {
stats = fs.statSync(path)
} catch (error) {
if (error.code === 'ENOENT') {
return false
}
throw new Error(
`Encountered an error when checking whether path '${path}' exists: ${error.message}`
)
}
if (!stats.isDirectory()) {
return true
}
return false
}