From 8df7cf80a81d729581df5fe20ae1e7fa4c1b3801 Mon Sep 17 00:00:00 2001 From: "Deavon M. McCaffery" Date: Tue, 7 May 2019 10:57:12 -0700 Subject: [PATCH] feat: make update-sln diff aware * calculate the diff between current directory structure and sln representation - remove items from the sln that no longer exist on disk - add items to the sln that exist on disk and do not appear in the sln --- src/scripts/update-sln | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/scripts/update-sln b/src/scripts/update-sln index aefcc5e..cd7d779 100755 --- a/src/scripts/update-sln +++ b/src/scripts/update-sln @@ -1,5 +1,17 @@ #!/usr/bin/env bash -rm -rf *.sln 1>/dev/null -dotnet new sln -find . -name *.csproj | xargs dotnet sln add +__contains() { for item in "${@:2}"; do [[ "$item" == "$1" ]] && return 0; done; return 1; } + +for SLN in *.sln; do + EXISTING=($(dotnet sln "$SLN" list)) + EXISTING=("${EXISTING[@]:2}") + DISCOVERED=($(find * -name '*.csproj' ! -path '*/bin/*' ! -path '*/obj/*' ! -path '*/shared/*' )) + + for existing in "${EXISTING[@]}"; do + __contains $existing "${DISCOVERED[@]}" || dotnet sln "$SLN" remove "$existing" + done + + for discovered in "${DISCOVERED[@]}"; do + __contains $discovered "${EXISTING[@]}" || dotnet sln "$SLN" add "$discovered" + done +done