Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #
  3. # Determine divergence from create-react-app!
  4. # Use this if you've ejected from create-react-app and want to see how its
  5. # latest output would differ in key areas (package.json, config, scripts).
  6. #
  7. # - Assumes you can run create-react-app, so make sure it's installed.
  8. # - Only shows files you've modified or removed from create-react-app.
  9. # - Runs $FORMAT_COMMAND below on the create-react-app directory so formatting
  10. # differences don't show up. Use something like Prettier, eslint --fix, etc.
  11.  
  12. set -e # Fail on error.
  13. set -x # Show what we're doing.
  14.  
  15. APP_DIR="$PWD"
  16. ESLINT="$APP_DIR/node_modules/.bin/eslint"
  17. FORMAT_COMMAND=( "$ESLINT" --config "$APP_DIR/.eslintrc.js" --fix . )
  18.  
  19. # Make a new directory in which to run create-react-app.
  20. NEW_APP_DIR="$(mktemp -d)/new-react-app"
  21.  
  22. # Note that we added /new-react-app onto the temp directory above.
  23. # That's to ensure that create-react-app likes our directory.
  24. mkdir -p "$NEW_APP_DIR"
  25.  
  26. # Run it!
  27. create-react-app "$NEW_APP_DIR"
  28.  
  29. # Eject!
  30. cd "$NEW_APP_DIR"
  31. yes | head -n 1 | yarn run eject
  32.  
  33. # Remove files we don't care about diffing. This is easier than getting
  34. # `git diff` to exclude them.
  35. rm -rf .gitignore README* node_modules package-lock.json public src yarn.lock
  36.  
  37. # Run our local formatting config on the create-react-app output so that it's
  38. # minimally different from ours.
  39. "${FORMAT_COMMAND[@]}"
  40.  
  41. # Come back to our app so the remaining commands are based here.
  42. cd "$APP_DIR"
  43.  
  44. # Make the new app's package.json look like ours, except for devDependencies
  45. # and a few config fields, so that only those show up in the diff.
  46. node -e "
  47. const newPath = process.argv[1] + '/package.json';
  48. const thisApp = require('./package.json');
  49. const newApp = require(newPath);
  50. thisApp.dependencies = newApp.dependencies;
  51. thisApp.devDependencies = newApp.devDependencies;
  52. thisApp.jest = newApp.jest;
  53. thisApp.babel = newApp.babel;
  54. thisApp.eslintConfig = newApp.eslintConfig;
  55. require('fs').writeFileSync(newPath, JSON.stringify(thisApp, null, 2) + '\n');
  56. " "$NEW_APP_DIR"
  57.  
  58. # Show the diff!
  59. git diff --no-index --diff-filter=MD --color "$NEW_APP_DIR" . 2>/dev/null | less -CFRX
  60.  
  61. set +x
  62. echo
  63. echo "For comparison, the new create-react-app output can be found in:"
  64. echo " $NEW_APP_DIR"
  65. echo
Add Comment
Please, Sign In to add comment