Skip to content

Instantly share code, notes, and snippets.

@cloakedninjas
Created June 1, 2020 10:23
Show Gist options
  • Save cloakedninjas/9e4e029c92a141c547dabdabe9ccbb1d to your computer and use it in GitHub Desktop.
Save cloakedninjas/9e4e029c92a141c547dabdabe9ccbb1d to your computer and use it in GitHub Desktop.
Node script to perform find/replace of Font Awesome icon from v4 to v5
const fs = require('fs');
const path = require('path');
// Sourced from https://fontawesome.com/how-to-use/on-the-web/setup/upgrading-from-version-4#name-changes
const changes = fs.readFileSync('icon-changes.csv', 'utf8');
const icons = changes.split('\r\n');
const OLD_PREFIX = 'fa fa-';
const ROOT_FOLDER = 'src';
const DRY_RUN = true;
function traverseDirs(dir) {
fs.readdir(dir, { withFileTypes: true }, (err, files) => {
if (err) {
throw err;
}
files.forEach(file => {
const pathToFile = path.join(dir, file.name);
if (file.isDirectory()) {
traverseDirs(pathToFile);
return;
}
fs.readFile(pathToFile, 'utf8', (err, fileContents) => {
if (err) {
throw err;
}
icons.forEach(iconUpgrade => {
const [fromName, toName, newPkg] = iconUpgrade.split(',');
const find = new RegExp(OLD_PREFIX + fromName, 'g');
const replace = newPkg + ' fa-' + toName;
if (fileContents.match(find)) {
console.log('Found', OLD_PREFIX + fromName, 'in', pathToFile);
console.log('Replace with', replace);
console.log('--------');
if (!DRY_RUN) {
fs.writeFileSync(pathToFile, fileContents.replace(find, replace));
}
}
});
});
});
});
}
traverseDirs(ROOT_FOLDER);
500px 500px fab
address-book-o address-book far
address-card-o address-card far
adn adn fab
amazon amazon fab
android android fab
angellist angellist fab
apple apple fab
area-chart chart-area fas
arrow-circle-o-down arrow-alt-circle-down far
arrow-circle-o-left arrow-alt-circle-left far
arrow-circle-o-right arrow-alt-circle-right far
arrow-circle-o-up arrow-alt-circle-up far
arrows arrows-alt fas
arrows-alt expand-arrows-alt fas
arrows-h arrows-alt-h fas
arrows-v arrows-alt-v fas
asl-interpreting american-sign-language-interpreting fas
automobile car fas
bandcamp bandcamp fab
bank university fas
bar-chart chart-bar far
bar-chart-o chart-bar far
bathtub bath fas
battery battery-full fas
battery-0 battery-empty fas
battery-1 battery-quarter fas
battery-2 battery-half fas
battery-3 battery-three-quarters fas
battery-4 battery-full fas
behance behance fab
behance-square behance-square fab
bell-o bell far
bell-slash-o bell-slash far
bitbucket bitbucket fab
bitbucket-square bitbucket fab
bitcoin btc fab
black-tie black-tie fab
bluetooth bluetooth fab
bluetooth-b bluetooth-b fab
bookmark-o bookmark far
btc btc fab
building-o building far
buysellads buysellads fab
cab taxi fas
calendar calendar-alt fas
calendar-check-o calendar-check far
calendar-minus-o calendar-minus far
calendar-o calendar far
calendar-plus-o calendar-plus far
calendar-times-o calendar-times far
caret-square-o-down caret-square-down far
caret-square-o-left caret-square-left far
caret-square-o-right caret-square-right far
caret-square-o-up caret-square-up far
cc closed-captioning far
cc-amex cc-amex fab
cc-diners-club cc-diners-club fab
cc-discover cc-discover fab
cc-jcb cc-jcb fab
cc-mastercard cc-mastercard fab
cc-paypal cc-paypal fab
cc-stripe cc-stripe fab
cc-visa cc-visa fab
chain link fas
chain-broken unlink fas
check-circle-o check-circle far
check-square-o check-square far
chrome chrome fab
circle-o circle far
circle-o-notch circle-notch fas
circle-thin circle far
clipboard clipboard far
clock-o clock far
clone clone far
close times fas
cloud-download cloud-download-alt fas
cloud-upload cloud-upload-alt fas
cny yen-sign fas
code-fork code-branch fas
codepen codepen fab
codiepie codiepie fab
comment-o comment far
commenting comment-dots fas
commenting-o comment-dots far
comments-o comments far
compass compass far
connectdevelop connectdevelop fab
contao contao fab
copyright copyright far
creative-commons creative-commons fab
credit-card credit-card far
credit-card-alt credit-card fas
css3 css3 fab
cutlery utensils fas
dashboard tachometer-alt fas
dashcube dashcube fab
deafness deaf fas
dedent outdent fas
delicious delicious fab
deviantart deviantart fab
diamond gem far
digg digg fab
dollar dollar-sign fas
dot-circle-o dot-circle far
dribbble dribbble fab
drivers-license id-card fas
drivers-license-o id-card far
dropbox dropbox fab
drupal drupal fab
edge edge fab
eercast sellcast fab
empire empire fab
envelope-o envelope far
envelope-open-o envelope-open far
envira envira fab
etsy etsy fab
eur euro-sign fas
euro euro-sign fas
exchange exchange-alt fas
expeditedssl expeditedssl fab
external-link external-link-alt fas
external-link-square external-link-square-alt fas
eye eye far
eye-slash eye-slash far
eyedropper eye-dropper fas
fa font-awesome fab
facebook facebook-f fab
facebook-f facebook-f fab
facebook-official facebook fab
facebook-square facebook-square fab
feed rss fas
file-archive-o file-archive far
file-audio-o file-audio far
file-code-o file-code far
file-excel-o file-excel far
file-image-o file-image far
file-movie-o file-video far
file-o file far
file-pdf-o file-pdf far
file-photo-o file-image far
file-picture-o file-image far
file-powerpoint-o file-powerpoint far
file-sound-o file-audio far
file-text file-alt fas
file-text-o file-alt far
file-video-o file-video far
file-word-o file-word far
file-zip-o file-archive far
files-o copy far
firefox firefox fab
first-order first-order fab
flag-o flag far
flash bolt fas
flickr flickr fab
floppy-o save far
folder-o folder far
folder-open-o folder-open far
font-awesome font-awesome fab
fonticons fonticons fab
fort-awesome fort-awesome fab
forumbee forumbee fab
foursquare foursquare fab
free-code-camp free-code-camp fab
frown-o frown far
futbol-o futbol far
gbp pound-sign fas
ge empire fab
gear cog fas
gears cogs fas
get-pocket get-pocket fab
gg gg fab
gg-circle gg-circle fab
git git fab
git-square git-square fab
github github fab
github-alt github-alt fab
github-square github-square fab
gitlab gitlab fab
gittip gratipay fab
glass glass-martini fas
glide glide fab
glide-g glide-g fab
google google fab
google-plus google-plus-g fab
google-plus-circle google-plus fab
google-plus-official google-plus fab
google-plus-square google-plus-square fab
google-wallet google-wallet fab
gratipay gratipay fab
grav grav fab
group users fas
hacker-news hacker-news fab
hand-grab-o hand-rock far
hand-lizard-o hand-lizard far
hand-o-down hand-point-down far
hand-o-left hand-point-left far
hand-o-right hand-point-right far
hand-o-up hand-point-up far
hand-paper-o hand-paper far
hand-peace-o hand-peace far
hand-pointer-o hand-pointer far
hand-rock-o hand-rock far
hand-scissors-o hand-scissors far
hand-spock-o hand-spock far
hand-stop-o hand-paper far
handshake-o handshake far
hard-of-hearing deaf fas
hdd-o hdd far
header heading fas
heart-o heart far
hospital-o hospital far
hotel bed fas
hourglass-1 hourglass-start fas
hourglass-2 hourglass-half fas
hourglass-3 hourglass-end fas
hourglass-o hourglass far
houzz houzz fab
html5 html5 fab
id-badge id-badge far
id-card-o id-card far
ils shekel-sign fas
image image far
imdb imdb fab
inr rupee-sign fas
instagram instagram fab
institution university fas
internet-explorer internet-explorer fab
intersex transgender fas
ioxhost ioxhost fab
joomla joomla fab
jpy yen-sign fas
jsfiddle jsfiddle fab
keyboard-o keyboard far
krw won-sign fas
lastfm lastfm fab
lastfm-square lastfm-square fab
leanpub leanpub fab
legal gavel fas
lemon-o lemon far
level-down level-down-alt fas
level-up level-up-alt fas
life-bouy life-ring far
life-buoy life-ring far
life-ring life-ring far
life-saver life-ring far
lightbulb-o lightbulb far
line-chart chart-line fas
linkedin linkedin-in fab
linkedin-square linkedin fab
linode linode fab
linux linux fab
list-alt list-alt far
long-arrow-down long-arrow-alt-down fas
long-arrow-left long-arrow-alt-left fas
long-arrow-right long-arrow-alt-right fas
long-arrow-up long-arrow-alt-up fas
mail-forward share fas
mail-reply reply fas
mail-reply-all reply-all fas
map-marker map-marker-alt fas
map-o map far
maxcdn maxcdn fab
meanpath font-awesome fab
medium medium fab
meetup meetup fab
meh-o meh far
minus-square-o minus-square far
mixcloud mixcloud fab
mobile mobile-alt fas
mobile-phone mobile-alt fas
modx modx fab
money money-bill-alt far
moon-o moon far
mortar-board graduation-cap fas
navicon bars fas
newspaper-o newspaper far
object-group object-group far
object-ungroup object-ungroup far
odnoklassniki odnoklassniki fab
odnoklassniki-square odnoklassniki-square fab
opencart opencart fab
openid openid fab
opera opera fab
optin-monster optin-monster fab
pagelines pagelines fab
paper-plane-o paper-plane far
paste clipboard far
pause-circle-o pause-circle far
paypal paypal fab
pencil pencil-alt fas
pencil-square pen-square fas
pencil-square-o edit far
photo image far
picture-o image far
pie-chart chart-pie fas
pied-piper pied-piper fab
pied-piper-alt pied-piper-alt fab
pied-piper-pp pied-piper-pp fab
pinterest pinterest fab
pinterest-p pinterest-p fab
pinterest-square pinterest-square fab
play-circle-o play-circle far
plus-square-o plus-square far
product-hunt product-hunt fab
qq qq fab
question-circle-o question-circle far
quora quora fab
ra rebel fab
ravelry ravelry fab
rebel rebel fab
reddit reddit fab
reddit-alien reddit-alien fab
reddit-square reddit-square fab
refresh sync fas
registered registered far
remove times fas
renren renren fab
reorder bars fas
repeat redo fas
resistance rebel fab
rmb yen-sign fas
rotate-left undo fas
rotate-right redo fas
rouble ruble-sign fas
rub ruble-sign fas
ruble ruble-sign fas
rupee rupee-sign fas
s15 bath fas
safari safari fab
scissors cut fas
scribd scribd fab
sellsy sellsy fab
send paper-plane fas
send-o paper-plane far
share-square-o share-square far
shekel shekel-sign fas
sheqel shekel-sign fas
shield shield-alt fas
shirtsinbulk shirtsinbulk fab
sign-in sign-in-alt fas
sign-out sign-out-alt fas
signing sign-language fas
simplybuilt simplybuilt fab
skyatlas skyatlas fab
skype skype fab
slack slack fab
sliders sliders-h fas
slideshare slideshare fab
smile-o smile far
snapchat snapchat fab
snapchat-ghost snapchat-ghost fab
snapchat-square snapchat-square fab
snowflake-o snowflake far
soccer-ball-o futbol far
sort-alpha-asc sort-alpha-down fas
sort-alpha-desc sort-alpha-up fas
sort-amount-asc sort-amount-down fas
sort-amount-desc sort-amount-up fas
sort-asc sort-up fas
sort-desc sort-down fas
sort-numeric-asc sort-numeric-down fas
sort-numeric-desc sort-numeric-up fas
soundcloud soundcloud fab
spoon utensil-spoon fas
spotify spotify fab
square-o square far
stack-exchange stack-exchange fab
stack-overflow stack-overflow fab
star-half-empty star-half far
star-half-full star-half far
star-half-o star-half far
star-o star far
steam steam fab
steam-square steam-square fab
sticky-note-o sticky-note far
stop-circle-o stop-circle far
stumbleupon stumbleupon fab
stumbleupon-circle stumbleupon-circle fab
sun-o sun far
superpowers superpowers fab
support life-ring far
tablet tablet-alt fas
tachometer tachometer-alt fas
telegram telegram fab
television tv fas
tencent-weibo tencent-weibo fab
themeisle themeisle fab
thermometer thermometer-full fas
thermometer-0 thermometer-empty fas
thermometer-1 thermometer-quarter fas
thermometer-2 thermometer-half fas
thermometer-3 thermometer-three-quarters fas
thermometer-4 thermometer-full fas
thumb-tack thumbtack fas
thumbs-o-down thumbs-down far
thumbs-o-up thumbs-up far
ticket ticket-alt fas
times-circle-o times-circle far
times-rectangle window-close fas
times-rectangle-o window-close far
toggle-down caret-square-down far
toggle-left caret-square-left far
toggle-right caret-square-right far
toggle-up caret-square-up far
trash trash-alt fas
trash-o trash-alt far
trello trello fab
tripadvisor tripadvisor fab
try lira-sign fas
tumblr tumblr fab
tumblr-square tumblr-square fab
turkish-lira lira-sign fas
twitch twitch fab
twitter twitter fab
twitter-square twitter-square fab
unsorted sort fas
usb usb fab
usd dollar-sign fas
user-circle-o user-circle far
user-o user far
vcard address-card fas
vcard-o address-card far
viacoin viacoin fab
viadeo viadeo fab
viadeo-square viadeo-square fab
video-camera video fas
vimeo vimeo-v fab
vimeo-square vimeo-square fab
vine vine fab
vk vk fab
volume-control-phone phone-volume fas
warning exclamation-triangle fas
wechat weixin fab
weibo weibo fab
weixin weixin fab
whatsapp whatsapp fab
wheelchair-alt accessible-icon fab
wikipedia-w wikipedia-w fab
window-close-o window-close far
window-maximize window-maximize far
window-restore window-restore far
windows windows fab
won won-sign fas
wordpress wordpress fab
wpbeginner wpbeginner fab
wpexplorer wpexplorer fab
wpforms wpforms fab
xing xing fab
xing-square xing-square fab
y-combinator y-combinator fab
y-combinator-square hacker-news fab
yahoo yahoo fab
yc y-combinator fab
yc-square hacker-news fab
yelp yelp fab
yen yen-sign fas
yoast yoast fab
youtube youtube fab
youtube-play youtube fab
youtube-square youtube-square fab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment