Create some files

This commit is contained in:
khai96_ 2020-05-08 11:29:39 +07:00
parent a7354264cc
commit cd1794a16e
6 changed files with 65 additions and 0 deletions

21
src/inputs/index.ts Normal file
View File

@ -0,0 +1,21 @@
import { getInput, InputOptions } from '@actions/core'
export interface Inputs {
readonly version: string
readonly dest: string
readonly binDest: string
readonly registry: string
}
const options: InputOptions = {
required: true,
}
export const getInputs = (): Inputs => ({
version: getInput('version', options),
dest: getInput('dest', options),
binDest: getInput('bin_dest', options),
registry: getInput('registry', options),
})
export default getInputs

17
src/install/index.ts Normal file
View File

@ -0,0 +1,17 @@
import { setFailed } from '@actions/core'
import { getInputs } from '../inputs'
import runSelfInstaller from './run'
export { runSelfInstaller }
export async function install() {
const { error, status } = await runSelfInstaller(getInputs())
if (error) return setFailed(error)
if (status) {
return setFailed(`Something does wrong, self-installer exits with code ${status}`)
}
}
export default install

18
src/install/run.ts Normal file
View File

@ -0,0 +1,18 @@
import { spawnSync } from 'child_process'
import { downloadSelfInstaller } from '../self-installer'
import { Inputs } from '../inputs'
export async function runSelfInstaller(inputs: Inputs) {
return spawnSync('node', {
env: {
PNPM_VERSION: inputs.version,
PNPM_DEST: inputs.dest,
PNPM_BIN_DEST: inputs.binDest,
PNPM_REGISTRY: inputs.registry,
},
input: await downloadSelfInstaller(),
stdio: 'inherit',
})
}
export default runSelfInstaller

View File

@ -0,0 +1,4 @@
import download from 'download'
import url from './url'
export const downloadSelfInstaller = () => download(url)
export default downloadSelfInstaller

View File

@ -0,0 +1,2 @@
export * from './url'
export * from './download'

View File

@ -0,0 +1,3 @@
export const ref = '301414cec74a2b6b63c95b42f2ad1790ccb980ed'
export const url = `https://raw.githubusercontent.com/pnpm/self-installer/${ref}/install.js`
export default url