Skip to content

Commit 47cb917

Browse files
committed
chore: 添加 bash 构建脚本和 IDE 配置
1 parent adc2469 commit 47cb917

6 files changed

Lines changed: 210 additions & 0 deletions

File tree

.idea/.gitignore

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/ChuChartManager.iml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packaging/build.sh

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
MODE="${1:-Canary}"
5+
CANARY_PUBLISHER="${2:-CN=凌莞}"
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9+
10+
# ==========================================
11+
# 1. 版本号
12+
# ==========================================
13+
echo -e "\033[36mCalculating version...\033[0m"
14+
BUILD_VERSION="0.1.0.0"
15+
BASE_VER="0.1.0"
16+
17+
if git_describe=$(git -C "$PROJECT_ROOT" describe --tags --long 2>/dev/null); then
18+
if [[ "$git_describe" =~ v?([0-9]+\.[0-9]+(\.[0-9]+)?)-([0-9]+)-g[0-9a-f]+ ]]; then
19+
BASE_VER="${BASH_REMATCH[1]}"
20+
COMMIT_COUNT="${BASH_REMATCH[3]}"
21+
IFS='.' read -ra parts <<< "$BASE_VER"
22+
if [[ ${#parts[@]} -eq 2 ]]; then
23+
BASE_VER_FULL="${BASE_VER}.0"
24+
else
25+
BASE_VER_FULL="$BASE_VER"
26+
fi
27+
28+
if [[ "$MODE" == "Canary" ]]; then
29+
BUILD_VERSION="${BASE_VER_FULL}.${COMMIT_COUNT}"
30+
else
31+
BUILD_VERSION="${BASE_VER_FULL}.0"
32+
fi
33+
fi
34+
else
35+
COMMIT_COUNT=$(git -C "$PROJECT_ROOT" rev-list --count HEAD 2>/dev/null || echo "0")
36+
BUILD_VERSION="0.1.0.${COMMIT_COUNT}"
37+
echo -e "\033[33mWarning: No git tag found, using fallback version $BUILD_VERSION\033[0m"
38+
fi
39+
40+
echo -e "\033[32mTarget Version: $BUILD_VERSION\033[0m"
41+
42+
# ==========================================
43+
# 2. 清理
44+
# ==========================================
45+
echo -e "\033[36mCleaning up...\033[0m"
46+
PACK_DIR="$SCRIPT_DIR/Pack"
47+
rm -rf "$PACK_DIR"
48+
mkdir -p "$PACK_DIR"
49+
rm -f "$SCRIPT_DIR"/*.appx "$SCRIPT_DIR"/*.msix
50+
51+
# ==========================================
52+
# 3. 前端构建
53+
# ==========================================
54+
WWWROOT_PATH="$PROJECT_ROOT/ChuChartManager/wwwroot"
55+
if [[ "$MODE" != "Canary" ]] || [[ ! -f "$WWWROOT_PATH/index.html" ]]; then
56+
echo -e "\033[36mBuilding Frontend...\033[0m"
57+
pushd "$PROJECT_ROOT" > /dev/null
58+
pnpm install
59+
pnpm --filter ccm-frontend build
60+
popd > /dev/null
61+
else
62+
echo -e "\033[33mwwwroot already exists, skipping frontend build.\033[0m"
63+
fi
64+
65+
# ==========================================
66+
# 4. FreeMote 工具链
67+
# ==========================================
68+
echo -e "\033[36mBuilding FreeMote tools...\033[0m"
69+
pushd "$PROJECT_ROOT" > /dev/null
70+
dotnet build FreeMote/FreeMote.Tools.PsbDecompile -c Release
71+
dotnet build FreeMote/FreeMote.Tools.PsBuild -c Release
72+
dotnet build FreeMote/FreeMote.Tools.Viewer -c Release
73+
popd > /dev/null
74+
75+
# ==========================================
76+
# 5. 发布主程序 + CLI
77+
# ==========================================
78+
echo -e "\033[36mPublishing ChuChartManager + CLI...\033[0m"
79+
pushd "$PROJECT_ROOT" > /dev/null
80+
81+
PUBLISH_ARGS=(
82+
-c Release -r win-x64 --self-contained
83+
-p:PublishSingleFile=false
84+
-p:PublishReadyToRun=true
85+
-p:ErrorOnDuplicatePublishOutputFiles=false
86+
-o "$PACK_DIR"
87+
)
88+
89+
dotnet publish ChuChartManager/ChuChartManager.csproj "${PUBLISH_ARGS[@]}"
90+
dotnet publish ChuChartManager.CLI/ChuChartManager.CLI.csproj "${PUBLISH_ARGS[@]}"
91+
popd > /dev/null
92+
93+
# ==========================================
94+
# 6. 复制 Manifest
95+
# ==========================================
96+
cp "$SCRIPT_DIR/AppxManifest.xml" "$PACK_DIR/AppxManifest.xml"
97+
98+
# ==========================================
99+
# 7. 复制图标
100+
# ==========================================
101+
echo -e "\033[36mCopying Appx icons...\033[0m"
102+
cp "$SCRIPT_DIR"/Base/*.png "$PACK_DIR/"
103+
104+
# ==========================================
105+
# 8. 修改 Manifest 版本和 Canary 标识
106+
# ==========================================
107+
echo -e "\033[36mPatching Manifest...\033[0m"
108+
MANIFEST_PATH="$PACK_DIR/AppxManifest.xml"
109+
110+
# 替换版本号
111+
sed -i "s/Version=\"[^\"]*\"/Version=\"$BUILD_VERSION\"/" "$MANIFEST_PATH"
112+
113+
if [[ "$MODE" == "Canary" ]]; then
114+
sed -i "s/Name=\"MuNET.ChuChartManager\"/Name=\"MuNET.ChuChartManager.Canary\"/" "$MANIFEST_PATH"
115+
sed -i "s/Publisher=\"[^\"]*\"/Publisher=\"$CANARY_PUBLISHER\"/" "$MANIFEST_PATH"
116+
sed -i "s/<DisplayName>ChuChartManager</<DisplayName>ChuChartManager (Canary)</" "$MANIFEST_PATH"
117+
sed -i "s/<PublisherDisplayName>MuNET</<PublisherDisplayName>凌莞</" "$MANIFEST_PATH"
118+
sed -i 's/DisplayName="ChuChartManager"/DisplayName="ChuChartManager (Canary)"/' "$MANIFEST_PATH"
119+
sed -i 's/Alias="ccm.exe"/Alias="ccmc.exe"/' "$MANIFEST_PATH"
120+
fi
121+
122+
# ==========================================
123+
# 9. 生成 PRI 并打包
124+
# ==========================================
125+
echo -e "\033[36mGenerating PRI and Packing...\033[0m"
126+
pushd "$PACK_DIR" > /dev/null
127+
128+
makepri.exe createconfig /cf priconfig.xml /dq zh-CN
129+
makepri.exe new /pr . /cf ./priconfig.xml
130+
rm -f priconfig.xml
131+
132+
if [[ "$MODE" == "Canary" ]]; then
133+
OUTPUT_NAME="ChuChartManager_Canary_${BUILD_VERSION}.appx"
134+
else
135+
OUTPUT_NAME="ChuChartManager_${BUILD_VERSION}.appx"
136+
fi
137+
OUTPUT_APPX="$SCRIPT_DIR/$OUTPUT_NAME"
138+
139+
makeappx.exe pack /d . /p "$OUTPUT_APPX"
140+
popd > /dev/null
141+
142+
# ==========================================
143+
# 10. 签名 (仅 Canary)
144+
# ==========================================
145+
if [[ "$MODE" == "Canary" ]]; then
146+
echo -e "\033[36mSigning Appx...\033[0m"
147+
SIGN_CMD="D:/Sign/signcode.cmd"
148+
if [[ -f "$SIGN_CMD" ]]; then
149+
"$SIGN_CMD" "$OUTPUT_APPX"
150+
echo -e "\033[32mBuild & Sign Complete: $OUTPUT_APPX\033[0m"
151+
else
152+
echo -e "\033[33mWarning: Sign script not found at $SIGN_CMD. Skipping signing.\033[0m"
153+
echo -e "\033[33mBuild Complete (unsigned): $OUTPUT_APPX\033[0m"
154+
fi
155+
else
156+
echo -e "\033[32mBuild Complete: $OUTPUT_APPX\033[0m"
157+
fi

0 commit comments

Comments
 (0)