From 5c97b669ae0ac57e917ee8d9a815659888203412 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Wed, 29 Apr 2026 14:24:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20HarmonyOS=20SDK=20?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=8F=91=E7=89=88=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/publish.sh — 接受版本号参数,更新 oh-package.json5 并执行 ohpm publish。 Co-Authored-By: Claude Sonnet 4.6 --- xuqm-sdk/scripts/publish.sh | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 xuqm-sdk/scripts/publish.sh diff --git a/xuqm-sdk/scripts/publish.sh b/xuqm-sdk/scripts/publish.sh new file mode 100755 index 0000000..26684c4 --- /dev/null +++ b/xuqm-sdk/scripts/publish.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# XuqmGroup HarmonyOS SDK 本地发版脚本 +# 使用方式: +# bash scripts/publish.sh 1.0.0 +# 或直接执行(交互式输入版本号): +# bash scripts/publish.sh +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_DIR="$(dirname "$SCRIPT_DIR")" # xuqm-sdk/ +PKG_FILE="$SDK_DIR/oh-package.json5" + +# ── 版本号 ──────────────────────────────────────────────────────────────────── + +VERSION="${1:-}" +if [ -z "$VERSION" ]; then + read -rp "请输入发布版本号(如 1.0.0): " VERSION +fi +if [ -z "$VERSION" ]; then + echo "❌ 版本号不能为空" >&2 + exit 1 +fi + +# ── 检查 ohpm ───────────────────────────────────────────────────────────────── + +if ! command -v ohpm &>/dev/null; then + echo "❌ 未找到 ohpm 命令,请安装 DevEco Studio 并将 ohpm 加入 PATH" >&2 + echo " macOS 默认路径:~/Library/Huawei/ohpm/bin" >&2 + exit 1 +fi + +if ! ohpm whoami &>/dev/null; then + echo "❌ 未登录 ohpm,请先执行:ohpm login" >&2 + exit 1 +fi + +# ── 更新版本号 ──────────────────────────────────────────────────────────────── + +echo "→ 更新 oh-package.json5 版本为 $VERSION ..." +if [[ "$(uname)" == "Darwin" ]]; then + sed -i '' "s/\"version\":[[:space:]]*\"[^\"]*\"/\"version\": \"$VERSION\"/" "$PKG_FILE" +else + sed -i "s/\"version\":[[:space:]]*\"[^\"]*\"/\"version\": \"$VERSION\"/" "$PKG_FILE" +fi + +# 验证更新结果 +ACTUAL=$(grep '"version"' "$PKG_FILE" | head -1) +echo " $ACTUAL" + +# ── 发布 ────────────────────────────────────────────────────────────────────── + +echo "→ 发布 @xuqm/harmony-sdk@$VERSION 到 ohpm ..." +cd "$SDK_DIR" +ohpm publish + +echo "" +echo "✅ HarmonyOS SDK $VERSION 发布成功" +echo " 集成方式:ohpm install @xuqm/harmony-sdk@$VERSION"