From 3d118fc5ccd191ce05c4e7b038ec652ad4a5e96d Mon Sep 17 00:00:00 2001 From: Artur Martins Barrionuevo Date: Fri, 7 Feb 2025 17:31:18 -0300 Subject: [PATCH] Atualizado variavel ADD_PACKAGE do S2I --- frontend/.s2i/bin/assemble | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/frontend/.s2i/bin/assemble b/frontend/.s2i/bin/assemble index 447c8c9..0965648 100644 --- a/frontend/.s2i/bin/assemble +++ b/frontend/.s2i/bin/assemble @@ -111,26 +111,36 @@ handle_pnpm_workspace() { # Function to handle ADD_PACKAGE # Example Input: -# export ADD_PACKAGE=['"volto-sitedemo": "workspace:*"'] +# export ADD_PACKAGE='[''"volto-sitedemo": "workspace:*"'']' handle_add_package() { - echo "Processing ADD_PACKAGE... Updating dependencies in package.json" - - # TODO: This method is deprecated... Will update in a later date (when moving to "artifacts") - - packages=$(echo "$ADD_PACKAGE" | sed "s|[][']||g") # Remove brackets and quotes - IFS=',' read -ra package_array <<< "$packages" - - # Find the dependencies block and add packages - awk -v packages="${package_array[*]}" ' - BEGIN {split(packages, pkgs, " ")} - /"dependencies": {/ { - print; - for (pkg in pkgs) { - print " " pkgs[pkg] ","; - } - next - } - 1' package.json > package.json.tmp && mv package.json.tmp package.json + echo "Processing ADD_PACKAGE... Updating dependencies in package.json" + + # Remover colchetes e aspas extras da variável ADD_PACKAGE + cleaned_packages=$(echo "$ADD_PACKAGE" | sed -E "s/^\[|\]$//g" | sed -E "s/'//g") + + # Criar uma string corretamente formatada para JSON + package_entries="" + IFS=',' read -ra package_array <<< "$cleaned_packages" + for pkg in "${package_array[@]}"; do + formatted_pkg=$(echo "$pkg" | sed -E 's/""/"/g' | sed -E 's/^"([^"]+)": "([^"]+)"$/ "\1": "\2"/') + package_entries+="$formatted_pkg,\n" + done + package_entries=${package_entries%,\\n} # Remove a última vírgula e nova linha extra + + # Modificar o JSON preservando sua estrutura + awk -v new_entries="$package_entries" ' + BEGIN { inside_deps=0 } + /"dependencies": {/ { + inside_deps=1; + print; + next; + } + inside_deps && /^[ ]*}/ { + printf ",\n%s\n", new_entries; # Adiciona os pacotes com uma vírgula antes + inside_deps=0; + } + { print } + ' package.json > package.json.tmp && mv package.json.tmp package.json } # Function to handle ADD_MRSDEVELOPER