fix: drop require

This commit is contained in:
Federico Grandi
2021-05-06 10:28:43 +02:00
parent 724766a764
commit 245f959e32
4 changed files with 42 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import fs from 'fs'
export type Input =
| 'add'
@@ -49,6 +50,21 @@ export function parseBool(value: any) {
} catch {}
}
export function readJSON(filePath: string) {
let fileContent: string
try {
fileContent = fs.readFileSync(filePath, { encoding: 'utf8' })
} catch {
throw `Couldn't read file. File path: ${filePath}`
}
try {
return JSON.parse(fileContent)
} catch {
throw `Couldn't parse file to JSON. File path: ${filePath}`
}
}
export function setOutput(name: Output, value: 'true' | 'false') {
core.debug(`Setting output: ${name}=${value}`)
outputs[name] = value