Skip to content

Instantly share code, notes, and snippets.

@brookslybrand
Last active October 16, 2023 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brookslybrand/53ecbcbad0fb7735aa763106536d4ed2 to your computer and use it in GitHub Desktop.
Save brookslybrand/53ecbcbad0fb7735aa763106536d4ed2 to your computer and use it in GitHub Desktop.
Remix v1 to v2 route upgrade (by directory)

This was heavily inspired (and in fact uses) Remix Migration Scripts

This script calls the above mentioned script, but also allows you to pass in an argument for the specific directory you want to migrate

./migrate-to-v2-routing.bash ./docs

Note: This script by no means is "complete". I haven't tested it against every possible case. It is meant to be mostly demonstrative in how you can setup a simple script to help you with your v1 to v2 route migration journey.

If you see any problems and want to suggest an update, feel free to let me know 🙂

#!/usr/bin/env bash
# Big thanks goes to Sébastien Morel (https://twitter.com/plopix) and ChatGPT
ROUTE_DIR=$1
TEMP_DIR=./temp
# prepare the original routes json and the temp directory
npx remix routes --json > original.json
rm -rf $TEMP_DIR
# run this awesome script by Plopix: https://gist.github.com/Plopix/58fc3f3be202d9915c466e71077d36a2
curl -fsSL https://gist.github.com/Plopix/58fc3f3be202d9915c466e71077d36a2/raw/migrate-to-v2-routing.bash | bash -s ./app/routes $TEMP_DIR
# copy files
rm -rf "./app/routes/$ROUTE_DIR"*
# update if the route starts with __ to _
if [[ $ROUTE_DIR == __* ]]; then
ROUTE_DIR="_${ROUTE_DIR#__}"
echo "Modified string: $ROUTE_DIR"
fi
mv "$TEMP_DIR/$ROUTE_DIR"* ./app/routes
# remove the temp directory
rm -rf $TEMP_DIR
# update the routes and diff
npx remix routes --json > new.json
routes_diff=$(diff original.json new.json)
if [ -z "$routes_diff" ]; then
echo -e "\n\nThe update did not effect your routes, congratulations!\n"
exit 0
else
echo -e "\nThe following changes will be made to your routes:\n"
diff --color original.json new.json
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment