Skip to content

Instantly share code, notes, and snippets.

@mjmaix
Last active October 5, 2020 18:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjmaix/4f37e38ce8846ea02b931c9f9103c5f7 to your computer and use it in GitHub Desktop.
Save mjmaix/4f37e38ce8846ea02b931c9f9103c5f7 to your computer and use it in GitHub Desktop.
React Native cleanup scripts
{
"scripts": {
"cleanup:all": "npm run cleanup:android && npm run cleanup:react && npm run cleanup:metrobundler && npm run cleanup:hastecache && npm run cleanup:ios",
"cleanup:react": "./scripts/killpackager.sh && watchman watch-del-all && rm -rf node_modules/ && rm -rf $TMPDIR/react-* ~/.npm/ ~./rncache",
"postcleanup:react": "echo 'run `npm install` or `yarn install`'",
"cleanup:ios": "rm -rf ~/Library/Developer/Xcode/DerivedData/* ios/build ios/Pods",
"cleanup:android": "./scripts/cleanandroid.sh",
"cleanup:metrobundler": "rm -rf /tmp/metro-bundler-cache-*",
"cleanup:hastecache": "rm -rf /tmp/haste-map-react-native-packager-*",
"start": "node node_modules/react-native/local-cli/cli.js start -- --reset-cache",
"postinstall": "./scripts/post.sh && npm run ios:pod:install",
"ios:pod:install": "cd ios && pod install"
}
}
#!/bin/bash
DIRECTORY="node_modules/react-native"
if [ -d "$DIRECTORY" ]; then
echo "Running gradle clean"
cd ./android/
./gradlew clean
echo "Finished cleaning up android"
fi
#!/bin/bash
echo "💣 Killing Packager on port 8081."
lsof -n -i4TCP:8081 | sed '1 d' | awk '{print $2}' | xargs kill -9
# chmod +x scripts/post.sh
#!/bin/bash
echo "Something to do here."
@mjmaix
Copy link
Author

mjmaix commented Apr 20, 2019

All of the commands here can be executed separately. Don't be afraid to clean up your React Native project every once in a while of or when something unexpected happens. Doing a good cleanup first often saves the trouble of filing an issue ticket and waiting for someone else to suggest that you reinstall the app.. etc.

How to use:

  1. Don't forget to close all Metrobundler (or the like) instances first before running.
  2. Close all emulators or simulators
  3. run cleanup:all and take a break

@mjmaix
Copy link
Author

mjmaix commented Apr 21, 2019

  • update to avoid gradlew error when node_modules/react-native is missing

@mjmaix
Copy link
Author

mjmaix commented Apr 22, 2019

  • New android cleanup script

  • npm start kills - existing packager or other tasks using port 8081

@mjmaix
Copy link
Author

mjmaix commented Apr 24, 2019

  • add kill package before cleanup:react

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment