2020-05-08 13:06:16 +07:00
|
|
|
import { spawn } from 'child_process'
|
2020-05-08 13:47:46 +07:00
|
|
|
import { execPath } from 'process'
|
2020-05-08 11:29:39 +07:00
|
|
|
import { downloadSelfInstaller } from '../self-installer'
|
|
|
|
import { Inputs } from '../inputs'
|
|
|
|
|
2020-05-08 21:34:25 +07:00
|
|
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
2020-05-08 13:47:46 +07:00
|
|
|
const cp = spawn(execPath, {
|
2020-05-08 11:29:39 +07:00
|
|
|
env: {
|
|
|
|
PNPM_VERSION: inputs.version,
|
|
|
|
PNPM_DEST: inputs.dest,
|
|
|
|
PNPM_BIN_DEST: inputs.binDest,
|
|
|
|
PNPM_REGISTRY: inputs.registry,
|
|
|
|
},
|
2020-05-08 13:06:16 +07:00
|
|
|
stdio: ['pipe', 'inherit', 'inherit'],
|
|
|
|
})
|
|
|
|
|
2020-05-08 21:34:25 +07:00
|
|
|
const response = await downloadSelfInstaller()
|
|
|
|
response.body.pipe(cp.stdin)
|
2020-05-08 13:06:16 +07:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
cp.on('error', reject)
|
|
|
|
cp.on('close', resolve)
|
2020-05-08 11:29:39 +07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export default runSelfInstaller
|