Skip to content

Instantly share code, notes, and snippets.

@markgoodyear
Created August 28, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markgoodyear/3b900a0cc1708b9c6c3c487d42ab5806 to your computer and use it in GitHub Desktop.
Save markgoodyear/3b900a0cc1708b9c6c3c487d42ab5806 to your computer and use it in GitHub Desktop.
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