Skip to content

Commit

Permalink
Novo processo de carga melhorado do ADD_PACKAGE do S2I
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-barrionuevo committed Feb 7, 2025
1 parent 3d118fc commit 21ba205
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions frontend/.s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,32 @@ handle_pnpm_workspace() {
done
}


# Function to handle ADD_PACKAGE
# Example Input:
# export ADD_PACKAGE='[''"volto-sitedemo": "workspace:*"'']'
# export ADD_PACKAGE='{"addon1": "*", "addon2": "*"}'
handle_add_package() {
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;
# Extract key-value pairs from JSON using sed
key_value_pairs=$(echo "$ADD_PACKAGE" | sed -E 's/[{}"]//g' | sed 's/,/ /g')

# Convert key-value pairs into the expected format for awk
formatted_packages=$(echo "$key_value_pairs" | awk '{for (i=1; i<=NF; i+=2) printf "\"%s\": \"%s\", ", $i, $(i+1)}' | sed 's/, $//')

# Use awk to insert dependencies into package.json
awk -v packages="$formatted_packages" '
/"dependencies": {/ {
print;
split(packages, pkgs, ", ");
for (i in pkgs) {
print " " pkgs[i] ",";
}
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
1' package.json > package.json.tmp && mv package.json.tmp package.json

cat package.json
}

# Function to handle ADD_MRSDEVELOPER
Expand Down

0 comments on commit 21ba205

Please sign in to comment.