Last active
March 11, 2016 13:46
-
-
Save TiddoLangerak/3f8a5c923e14794fbfff to your computer and use it in GitHub Desktop.
FA3->FA4 migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob from 'glob'; | |
import fs from 'fs'; | |
import path from 'path'; | |
//We don't want ng-class, so we need to make sure to have the \s stuff | |
const CLASS_REGEXP = /\sclass="(.*?)"/g; | |
const ICON_PREFIX_REGEXP = /^icon-/; | |
const replacements = { | |
"ban-circle": "ban", | |
"bar-chart": "bar-chart-o", | |
"beaker": "flask", | |
"bell": "bell-o", | |
"bell-alt": "bell", | |
"bitbucket-sign": "bitbucket-square", | |
"bookmark-empty": "bookmark-o", | |
"building": "building-o", | |
"calendar-empty": "calendar-o", | |
"check-empty": "square-o", | |
"check-minus": "minus-square-o", | |
"check-sign": "check-square", | |
"check": "check-square-o", | |
"chevron-sign-down": "chevron-down", | |
"chevron-sign-left": "chevron-left", | |
"chevron-sign-right": "chevron-right", | |
"chevron-sign-up": "chevron-up", | |
"circle-arrow-down": "arrow-circle-down", | |
"circle-arrow-left": "arrow-circle-left", | |
"circle-arrow-right": "arrow-circle-right", | |
"circle-arrow-up": "arrow-circle-up", | |
"circle-blank": "circle-o", | |
"cny": "rmb", | |
"collapse-alt": "minus-square-o", | |
"collapse-top": "caret-square-o-up", | |
"collapse": "caret-square-o-down", | |
"comment-alt": "comment-o", | |
"comments-alt": "comments-o", | |
"copy": "files-o", | |
"cut": "scissors", | |
"dashboard": "tachometer", | |
"double-angle-down": "angle-double-down", | |
"double-angle-left": "angle-double-left", | |
"double-angle-right": "angle-double-right", | |
"double-angle-up": "angle-double-up", | |
"download": "arrow-circle-o-down", | |
"download-alt": "download", | |
"edit-sign": "pencil-square", | |
"edit": "pencil-square-o", | |
"ellipsis-horizontal": "ellipsis-h", | |
"ellipsis-vertical": "ellipsis-v", | |
"envelope-alt": "envelope-o", | |
"exclamation-sign": "exclamation-circle", | |
"expand-alt": "plus-square-o", | |
"expand": "caret-square-o-right", | |
"external-link-sign": "external-link-square", | |
"eye-close": "eye-slash", | |
"eye-open": "eye", | |
"facebook-sign": "facebook-square", | |
"facetime-video": "video-camera", | |
"file-alt": "file-o", | |
"file-text-alt": "file-text-o", | |
"flag-alt": "flag-o", | |
"folder-close-alt": "folder-o", | |
"folder-close": "folder", | |
"folder-open-alt": "folder-open-o", | |
"food": "cutlery", | |
"frown": "frown-o", | |
"fullscreen": "arrows-alt", | |
"github-sign": "github-square", | |
"google-plus-sign": "google-plus-square", | |
"group": "users", | |
"h-sign": "h-square", | |
"hand-down": "hand-o-down", | |
"hand-left": "hand-o-left", | |
"hand-right": "hand-o-right", | |
"hand-up": "hand-o-up", | |
"hdd": "hdd-o", | |
"heart-empty": "heart-o", | |
"hospital": "hospital-o", | |
"indent-left": "outdent", | |
"indent-right": "indent", | |
"info-sign": "info-circle", | |
"keyboard": "keyboard-o", | |
"legal": "gavel", | |
"lemon": "lemon-o", | |
"lightbulb": "lightbulb-o", | |
"linkedin-sign": "linkedin-square", | |
"meh": "meh-o", | |
"microphone-off": "microphone-slash", | |
"minus-sign-alt": "minus-square", | |
"minus-sign": "minus-circle", | |
"mobile-phone": "mobile", | |
"moon": "moon-o", | |
"move": "arrows", | |
"off": "power-off", | |
"ok-circle": "check-circle-o", | |
"ok-sign": "check-circle", | |
"ok": "check", | |
"paper-clip": "paperclip", | |
"paste": "clipboard", | |
"phone-sign": "phone-square", | |
"picture": "picture-o", | |
"pinterest-sign": "pinterest-square", | |
"play-circle": "play-circle-o", | |
"play-sign": "play-circle", | |
"plus-sign-alt": "plus-square", | |
"plus-sign": "plus-circle", | |
"pushpin": "thumb-tack", | |
"question-sign": "question-circle", | |
"remove-circle": "times-circle-o", | |
"remove-sign": "times-circle", | |
"remove": "times", | |
"reorder": "bars", | |
"resize-full": "expand", | |
"resize-horizontal": "arrows-h", | |
"resize-small": "compress", | |
"resize-vertical": "arrows-v", | |
"rss-sign": "rss-square", | |
"save": "floppy-o", | |
"screenshot": "crosshairs", | |
"share-alt": "share", | |
"share-sign": "share-square", | |
"share": "share-square-o", | |
"sign-blank": "square", | |
"signin": "sign-in", | |
"signout": "sign-out", | |
"smile": "smile-o", | |
"sort-by-alphabet-alt": "sort-alpha-desc", | |
"sort-by-alphabet": "sort-alpha-asc", | |
"sort-by-attributes-alt": "sort-amount-desc", | |
"sort-by-attributes": "sort-amount-asc", | |
"sort-by-order-alt": "sort-numeric-desc", | |
"sort-by-order": "sort-numeric-asc", | |
"sort-down": "sort-desc", | |
"sort-up": "sort-asc", | |
"stackexchange": "stack-overflow", | |
"star-empty": "star-o", | |
"star-half-empty": "star-half-o", | |
"sun": "sun-o", | |
"thumbs-down-alt": "thumbs-o-down", | |
"thumbs-up-alt": "thumbs-o-up", | |
"time": "clock-o", | |
"trash": "trash-o", | |
"tumblr-sign": "tumblr-square", | |
"twitter-sign": "twitter-square", | |
"unlink": "chain-broken", | |
"upload": "arrow-circle-o-up", | |
"upload-alt": "upload", | |
"warning-sign": "exclamation-triangle", | |
"xing-sign": "xing-square", | |
"youtube-sign": "youtube-square", | |
"zoom-in": "search-plus", | |
"zoom-out": "search-minus", | |
}; | |
glob("**/*.tpl", (er, files) => { | |
if (er) { | |
console.error('could not glob'); | |
console.error(er); | |
process.exit(-1); | |
} | |
files.forEach(file => { | |
const fullPath = path.join(__dirname, file); | |
fs.readFile(fullPath, 'utf8', (err, file) => { | |
if (err) { | |
console.error('could not read file'); | |
console.error(err); | |
process.exit(-1); | |
} | |
const newFile = file.replace(CLASS_REGEXP, (match, classes) => { | |
const classList = classes.split(/\s+/); | |
let hasIcons = false; | |
if (classList.find(className => className.startsWith('icon-'))) { | |
hasIcons = true; | |
} | |
const newClasses = classList | |
.filter(className => className !== 'icon') | |
.map(className => { | |
if (className.startsWith('icon-')) { | |
const replacement = replacements[className.replace(ICON_PREFIX_REGEXP, '')]; | |
if (replacement) { | |
return `fa-${replacement}`; | |
} | |
}; | |
return className; | |
}) | |
.map(className => className.replace(ICON_PREFIX_REGEXP, 'fa-')); | |
if (hasIcons) { | |
newClasses.unshift('fa'); | |
} | |
return ` class="${newClasses.join(' ')}"`; | |
}); | |
if (file !== newFile) { | |
fs.writeFile(fullPath, newFile, (err) => { | |
if (err) { | |
console.error('could not write file'); | |
console.error(err); | |
process.exit(-1); | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment