Files
pnpm-setup/src/inputs/index.ts

36 lines
991 B
TypeScript
Raw Normal View History

2020-05-08 14:12:16 +07:00
import { inspect } from 'util'
import { getInput, error, InputOptions } from '@actions/core'
import * as glob from '@actions/glob'
2020-05-08 11:29:39 +07:00
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
}
const options: InputOptions = {
required: true,
}
2020-05-08 14:12:16 +07:00
async function parsePath(pattern: string, inputName: string) {
const builder = await glob.create(pattern)
const paths = await builder.glob()
if (paths.length !== 1) {
error(`Input ${inputName} is expected to match 1 path, but it matches ${paths.length}: ${inspect(paths)}`)
2020-05-08 14:17:43 +07:00
throw process.exit(1)
2020-05-08 14:12:16 +07:00
}
return paths[0]
}
const parseInputPath = (name: string) => parsePath(getInput(name, options), name)
export const getInputs = async (): Promise<Inputs> => ({
2020-05-08 11:29:39 +07:00
version: getInput('version', options),
2020-05-08 14:12:16 +07:00
dest: await parseInputPath('dest'),
binDest: await parseInputPath('bin_dest'),
2020-05-08 11:29:39 +07:00
registry: getInput('registry', options),
})
export default getInputs