Skip to content

Commit 5f34bd5

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

7 files changed

Lines changed: 122 additions & 99 deletions

File tree

package.json

Lines changed: 73 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
"url": "https://github.com/tomgrv/devcontainer-features/issues",
2525
"email": "project@hostname.com"
2626
},
27+
"author": "tomgrv",
28+
"files": [
29+
"./src/*",
30+
"./stubs/*"
31+
],
32+
"bin": "./install.sh",
33+
"type": "module",
2734
"repository": {
2835
"type": "git",
2936
"url": "git+https://github.com/tomgrv/devcontainer-features.git"
@@ -32,72 +39,13 @@
3239
"type": "individual",
3340
"url": "https://buymeacoffee.com/tomgrv"
3441
},
35-
"author": "tomgrv",
36-
"type": "module",
37-
"bin": "./install.sh",
38-
"files": [
39-
"./src/*",
40-
"./stubs/*"
41-
],
4242
"scripts": {
4343
"lint": "npx --yes lint-staged",
4444
"release": "npx --yes commit-and-tag-version --no-verify --",
4545
"test": "echo \"Warning: no test specified\"",
4646
"update": "npm-check-updates -i -u",
4747
"update-all": "npm run update -ws --root"
4848
},
49-
"commitlint": {
50-
"extends": [
51-
"@commitlint/config-conventional"
52-
],
53-
"rules": {
54-
"subject-case": [
55-
2,
56-
"never",
57-
[
58-
"start-case",
59-
"pascal-case",
60-
"upper-case"
61-
]
62-
],
63-
"scope-enum": [
64-
2,
65-
"always",
66-
[
67-
"deps",
68-
"release",
69-
"security",
70-
"i18n",
71-
"config",
72-
"add",
73-
"remove",
74-
"breaking",
75-
"modules",
76-
"packages",
77-
"ui-ux",
78-
"api",
79-
"model"
80-
]
81-
]
82-
}
83-
},
84-
"lint-staged": {
85-
"*.php": [
86-
"composer lint"
87-
],
88-
"*.{js,jsx,ts,tsx,md,html,css,json,vue, yaml, yml, sh}": [
89-
"npx --yes prettier --write"
90-
],
91-
"package.json": [
92-
"npx --yes sort-package-json"
93-
],
94-
"composer.lock": [
95-
"composer validate --ansi --strict"
96-
],
97-
".devcontainer/*": [
98-
"cp -u -t ./stubs/.devcontainer "
99-
]
100-
},
10149
"config": {
10250
"commitizen": {
10351
"path": "@commitlint/cz-commitlint"
@@ -107,16 +55,6 @@
10755
"githooks"
10856
]
10957
},
110-
"prettier": {
111-
"insertPragma": true,
112-
"plugins": [
113-
"prettier-plugin-sh"
114-
],
115-
"semi": false,
116-
"singleQuote": true,
117-
"tabWidth": 4,
118-
"trailingComma": "es5"
119-
},
12058
"peerDependencies": {
12159
"@commitlint/cli": "^19.2.2",
12260
"@commitlint/config-conventional": "^19.2.2",
@@ -131,6 +69,16 @@
13169
"lint-staged": "^15.2.2",
13270
"prettier": "^3.2.5"
13371
},
72+
"prettier": {
73+
"insertPragma": true,
74+
"plugins": [
75+
"prettier-plugin-sh"
76+
],
77+
"semi": false,
78+
"singleQuote": true,
79+
"tabWidth": 4,
80+
"trailingComma": "es5"
81+
},
13482
"commit-and-tag-version": {
13583
"bumpFiles": [
13684
{
@@ -184,6 +132,41 @@
184132
"prebump": "gitversion -config .gitversion -showvariable MajorMinorPatch"
185133
}
186134
},
135+
"commitlint": {
136+
"extends": [
137+
"@commitlint/config-conventional"
138+
],
139+
"rules": {
140+
"scope-enum": [
141+
2,
142+
"always",
143+
[
144+
"deps",
145+
"release",
146+
"security",
147+
"i18n",
148+
"config",
149+
"add",
150+
"remove",
151+
"breaking",
152+
"modules",
153+
"packages",
154+
"ui-ux",
155+
"api",
156+
"model"
157+
]
158+
],
159+
"subject-case": [
160+
2,
161+
"never",
162+
[
163+
"start-case",
164+
"pascal-case",
165+
"upper-case"
166+
]
167+
]
168+
}
169+
},
187170
"git-precommit-checks": {
188171
"rules": [
189172
{
@@ -197,5 +180,25 @@
197180
"regex": "(?:FIXME|TODO)"
198181
}
199182
]
183+
},
184+
"lint-staged": {
185+
"*.php": [
186+
"composer lint"
187+
],
188+
"*.{js,jsx,ts,tsx,md,html,css,json,vue, yaml, yml, sh}": [
189+
"npx --yes prettier --write"
190+
],
191+
"*.json": [
192+
"normalize-json -s -a -i -t 4 -l true"
193+
],
194+
"package.json": [
195+
"npx --yes sort-package-json"
196+
],
197+
"composer.lock": [
198+
"composer validate --ansi --strict"
199+
],
200+
".devcontainer/*": [
201+
"cp -u -t ./stubs/.devcontainer "
202+
]
200203
}
201-
}
204+
}

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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ eval $(
99
a - allow allow additional properties at root level
1010
d - debug debug output
1111
f fallback fallback fallback schema to use if none found locally
12-
l local local infer schema in <local> folder from json file name (x.y.json => <local>/y.schema.json)
12+
l local local infer schema in <local> folder from json file name (x.y.json => <local>/y.schema.json). Use "true" to use script folder
1313
i - import infer on schema store if nothing found locally (x.y.json => "y" on schema store)
1414
- json json json to normalize
1515
+ schema schema schema to use for normalization
@@ -460,11 +460,15 @@ if [ -n "$local" ]; then
460460
# Identify package type from file name just before json extension
461461
type=$(basename -s .json $json | sed -E 's/.*\.(.*)/\1/')
462462

463+
if [ "$local" == "true" ]; then
464+
local=$(dirname $0)
465+
fi
466+
463467
# Identify schema file
464468
schema=$local/_$type.schema.json
465469

466470
# log
467-
zz_log i "Infering schema from local folder for {UYellow $json}"
471+
zz_log i "Infering schema from local folder {U $folder} for {UYellow $json}"
468472
fi
469473

470474
# Check if schema file exists, and if not and import allowed, download it from schema store
@@ -519,7 +523,7 @@ fi
519523

520524
# Validate JSON according to schema and display valid json paths
521525
if validate "$json" "$schema"; then
522-
zz_log s "JSON is valid and normalized"
526+
zz_log s "File {U $json} valid"
523527
else
524-
zz_log e "JSON is empty or invalid" && exit 1
528+
zz_log e "File {U $json} empty or invalid" && exit 1
525529
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.2",
44
"description": "Common utils for tomgrv/devcontainer-features",
55
"dependsOn": {
66
"ghcr.io/devcontainers/features/common-utils": {}

0 commit comments

Comments
 (0)