Skip to content

Instantly share code, notes, and snippets.

@Juan-escobar94
Last active November 8, 2023 19:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Juan-escobar94/f76535a1264ac6f7251c643af50c184d to your computer and use it in GitHub Desktop.
Save Juan-escobar94/f76535a1264ac6f7251c643af50c184d to your computer and use it in GitHub Desktop.
Migrate bootstrap 4 classes to bootstrap 5.
set -x
set -e
# e.g. folder to process e.g. "frontend/"
migration_folder=$1
find_regex=".*/*.tsx?" # mach all .ts and .tsx files
# include trailing path "/" in folder parameter: e.g "frontend/" instead of just "frontend"
ignore_path="*/$1node_modules/*"
# Back up your files or change sed argument -i to -i.bak to generate backup files
find $migration_folder -regextype posix-egrep -regex $find_regex -type f -not -path $ignore_path | xargs sed -i -E '/[(class)(")]/{
s/([mp])l(-[0-5])/\1s\2/g
s/([mp])r(-[0-5])/\1e\2/g
s/no-gutters/g-0/g
s/ close / btn-close /g
s/arrow/popover-arrow/g
s/left(-[0-9]*)/start\1/g
s/right(-[0-9]*)/end\1/g
s/(float|border|rounded|text)-left/\1-start/g
s/(float|border|rounded|text)-right/\1-end/g
s/font-weight(-[a-zA-Z]*)/fw\1/g
s/font-style(-[a-zA-Z]*)/fst\1/g
}'
@tellts
Copy link

tellts commented Oct 6, 2022

Hello. Please tell me how to use this converter correctly and for which operating system it is intended?

@Juan-escobar94
Copy link
Author

Juan-escobar94 commented Oct 6, 2022

Hello. Please tell me how to use this converter correctly and for which operating system it is intended?

Hey! its intended to be used on a gnu/linux machine, I used ubuntu 20.04 iirc. I would guess there are better migration tools out there now tbh! And I do not know if b5 has made any other big changes that would make this script obsolete... I would advise you to rather find something else ;)

Anyways,
the script takes a directory as its only argument, for example: ./migrate-b4-to-b5.sh my-folder/

@dchevilletRDR
Copy link

Hello,

Thank you for this script. I just used it and maybe one suggestion for the next visitor. The pattern 'arrow' break the font awesome icon "fa-arrow". And in fact, the line 14 and 15 are the same, so it gives you "popover-popover-arrow" :-)

@Juan-escobar94
Copy link
Author

Hello,

Thank you for this script. I just used it and maybe one suggestion for the next visitor. The pattern 'arrow' break the font awesome icon "fa-arrow". And in fact, the line 14 and 15 are the same, so it gives you "popover-popover-arrow" :-)

Thanks! just updated it

@tellts
Copy link

tellts commented Jul 31, 2023

Thanks!

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