Skip to content

Instantly share code, notes, and snippets.

@jebai0521
Last active March 12, 2020 01:19
Show Gist options
  • Save jebai0521/a9bd1f38b7a10d27775fe0bf58520c36 to your computer and use it in GitHub Desktop.
Save jebai0521/a9bd1f38b7a10d27775fe0bf58520c36 to your computer and use it in GitHub Desktop.
react-native-android-reverse-tool.js
#!/usr/bin/env node
const {exec} = require('child_process');
const execute = (cmd) => {
console.log('command ==> ', cmd);
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error);
}
resolve(stdout ? stdout : stderr);
});
});
};
const main = async () => {
const devices = await execute('adb devices');
devices.split('\n').forEach(async (line, index) => {
const cols = line.split('\t');
if (cols.length === 2 && cols[1] === 'device') {
const serial = cols[0];
console.log('device ==> ', serial);
await execute(`adb -s ${serial} reverse tcp:8081 tcp:8081`);
}
})
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment