Created
August 28, 2018 16:06
-
-
Save markgoodyear/3b900a0cc1708b9c6c3c487d42ab5806 to your computer and use it in GitHub Desktop.
Runs react-native run-ios to the current open simulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const child_process = require('child_process'); | |
const runOnCurrentSim = () => { | |
try { | |
const simulators = JSON.parse( | |
child_process.execFileSync( | |
'xcrun', | |
['simctl', 'list', '--json', 'devices'], | |
{encoding: 'utf8'}, | |
), | |
); | |
const device = Object.keys(simulators.devices).reduce((obj, item) => { | |
const deviceArr = simulators.devices[item].find(device => device.state === 'Booted' && device.availability === '(available)'); | |
if (deviceArr && deviceArr.length === 0 || typeof deviceArr === 'undefined') return obj; | |
obj = deviceArr; | |
return obj | |
}, {}); | |
child_process.execSync( | |
`react-native run-ios --simulator="${device.name || 'iPhone 6'}"`, | |
{ stdio: [0, 1, 2] } | |
); | |
} catch (e) { | |
throw new Error(e); | |
} | |
} | |
runOnCurrentSim(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment