-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsmarter-prepare.sh
executable file
·108 lines (84 loc) · 1.97 KB
/
smarter-prepare.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
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
105
106
107
108
#!/bin/sh
set -e
DIR_NAME=${0%/*}
CACHE_DIR=${DIR_NAME}/../node_modules/.build_cache
mkdir -p $CACHE_DIR
LOCAL_COMMIT_ID_HEAD=$(git rev-parse HEAD)
check_project() {
if [[ -z $1 ]]; then
exit
fi
cache=$CACHE_DIR/$1
project_path=${DIR_NAME}/../packages/$1
if [[ ! -d $project_path ]]; then
echo "Project does not exist: packages/$1"
exit
fi
if [[ -f $cache ]]; then
commit_id_on_last_build=$(cat $cache)
if [[ ! -d $project_path/dist ]]; then
dist_removed="1"
fi
uncommitted_changes=$(git status -s $project_path)
if [[ $commit_id_on_last_build == $LOCAL_COMMIT_ID_HEAD ]]; then
is_same_commit="1"
fi
# 同一个 commit、dist 存在、且没有未提交的更改
if [[ -n $is_same_commit && -z $dist_removed ]]; then
if [[ -z "$uncommitted_changes" && -d $project_path/dist ]]; then
echo 'Project unchanged since last build:' $1
exit
fi
fi
# 不同版本之间没有变化、dist 存在、且没有未提交的更改
if [[ -z "$uncommitted_changes" && -z "$dist_removed" ]]; then
changed_accross_version=$(git diff --name-only $commit_id_on_last_build $LOCAL_COMMIT_ID_HEAD $project_path)
if [ -z "$changed_accross_version" ]; then
echo 'Project unchanged:' $1
exit
fi
fi
fi
touch $cache
}
join() {
local IFS="$1"
shift
echo "$*"
}
make_scope() {
case ${#@} in
0)
exit
;;
1)
echo "@clair/$1"
;;
*)
str=$(join , $@)
echo "@clair/{$str}"
;;
esac
}
build_project_done() {
cache=$CACHE_DIR/$1
echo $LOCAL_COMMIT_ID_HEAD >$cache
echo $1 'build DONE'
}
array=()
for var in "$@"; do
result=$(check_project $var)
if [[ -z $result ]]; then
array+=("$var")
fi
done
scope=$(make_scope ${array[@]})
if [[ -n $scope ]]; then
npx lerna run build --stream --parallel --scope=$(make_scope ${array[@]})
for var in "${array[@]}"; do
build_project_done $var
done
else
# echo 'Skip'
echo
fi