Skip to content

Commit 2982157

Browse files
author
Thomas G.
committed
chore: 🔧 add comments
1 parent 15b3d5e commit 2982157

6 files changed

Lines changed: 43 additions & 27 deletions

File tree

src/common-utils/_configure-feature.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ export source=${source:-/usr/local/share/$feature}
2222
# Get the indent size from devcontainer.json with jq, default to 2 if not found
2323
export tabSize=4
2424

25-
echo "Configuring feature <${Purple}$feature${None}>${End}"
26-
echo "from <$source>${End}"
25+
zz_log i "Configure feature <{Purple $feature}>"
26+
zz_log - "From {U $source}"
2727

2828
# Go to the module root
2929
cd "$(git rev-parse --show-toplevel)" >/dev/null
3030

31+
# Ensure the source directory exists
32+
if [ ! -d $source ]; then
33+
zz_log e "Source directory <$source> does not exist"
34+
exit 1
35+
fi
36+
3137
# Deploy stubs if existing
3238
if [ -d $source/stubs ]; then
3339

34-
echo "${Blue}Deploy stubs${End}"
40+
zz_log i "Deploy stubs"
3541

3642
find $source/stubs -type f -name ".*" -o -type f | while read file; do
3743

@@ -50,14 +56,15 @@ if [ -d $source/stubs ]; then
5056
# Remove # occurrences in the file path
5157
dest=$(echo $dest | sed 's/\/\#/\//g')
5258

53-
echo "Add '$dest' to .gitignore${End}"
59+
# Add to .gitignore if not already there
60+
zz_log i "Add {U $dest} to .gitignore"
5461

5562
# Add to .gitignore if not already there
5663
grep -qxF $dest .gitignore || echo -e "$dest" >>.gitignore
5764
fi
5865

5966
# Merge the file
60-
echo -e "${Yellow}Merging '$dest'...${End}"
67+
zz_log i "Merge {U $file} in {U $dest}"
6168
git merge-file -p -L current -L base -L stubs $dest /dev/null $file >$dest
6269

6370
# Apply the same permissions as the original file
@@ -67,30 +74,29 @@ if [ -d $source/stubs ]; then
6774
fi
6875

6976
# Log the merging process
70-
echo "${Blue}Merge all package folder json files into top level xxx.json${End}"
77+
zz_log i "Merge all package folder json files into top level xxx.json"
7178

7279
for package in package composer; do
7380

7481
# Create package.json if it does not exist or is empty
7582
if [ ! -f $package.json -o ! -s $package.json ]; then
7683
# Create an empty package.json
7784
echo "{}" >$package.json
78-
else
79-
# Pre-sort the existing package.json
80-
echo "${Yellow}Pre-merge normalize $package.json${End}"
81-
normalize-json -s -a -i -t ${tabSize:-4} $package.json
8285
fi
8386

8487
# Merge all package folder json files into the top-level package.json
8588
find $source -maxdepth 1 -name _*.$package.json | sort | while read file; do
86-
echo "${Yellow}Merge $file in $package.json${End}"
89+
zz_log i "Merge {U $file} in {U $package.json}"
8790
jq --indent ${tabSize:-4} -s '.[0] * .[1]' $file $package.json >/tmp/$package.json && mv -f /tmp/$package.json $package.json
8891
done
8992

93+
# Post merge normalize package.json
94+
zz_log i "Post-merge normalize {U $package.json}"
95+
normalize-json -s -a -i -t ${tabSize:-4} $package.json
9096
done
9197

9298
# Call all configure-xxx.sh scripts
9399
find $source -maxdepth 1 -name configure-*.sh | sort | while read file; do
94-
echo "${Yellow}Run $file${End}"
100+
zz_log i "Run {U $file}"
95101
$file
96102
done

src/common-utils/_normalize-json.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ zz_log i "Normalizing JSON..."
2727
list=$(validate-json ${allow:+-a} ${debug:+-d} ${fallback:+-f "$fallback"} ${local:+-l "$local"} ${import:+-i} "$json" "$schema")
2828

2929
if test -z "$list"; then
30-
zz_log e "JSON not valid, cannot normalize" && exit 1
30+
zz_log e "JSON {U $json} not valid, cannot normalize" && exit 1
3131
fi
3232

3333
# Normalize JSON
@@ -63,6 +63,9 @@ if test -s /tmp/$$.json; then
6363
else
6464
jq -M --indent ${tabSize:-4} . /tmp/$$.json >$json
6565
fi
66+
zz_log s "File {U $json} normalized"
67+
else
68+
zz_log e "File {U $json} not normalized"
6669
fi
6770

6871
# Clean up

src/common-utils/_validate-json.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ fi
519519

520520
# Validate JSON according to schema and display valid json paths
521521
if validate "$json" "$schema"; then
522-
zz_log s "JSON is valid and normalized"
522+
zz_log s "File {U $json} valid"
523523
else
524-
zz_log e "JSON is empty or invalid" && exit 1
524+
zz_log e "File {U $json} empty or invalid" && exit 1
525525
fi | sed -n -e 's/^.//g' -e '/^$/d' -e 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'

src/common-utils/_zz_args.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ else
105105
fi
106106
done
107107

108+
# Process remaining '=' parameters
109+
for arg in $(echo $varnames | grep -E "^=" | cut -f2); do
110+
if [ "$#" -gt "0" ]; then
111+
echo "$arg=$1" && shift 1
112+
fi
113+
done
114+
108115
# Process remaining '+' parameters
109116
for arg in $(echo $varnames | grep -E "^\+" | cut -f2); do
110117
if [ "$#" -gt "0" ]; then

src/common-utils/_zz_log.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ lvl="$1" && shift
77

88
case $lvl in
99
i*)
10-
picto=""
11-
base="Blue"
10+
picto="{BBlue →} "
11+
base="White"
1212
;;
1313
w*)
14-
picto="!"
14+
picto="{BYellow !} "
1515
base="Yellow"
1616
;;
1717
e*)
18-
picto=""
18+
picto="{BRed ✕} "
1919
base="Red"
2020
;;
2121
s*)
22-
picto=""
22+
picto="{BGreen ✔} "
2323
base="Green"
2424
;;
25+
-)
26+
picto=""
27+
base="White"
28+
;;
2529
*)
26-
picto="$lvl"
30+
picto="$lvl "
2731
base="White"
2832
;;
2933
esac
3034

3135
eval "$(
32-
if [ -n "$picto" ]; then
33-
echo "echo \"{B $picto} $*\${End}\""
34-
else
35-
echo "echo \"$*\${End}\""
36-
fi | sed -E "s/\{([A-Z]) /{\1${base} /g;s/\{([a-zA-Z]+) ([^}]*)\}/\${\1}\2\${${base}}/g; s/\r//g; "
36+
echo "echo \"$picto$*\${End}\"" | sed -E "s/\{([A-Z]) /{\1${base} /g;s/\{([a-zA-Z]+) ([^}]*)\}/\${\1}\2\${${base}}/g; s/\r//g; "
3737
)" >&2

src/common-utils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Common Utils",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"description": "Common utils for tomgrv/devcontainer-features",
55
"dependsOn": {
66
"ghcr.io/devcontainers/features/common-utils": {}

0 commit comments

Comments
 (0)