react-native-navigation的迁移库

start.js 667B

123456789101112131415161718192021222324252627282930
  1. const exec = require('shell-utils').exec;
  2. run();
  3. function run() {
  4. const port = findPort();
  5. exec.execSync(`watchman watch-del-all || true`);
  6. exec.execSync(`adb reverse tcp:${port} tcp:${port} || true`);
  7. exec.execSync(`node ./node_modules/react-native/local-cli/cli.js start --port=${port} --root=./playground`);
  8. }
  9. function findPort() {
  10. let port = 8081;
  11. if (!process.env.CI) {
  12. return port;
  13. }
  14. while (!isPortOpen(port)) {
  15. port = Number((Math.random() * 1000).toFixed(0)) + 35000;
  16. }
  17. return port;
  18. }
  19. function isPortOpen(port) {
  20. try {
  21. return !exec.execSyncRead(`netstat -vanp tcp | grep ${port}`);
  22. } catch (e) {
  23. return true;
  24. }
  25. }