批量上传依赖到离线nexus仓库(maven/npm)
MAVEN
#!/bin/sh
# Reference: http://roboojack.blogspot.in/2014/12/bulk-upload-your-local-maven-artifacts.html
if [ "$#" -ne 3 ] || ! [ -d "$1" ]; then
echo "Usage:"
echo " bash run.sh <repoRootFolder> <repositoryId> <repositoryUrl>"
echo ""
echo ""
echo " Where..."
echo " repoRootFolder: The folder containing the repository tree."
echo " Ensure you move the repository outside of ~/.m2 folder"
echo " or whatever is configured in settings.xml"
echo " repositoryId: The repositoryId from the <server> configured for the repositoryUrl in settings.xml."
echo " Ensure that you have configured username and password in settings.xml."
echo " repositoryUrl: The URL of the repository where you want to upload the files."
exit 1
fi
while read -r line ; do
echo "Processing file $line"
jarLocation=$(realpath $line)
pomLocation=$(find $(dirname $jarLocation) -name "*.pom")
# jarLocation=$PWD${jarLocation/pom/jar}
printf "\n ---------------- \n 发布pom: %s\njar: %s\n" $pomLocation $jarLocation
mvn deploy:deploy-file -DpomFile=$pomLocation -Dfile=$jarLocation -DrepositoryId=$2 -Durl=$3
done < <(find $1 -name "*.jar")
NPM
下载
# https://www.npmjs.com/package/node-tgz-downloader
docker run --name temp -d node:latest sleep 1000
docker exec -it temp bash
# 克隆所需要依赖的仓库
git clone xxx
npm set registry=xxx
# 下载所有依赖到本地
npm i
# 利用npm插件将依赖转为tgz文件
npm install node-tgz-downloader -g
download-tgz package-lock path/to/package-lock.json
# 下载产物在这里
ls -lh tarballs
上传
# 遍历当前文件夹下文件
for file in $(find .)
do
if test -f $file
then
echo "当前文件${file}"
curl -u root:123456 -X POST "http://127.0.0.1:13003/service/rest/v1/components?repository=npm-release" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "npm.asset=@${file};type=application/x-compressed"
fi
if test -d $file
then
echo $file 是目录
fi
done
echo 结束
或者可以使用npm命令来发布
#!/bin/bash
REPOSITORY=[REPOSITORY_URL]
PACKAGES_PATH=./packages
npm login --registry=$REPOSITORY
for package in $PACKAGES_PATH/*.tgz; do
npm publish --registry=$REPOSITORY $package
done