Move run-install to its own module

This commit is contained in:
khai96_ 2020-05-09 20:01:25 +07:00
parent 91d3d73121
commit 6fe65dc1af
4 changed files with 43 additions and 37 deletions

BIN
dist/index.js vendored

Binary file not shown.

View File

@ -1,21 +1,6 @@
import process from 'process'
import { getInput, error, InputOptions } from '@actions/core'
import { getInput, InputOptions } from '@actions/core'
import expandTilde from 'expand-tilde'
import { safeLoad } from 'js-yaml'
import Ajv from 'ajv'
import runInstallSchema from './run-install-input.schema.json'
interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
@ -31,25 +16,6 @@ const options: InputOptions = {
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = safeLoad(getInput(name, options))
const ajv = new Ajv({
allErrors: true,
async: false,
})
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) {
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
}
return process.exit(1)
}
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
}
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: parseInputPath('dest'),

View File

@ -14,7 +14,7 @@
"esModuleInterop": true,
"resolveJsonModule": true
},
"input": "index.ts",
"input": "run-install.ts",
"symbol": "RunInstallInput",
"output": "run-install-input.schema.json"
}

40
src/inputs/run-install.ts Normal file
View File

@ -0,0 +1,40 @@
import process from 'process'
import { safeLoad } from 'js-yaml'
import Ajv from 'ajv'
import { getInput, error, InputOptions } from '@actions/core'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall {
readonly recursive?: boolean
readonly cwd?: string
readonly args?: readonly string[]
}
export type RunInstallInput =
| null
| boolean
| RunInstall
| RunInstall[]
const options: InputOptions = {
required: true,
}
export function parseRunInstall(name: string): RunInstall[] {
const result: RunInstallInput = safeLoad(getInput(name, options))
const ajv = new Ajv({
allErrors: true,
async: false,
})
const validate = ajv.compile(runInstallSchema)
if (!validate(result)) {
for (const errorItem of validate.errors!) {
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
}
return process.exit(1)
}
if (!result) return []
if (result === true) return [{ recursive: true }]
if (Array.isArray(result)) return result
return [result]
}