Skip to content

Instantly share code, notes, and snippets.

@stoffeastrom
Forked from JamieMason/migrate-to-lerna.sh
Created April 30, 2018 16:30
Show Gist options
  • Save stoffeastrom/b6855c81966a0f48cb67657c47b7c01c to your computer and use it in GitHub Desktop.
Save stoffeastrom/b6855c81966a0f48cb67657c47b7c01c to your computer and use it in GitHub Desktop.
Bash script to migrate multiple projects into one Lerna monorepo (https://lernajs.io)
#!/usr/bin/env bash
set -x
shopt -s extglob dotglob
cd "$HOME"
rm -rf "$HOME/TEMP_DIR"
mkdir "$HOME/TEMP_DIR"
cd "$HOME/TEMP_DIR"
git init
function clone_repo () {
git clone "https://github.com/some-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"
}
clone_repo "some-package-1"
clone_repo "some-package-2"
clone_repo "some-package-3"
cd "$HOME/TEMP_DIR"
mkdir lerna-monorepo
cd lerna-monorepo
git init
git pull $HOME/TEMP_DIR/some-package-1 master --allow-unrelated-histories -s resolve
git pull $HOME/TEMP_DIR/some-package-2 master --allow-unrelated-histories -s resolve
git pull $HOME/TEMP_DIR/some-package-3 master --allow-unrelated-histories -s resolve
set +x
shopt -u extglob dotglob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment