forked from flutter/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dash_site
executable file
·104 lines (85 loc) · 3.36 KB
/
dash_site
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
REQUIRED_DART_VERSION="3.4"
REQUIRED_NODE_VERSION="20.12"
REQUIRED_PNPM_VERSION="9.0"
# Check that the 'dart' command is available on the user's path.
if ! command -v dart &> /dev/null; then
echo "Dart not found. To learn how to setup Dart and Flutter, follow the instructions at https://docs.flutter.dev/get-started."
exit 1
fi
# Check that the current version of a tool is the same or
# newer than a required version.
version_is_new_enough() {
required_version="$1"
current_version="$2"
# Split the version strings into lists based on the dot separators.
IFS='.' read -ra required_list <<< "$required_version"
IFS='.' read -ra current_list <<< "$current_version"
# Compare each portion of the version number.
for ((i = 0; i < ${#required_list[@]}; i += 1)); do
required_segment="${required_list[i]:-0}"
current_segment="${current_list[i]:-0}"
if [[ "$required_segment" -gt "$current_segment" ]]; then
# The current version is too low.
return 0
elif [[ "$required_segment" -lt "$current_segment" ]]; then
# The current version is higher, which is ok.
return 1
fi
done
# The current version is (mostly) the same as the required version.
return 1
}
# Determine the available Dart SDK version.
dart_version=$(dart --version | grep -oE 'Dart SDK version: [0-9.]+' | cut -d ' ' -f 4)
# Validate the version of the installed Dart SDK.
if version_is_new_enough "$REQUIRED_DART_VERSION" "$dart_version"; then
echo "Dart version $dart_version is too low. Version $REQUIRED_DART_VERSION or later is required."
exit 1
fi
# Check that the 'node' command is available on the user's path.
if ! command -v node &> /dev/null; then
echo "'node' command not found. To learn how to install and setup Node, reference the repository README."
exit 1
fi
# Determine the available Node version.
node_version=$(node --version | cut -d 'v' -f 2)
# Validate the version of the Node installation.
if version_is_new_enough "$REQUIRED_NODE_VERSION" "$node_version"; then
echo "Node version $node_version is too low. Version $REQUIRED_NODE_VERSION or later is required."
exit 1
fi
# Check that the 'npx' command is available on the user's path.
if ! command -v npx &> /dev/null; then
echo "'npx' command from Node not found. Check your Node installation."
exit 1
fi
# Run extra logic if the 'pnpm' command is available on the user's path.
if command -v pnpm &> /dev/null; then
# Determine the available pnpm version.
pnpm_version=$(pnpm --version)
# Validate the version of the pnpm installation.
if version_is_new_enough "$REQUIRED_PNPM_VERSION" "$pnpm_version"; then
echo "pnpm version $pnpm_version is too low. Version $REQUIRED_PNPM_VERSION or later is required."
exit 1
fi
fi
# Verify that Node packages have been installed.
if [[ ! -d "node_modules" ]]; then
if command -v pnpm &> /dev/null; then
echo "Node packages not found. Installing with 'pnpm install'..."
pnpm install
elif command -v npm &> /dev/null; then
echo "Node packages not found. Installing with 'npm install'..."
npm install
else
echo "Neither 'pnpm' nor 'npm' found. To learn how to setup pnpm, reference the repository README."
exit 1
fi
fi
# Verify that Dart dependencies have been retrieved.
if [[ ! -d ".dart_tool" ]]; then
dart pub get
fi
# Run the Flutter site tool and pass through all arguments.
dart run flutter_site "$@"