-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-assets.sh
executable file
·69 lines (54 loc) · 1.92 KB
/
update-assets.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
69
#!/bin/bash
check_latest_version () {
local latest_version
latest_version=$(curl "https://registry.npmjs.org/@catala-lang/$1/latest" -s | grep -oP '"version":"\K[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z]+(\.[0-9]+)?)?')
echo "[info] Latest version: $latest_version"
if [ -d "node_modules/@catala-lang/$1-$latest_version" ]; then
echo "[info] Already up to date"
else
echo "[info] Adding latest version $latest_version"
yarn add -D "@catala-lang/$1-$latest_version@npm:@catala-lang/$1@$latest_version"
echo "[done] Added latest version $latest_version"
fi
}
copy_files () {
local package_name
local files_to_copy
local version_number
package_name="$1"
shift 1
echo "[info] Removing directory $package_name"
rm -r "$package_name"
echo "[info] Checking latest version for @catala-lang/$package_name"
check_latest_version "$package_name"
files_to_copy=("$@")
for folder in node_modules/@catala-lang/$package_name*; do
version_number=""
if [ -L "$folder" ]; then
# found a symlink created by yarn link
version_number=$(echo "local")
elif [ -d "$folder" ]; then
version_number=$(echo "$folder" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?(-[a-zA-Z]+(\.[0-9]+)?)?')
fi
if [ -n "$version_number" ]; then
local dest="$package_name/$version_number"
mkdir -p "$dest"
for file in "${files_to_copy[@]}"; do
cp "$folder/$file" "$dest"
done
echo "[done] Created $dest"
fi
done
}
assets_files=(
"assets/allocations_familiales.html"
"assets/allocations_familiales_schema_fr.json"
"assets/allocations_familiales_ui_schema_fr.json"
"assets/aides_logement.html"
"assets/aides_logement_schema_fr.json"
"assets/aides_logement_ui_fr.schema.jsx"
"assets/aides_logement_init.json"
)
copy_files "catala-web-assets" "${assets_files[@]}"
french_law_files=("src/french_law.js")
copy_files "french-law" "${french_law_files[@]}"