Last active
March 12, 2020 01:19
-
-
Save jebai0521/a9bd1f38b7a10d27775fe0bf58520c36 to your computer and use it in GitHub Desktop.
react-native-android-reverse-tool.js
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
#!/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