react-native-navigation的迁移库

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const _ = require('lodash');
  2. const exec = require('./exec');
  3. const fs = require('fs');
  4. const release = _.includes(process.argv, 'release');
  5. function hackReactXcodeScript() {
  6. const fileToHack = `./node_modules/react-native/packager/react-native-xcode.sh`;
  7. const lines = _.split(String(fs.readFileSync(fileToHack)), '\n');
  8. lines[11] = release ? '' : `exit 0;`;
  9. fs.writeFileSync(fileToHack, _.join(lines, '\n'));
  10. }
  11. function buildProjForDetox() {
  12. const scheme = release ? `playground_release_Detox` : `playground_Detox`;
  13. const args = release ? '' : `GCC_PREPROCESSOR_DEFINITIONS="DEBUG=1 RCT_DEBUG=1 RCT_DEV=1 RCT_NSASSERT=1"`;
  14. exec.exec(`RCT_NO_LAUNCH_PACKAGER=true \
  15. cd ios && xcodebuild \
  16. -scheme ${scheme} build \
  17. -project playground.xcodeproj \
  18. -sdk iphonesimulator \
  19. -derivedDataPath ./DerivedData/playground \
  20. ${args}`);
  21. }
  22. function e2e() {
  23. try {
  24. kill(`detox-server`);
  25. exec.execAsync(`./node_modules/.bin/detox-server > ./detox-server.log 2>&1`);
  26. const detoxAppBuildPath = `ios/DerivedData/playground/Build/Products/${release ? 'Release' : 'Debug'}_Detox-iphonesimulator/playground.app`;
  27. exec.exec(`detoxAppBuildPath="${detoxAppBuildPath}" BABEL_ENV=test ./node_modules/mocha/bin/mocha e2e --recursive --compilers js:babel-register`);
  28. } finally {
  29. kill(`detox-server`);
  30. if (release) {
  31. kill(`Simulator`);
  32. kill(`CoreSimulator`);
  33. }
  34. exec.exec(`cat ./detox-server.log`);
  35. exec.exec(`rm -f ./detox-server.log`);
  36. exec.exec(`sleep 5`);
  37. }
  38. }
  39. function kill(process) {
  40. exec.execSilent(`pkill -f "${process}"`);
  41. }
  42. function run() {
  43. hackReactXcodeScript();
  44. buildProjForDetox();
  45. e2e();
  46. }
  47. run();