-
-
Save rhalff/aeee444874c7a140bf410d55cd6edc2d to your computer and use it in GitHub Desktop.
Bash script to migrate multiple projects into one Lerna monorepo (https://lernajs.io)
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
| #!/usr/bin/env bash | |
| set -x | |
| shopt -s extglob dotglob | |
| TEMP_DIR=tmp | |
| USERNAME=psichi | |
| REPOS=(chix) | |
| function clone_repo () { | |
| git clone git@github.com:$USERNAME/$1.git | |
| cd "$1" | |
| mkdir -p "packages/$1" | |
| git mv !(packages|.git|..|.) packages | |
| cd packages | |
| git mv !("$1") "$1" | |
| cd "$HOME/$TEMP_DIR/$1" | |
| git add . -A | |
| git commit -m "Move source to packages/$1" -n | |
| cd "$HOME/$TEMP_DIR" | |
| } | |
| rm -rf "$HOME/$TEMP_DIR" | |
| mkdir "$HOME/$TEMP_DIR" | |
| cd "$HOME/$TEMP_DIR" | |
| git init | |
| for repo in "${REPOS[@]}" | |
| do | |
| clone_repo $repo | |
| done | |
| mkdir lerna-monorepo | |
| cd lerna-monorepo | |
| git init | |
| for repo in "${REPOS[@]}" | |
| do | |
| git pull $HOME/$TEMP_DIR/$repo master --allow-unrelated-histories -s resolve | |
| done | |
| set +x | |
| shopt -u extglob dotglob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment