-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·74 lines (57 loc) · 1.74 KB
/
build.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
#!/bin/bash
# 1) chmod +x build.sh
# 2) ./build.sh [patch|minor|major]
set -e
MANIFEST_FILE="./public/manifest.json"
BUILD_DIR="build"
DEV_OUTPUT_DIR="${BUILD_DIR}/develop"
PROD_OUTPUT_DIR="${BUILD_DIR}/production"
VERSION_TYPE=$1
# 1. VERSION 업데이트
update_version() {
if [[ -n "$VERSION_TYPE" ]]; then
echo "Updating version with type: $VERSION_TYPE"
CURRENT_VERSION=$(node -p "require('${MANIFEST_FILE}').version")
UPDATED_VERSION=$(node -p "
const semver = require('semver');
semver.inc('${CURRENT_VERSION}', '${VERSION_TYPE}');
")
if [[ -z "$UPDATED_VERSION" ]]; then
echo "Error: Failed to update version. Check your 'manifest.json'."
exit 1
fi
# manifest.json 업데이트
jq ".version = \"${UPDATED_VERSION}\"" "$MANIFEST_FILE" > tmp.$$.json && mv tmp.$$.json "$MANIFEST_FILE"
echo "Version updated: ${CURRENT_VERSION} -> ${UPDATED_VERSION}"
else
echo "No version type provided. Skipping version update."
fi
}
# 2. development 빌드
build_dev() {
echo "Starting development build..."
rm -rf "$DEV_OUTPUT_DIR"
mkdir -p "$DEV_OUTPUT_DIR"
echo "Building using .env.development"
yarn build:dev
echo "Moving development build to $DEV_OUTPUT_DIR"
mv dist/* "$DEV_OUTPUT_DIR/"
}
# 3. production 빌드
build_prod() {
echo "Starting production build..."
VERSION=$(node -p "require('${MANIFEST_FILE}').version")
echo "Version: $VERSION"
echo "Building using .env.production"
yarn build:prod
ZIP_FILE="build-${VERSION}.zip"
echo "Creating zip file: $ZIP_FILE"
zip -r "$ZIP_FILE" "dist/"
echo "Moving production zip to $PROD_OUTPUT_DIR"
mv "$ZIP_FILE" "$PROD_OUTPUT_DIR/"
}
# main #
update_version
build_dev
build_prod
echo "Build completed successfully!"