import { spawn } from 'child_process' ; import * as helpers from '../helpers' ; import * as path from './path' ; import * as os from './os' ; async function runLink ( name ? ) { return new Promise < void > ( ( packageResolve , packageReject ) => { const spawned = spawn ( 'react-native' , name ? [ 'link' , name ] : [ 'link' ] , { cwd : path . project . path ( ) , shell : os . win } ) ; spawned . stdout . pipe ( process . stdout ) ; spawned . stderr . pipe ( process . stderr ) ; spawned . on ( 'error' , e => packageReject ( new Error ( 'Error spawning react-native link' + e ) ) ) ; spawned . on ( 'close' , packageResolve ) ; spawned . stdin . end ( ) ; } ) ; } param { string [ ] } forceLink returns { Promise < void > } export async function link ( forceLink ? ) { return new Promise < void > ( async ( resolve , reject ) => { if ( forceLink && forceLink . length ) { for ( const name in forceLink ) { if ( forceLink . hasOwnProperty ( name ) ) { helpers . logInfo ( 'running react-native link for ' + [ forceLink [ name ] ] ) ; await runLink ( forceLink [ name ] ) ; } } } helpers . logInfo ( 'running react-native link to link assets' ) ; await runLink ( ) ; resolve ( ) ; } ) ; }