Skip to content

Commit 2484c3f

Browse files
committed
chore: enhance build function with better error handling and build options
1 parent 425aac8 commit 2484c3f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

scripts/build-base.sh

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/bin/bash
22

3-
## 一键打包所有 package
3+
## One-click build script for all packages
44

55
# 获取 yarn dev/build 类型
66
buildType=build
7-
if [ -n "$1" ]; then
8-
if [ "$1" != "dev" ] && [ "$1" != "build" ]; then
9-
echo "Error: Build type must be either 'dev' or 'build'"
10-
exit 1
11-
fi
7+
if [ -z "$1" ]; then
8+
echo "No build type specified, defaulting to 'build'"
9+
elif [ "$1" != "dev" ] && [ "$1" != "build" ]; then
10+
echo "Error: Build type must be either 'dev' or 'build'"
11+
exit 1
12+
else
1213
buildType=$1
1314
fi
1415

@@ -47,15 +48,28 @@ print_summary() {
4748
# Update build_package function
4849
build_package() {
4950
local package_name=$1
51+
local timeout=1800 # 30 minutes timeout
5052
echo "Building package: $package_name"
51-
if cd "$package_name" && \
52-
rm -rf dist && \
53-
yarn "$buildType"; then
53+
if cd "$package_name"; then
54+
rm -rf dist
55+
if timeout $timeout yarn "$buildType" 2> build_error.log; then
56+
rm -f build_error.log
57+
log_status "$package_name" "success"
58+
else
59+
if [ -f build_error.log ]; then
60+
echo "Build failed for $package_name. Error:"
61+
cat build_error.log
62+
rm -f build_error.log
63+
fi
64+
log_status "$package_name" "failed"
65+
cd ..
66+
return 1
67+
fi
5468
log_status "$package_name" "success"
5569
cd ..
5670
else
71+
echo "Failed to enter directory: $package_name"
5772
log_status "$package_name" "failed"
58-
cd ..
5973
return 1
6074
fi
6175
}

0 commit comments

Comments
 (0)