Skip to content

Instantly share code, notes, and snippets.

@nykula
Created February 22, 2018 20:08
Show Gist options
  • Save nykula/223b18c1b22a9da5e2cefd3fd7d08c26 to your computer and use it in GitHub Desktop.
Save nykula/223b18c1b22a9da5e2cefd3fd7d08c26 to your computer and use it in GitHub Desktop.
Translate Angular 1 to React JSX. You still do a lot, but helps
#!/bin/bash
perl -i -pe 's/{{ ?/{/g' "$@"
perl -i -pe 's/ ?}}/}/g' "$@"
perl -i -pe 's/\$?(ctrl|self)/this/g' "$@"
perl -i -pe 's/= function//g' "$@"
perl -i -pe 's/\$onInit\s+\(\) {/constructor(props) {\nsuper(props)\n/g' "$@"
perl -i -pe 's/\$postLink\s+\(\) {/componentDidMount() {/g' "$@"
perl -i -pe 's/\.(\$|api|dialog|env|glue|store)/.props.\1/g' "$@"
perl -i -pe 's/<br>/<br \/>/g' "$@"
perl -i -0pe "s/\{'([^']*)'\s*\|\s*translate\}/{translate(\\1)}/g" "$@"
perl -i -0pe "s/translate='([^']*)'>/>{translate(\1)}/g" "$@"
perl -i -0pe "s/translate='([^']*)'\s*translate-values='([^']*)'>/>{translate(\1, \2)}/g" "$@"
perl -i -pe "s/ng-click='([a-zA-Z\.]*)\(.event\)'/onClick={\1}/g" "$@"
perl -i -pe "s/ng-submit='([a-zA-Z\.]*)\(.event\)'/onSubmit={\1}/g" "$@"
perl -i -pe "s/ng-bind='([^']*)'>/>{\1}/g" "$@"
perl -i -pe "s/ng-src='([^']*)'/src=\1/g" "$@"
perl -i -pe "s/(\.props)+/.props/g" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment