Created
May 6, 2016 00:14
-
-
Save jashmenn/adf865afb9d51676e6ab7ea38da945b2 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash -x | |
# | |
# Angular 2.0.0-rc.1 renamed a bunch of modules. This script can help you do a | |
# little bit of the dirty work for renaming those modules. | |
# | |
# As a bonus, this script will try to fix your template-local variables | |
# e.g. *ngFor="#thread of threads" becomes -> *ngFor="let thread of threads" | |
# | |
# 🦁 by Nate Murray nate@fullstack.io // https://ng-book.com/2 | |
# | |
function rename_angular_imports() { | |
FOLDER=$1 | |
for f in `find ${FOLDER} | grep -E '.(ts|js|md)$'`; do | |
echo $f | |
perl -pi -e 's#angular2/core#\@angular/core#g' $f | |
perl -pi -e 's#angular2/compiler#\@angular/compiler#g' $f | |
perl -pi -e 's#angular2/common#\@angular/common#g' $f | |
perl -pi -e 's#angular2/platform/browser#\@angular/platform-browser-dynamic#g' $f | |
perl -pi -e 's#angular2/platform/server#\@angular/platform-server#g' $f | |
perl -pi -e 's#angular2/testing#\@angular/core/testing#g' $f | |
perl -pi -e 's#angular2/upgrade#\@angular/upgrade#g' $f | |
perl -pi -e 's#angular2/http#\@angular/http#g' $f | |
perl -pi -e 's#angular2/router#\@angular/router-deprecated#g' $f | |
perl -pi -e 's#angular2/platform/testing/browser#\@angular/platform-browser-dynamic/testing#g' $f | |
done | |
} | |
function fix_ngfor_vars() { | |
FOLDER=$1 | |
for f in `find ${FOLDER} | grep -E '.(ts|js|md)$'`; do | |
# *ngFor="#thread of threads" becomes -> *ngFor="let thread of threads" | |
# \x27 and \x22 are unicode for single and double quote | |
perl -pi -e 's/\*(\w+)=([\x27\x22])#/*\1=\2let /g' $f | |
done | |
} | |
# assuming you have .ts or .js you want to update in app or test dir: | |
rename_angular_imports "app test" | |
fix_ngfor_vars "app test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment