Skip to content

Commit

Permalink
Merge pull request #271 from onerain88/feat/npm-release
Browse files Browse the repository at this point in the history
支持 NPMJS 发布
  • Loading branch information
onerain88 authored Oct 18, 2023
2 parents 68062f1 + 3c62ce7 commit b17ec73
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,8 @@ Push/Push.Unity/iOSProj/
Push/Push.Unity/Logs/
!Push/Push.Unity/Assets/**/*.meta
.vscode/
script/deploy-upm.sh

.env
upm-play
upm-realtime
upm-storage
4 changes: 2 additions & 2 deletions Unity/play.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "This is leancloud Play package",
"unity": "2019.1",
"dependencies": {
"com.leancloud.storage": "https://github.com/leancloud/csharp-sdk-upm.git#storage-__VERSION__",
"com.leancloud.realtime": "https://github.com/leancloud/csharp-sdk-upm.git#realtime-__VERSION__"
"com.leancloud.storage": "__VERSION__",
"com.leancloud.realtime": "__VERSION__"
},
"keywords": ["LeanCloud", "Play"],
"author": {
Expand Down
2 changes: 1 addition & 1 deletion Unity/realtime.package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "This is leancloud realtime package",
"unity": "2019.1",
"dependencies": {
"com.leancloud.storage": "https://github.com/leancloud/csharp-sdk-upm.git#storage-__VERSION__"
"com.leancloud.storage": "__VERSION__"
},
"keywords": ["LeanCloud", "Realtime"],
"author": {
Expand Down
35 changes: 35 additions & 0 deletions script/deploy-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
# 发布 npm
# sh ./script/deploy_npm.sh registry.npmjs.org {authToken} ./Assets/TapTap/Common
# sh ./script/deploy_npm.sh nexus.tapsvc.com/repository/npm-registry {authToken} ./Assets/TapTap/Common

# 接收参数

echo $1
echo $2
echo $3

# 仓库
registry=$1

# 认证方式
authToken=$2

# 模块目录
modulePath=$3

echo "Package: $modulePath"

cd $modulePath

echo email=bot@xd.com > .npmrc
echo registry=https://$registry/ >> .npmrc
echo //$registry/:always-auth=true >> .npmrc
echo //$registry/:_authToken=$authToken >> .npmrc

# 发布
npm publish --access public

rm -rf .npmrc

cd -
24 changes: 24 additions & 0 deletions script/deploy-upm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# 发布 upm

REPO_GIT_URL="git@github.com:leancloud/csharp-sdk-upm.git"

upmPath=$1
tagPrefix=$2
version=$3

# push 到 GitHub
upmTag=$tagPrefix-$version

cd $upmPath

git init
git config user.name "leancloud-bot";
git config user.email "ci@leancloud.cn";
git add .
git commit -m $version .;
git tag $upmTag
# git push origin $version
git push -f $REPO_GIT_URL $upmTag

cd -
127 changes: 127 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/sh
VERSION_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$"

UNITY_PATH="/Applications/Unity/Hub/Editor/2020.3.36f1c1/Unity.app/Contents/MacOS/Unity"


# 从 Releases 下载
download() {
releaseURL=$1
upmPath=$2
# Plugins
zipFile=`basename "$releaseURL"`
curl -L $releaseURL -o $zipFile
unzip $zipFile -d $upmPath
rm $zipFile
}

# 去掉依赖中的重复文件
diff() {
srcPath=$1
dstPath=$2
for df in `ls $dstPath`:
do
for sf in `ls $srcPath`:
do
if cmp -s $dstPath/$df $srcPath/$sf
then
rm $dstPath/$df
break
fi
done
done
}

# 生成 package.json
package() {
packageJson=$1
upmPath=$2

cat $packageJson | sed 's/__VERSION__/'$version'/' > $upmPath/package.json
}

# 生成 .meta
generateMetas() {
upmPath=$1

# 创建 Unity 工程
unityProject=./Unity/UnityProject
$UNITY_PATH -batchmode -quit -createProject $unityProject

# 将 UPM 包移动到 Unity Project 下
unityAssetsPath=$unityProject/Assets
mv $upmPath/* $unityAssetsPath/

# 使用 Unity Editor 打开工程,生成 .meta 文件
$UNITY_PATH -batchmode -quit -nographics -silent-crashes -projectPath $unityProject

mv $unityAssetsPath/* $upmPath/

# 移除临时 Unity 工程
rm -rf $unityProject
}

# 发布流程

version=$1

if [[ !($version =~ $VERSION_REGEX) ]]; then
echo 'Invalid version'
exit
fi

if !(test -f $UNITY_PATH); then
echo 'Unity does NOT exist.'
exit
fi

STORAGE_RELEASE_URL="https://github.com/leancloud/csharp-sdk/releases/download/$version/LeanCloud-SDK-Storage-Unity.zip"
REALTIME_RELEASE_URL="https://github.com/leancloud/csharp-sdk/releases/download/$version/LeanCloud-SDK-Realtime-Unity.zip"
PLAY_RELEASE_URL="https://github.com/leancloud/csharp-sdk/releases/download/$version/LeanCloud-SDK-Play-Unity.zip"

upmStoragePath="upm-storage"
upmRealtimePath="upm-realtime"
upmPlayPath="upm-play"

# 下载
download $STORAGE_RELEASE_URL $upmStoragePath
download $REALTIME_RELEASE_URL $upmRealtimePath
download $PLAY_RELEASE_URL $upmPlayPath

# 去重
diff $upmRealtimePath/Plugins $upmPlayPath/Plugins
diff $upmStoragePath/Plugins $upmRealtimePath/Plugins

# 打包
package ./Unity/storage.package.json $upmStoragePath
package ./Unity/realtime.package.json $upmRealtimePath
package ./Unity/play.package.json $upmPlayPath

# 生成 .meta
generateMetas $upmStoragePath
generateMetas $upmRealtimePath
generateMetas $upmPlayPath

# 发布 Github UPM
storageTag="storage"
realtimeTag="realtime"
playTag="play"

sh ./script/deploy-upm.sh $upmStoragePath $storageTag $version
sh ./script/deploy-upm.sh $upmRealtimePath $realtimeTag $version
sh ./script/deploy-upm.sh $upmPlayPath $playTag $version

发布 NPMJS
sh ./script/deploy-npm.sh $NPMJS_REGISTRY $NPMJS_TOKEN $upmStoragePath
sh ./script/deploy-npm.sh $NPMJS_REGISTRY $NPMJS_TOKEN $upmRealtimePath
sh ./script/deploy-npm.sh $NPMJS_REGISTRY $NPMJS_TOKEN $upmPlayPath

# 发布 Tap NPM
sh ./script/deploy-npm.sh $TAP_NPM_REGISTRY $TAP_NPM_TOKEN $upmStoragePath
sh ./script/deploy-npm.sh $TAP_NPM_REGISTRY $TAP_NPM_TOKEN $upmRealtimePath
sh ./script/deploy-npm.sh $TAP_NPM_REGISTRY $TAP_NPM_TOKEN $upmPlayPath

# 移除 SDK 包
rm -rf $upmStoragePath
rm -rf $upmRealtimePath
rm -rf $upmPlayPath

0 comments on commit b17ec73

Please sign in to comment.