mirror of
				https://github.com/pnpm/action-setup.git
				synced 2025-11-04 13:29:08 +08:00 
			
		
		
		
	Create some files
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/inputs/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/inputs/index.ts
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										17
									
								
								src/install/index.ts
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										18
									
								
								src/install/run.ts
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										4
									
								
								src/self-installer/download.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/self-installer/download.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
import download from 'download'
 | 
			
		||||
import url from './url'
 | 
			
		||||
export const downloadSelfInstaller = () => download(url)
 | 
			
		||||
export default downloadSelfInstaller
 | 
			
		||||
							
								
								
									
										2
									
								
								src/self-installer/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/self-installer/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
export * from './url'
 | 
			
		||||
export * from './download'
 | 
			
		||||
							
								
								
									
										3
									
								
								src/self-installer/url.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/self-installer/url.ts
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Reference in New Issue
	
	Block a user