Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Runs react-native run-ios to the current open simulator
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
You can’t perform that action at this time.