-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsync-engine-version.sh
executable file
·68 lines (60 loc) · 2.63 KB
/
sync-engine-version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# How it works?
# 1. reads `engines.version` from ./node_modules/vscode-languageclient/package.json
# 2. puts THAT version to `engines.version` and `devDependencies.@types/vscode` in ./package.json
#
# If wont do that - there will be error in logs
# Path to the package.json files
PACKAGE_JSON="./package.json"
LANGUAGE_CLIENT_JSON="./node_modules/vscode-languageclient/package.json"
# Check if the vscode-languageclient package.json exists
if [ ! -f "$LANGUAGE_CLIENT_JSON" ]; then
echo "File $LANGUAGE_CLIENT_JSON does not exist. Ensure vscode-languageclient is installed."
exit 1
fi
# Get the engines.vscode version from the vscode-languageclient package.json
vscode_engine_version=$(jq -r '.engines.vscode' "$LANGUAGE_CLIENT_JSON")
# Check if the version was found
if [ "$vscode_engine_version" = "null" ]; then
echo "engines.vscode version not found in $LANGUAGE_CLIENT_JSON."
exit 1
fi
# Get the current engines.vscode and @types/vscode version in package.json
current_engine_version=$(jq -r '.engines.vscode' "$PACKAGE_JSON")
current_types_version=$(jq -r '.devDependencies["@types/vscode"]' "$PACKAGE_JSON")
# Function to update package.json
update_package_json() {
jq --arg version "$vscode_engine_version" \
'.engines.vscode = $version | .devDependencies["@types/vscode"] = $version' \
"$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
echo "Updated engines.vscode and devDependencies.@types/vscode to $vscode_engine_version in $PACKAGE_JSON."
}
# Check for command-line argument
case "$1" in
update-in-place)
if [ "$current_engine_version" = "$vscode_engine_version" ] && [ "$current_types_version" = "$vscode_engine_version" ]; then
echo "No updates needed; versions are already up to date."
else
update_package_json
fi
;;
check)
if [ "$current_engine_version" = "$vscode_engine_version" ] && [ "$current_types_version" = "$vscode_engine_version" ]; then
echo "Versions are up to date."
else
echo "Version mismatch detected:"
if [ "$current_engine_version" != "$vscode_engine_version" ]; then
echo " engines.vscode in $PACKAGE_JSON: $current_engine_version"
fi
if [ "$current_types_version" != "$vscode_engine_version" ]; then
echo " devDependencies.@types/vscode in $PACKAGE_JSON: $current_types_version"
fi
echo " Expected version from vscode-languageclient: $vscode_engine_version"
exit 1
fi
;;
*)
echo "Usage: $0 {update-in-place|check}"
exit 1
;;
esac