# 批量上传npm依赖到私服脚本操作 当前文件夹下有 - tgz文件夹(**里面存放要上传的.tgz包**) - npm-uploadbatch.sh ⚠下载到本地后,莫修改当前文件下的相对路径以及文件夹名! ## 修改脚本配置信息 ```shell #!/bin/bash targetDir=./tgz publishRestful=http:///service/rest/v1/components?repository= echo ">>> 文件所在目录:$targetDir <<<" dir=$(ls -l $targetDir | awk '/.tgz$/ {print $NF}') cd $targetDir for file in $dir do echo ">>> $targetDir/$file 上传开始 \n" ret=`curl -u : -X POST "$publishRestful" -H "Accept: application/json" -H "Content-Type: multipart/form-data" -F "npm.asset=@$file;type=application/x-compressed"` echo $ret echo ">>> $targetDir/$file 上传完成 \n" done ``` - ``:你nexus私服的IP:端口 - ``:你nexus私服的npm(hosted)仓库名 - ``:你nexus私服的用户名(一般为admin管理员) - ``:你nexus私服的密码(一般为admin管理员对应的密码) 示例: ```shell #!/bin/bash targetDir=./tgz publishRestful=http://10.58.20.199:8081/service/rest/v1/components?repository=npm_hosted echo ">>> 文件所在目录:$targetDir <<<" dir=$(ls -l $targetDir | awk '/.tgz$/ {print $NF}') cd $targetDir for file in $dir do echo ">>> $targetDir/$file 上传开始 \n" ret=`curl -u admin:1234 -X POST "$publishRestful" -H "Accept: application/json" -H "Content-Type: multipart/form-data" -F "npm.asset=@$file;type=application/x-compressed"` echo $ret echo ">>> $targetDir/$file 上传完成 \n" done ``` ## windows上传 ❗前提:安装好了git,这里不再赘述安装! 在当前文件夹下,右键选择`git bash here`,在窗口输入以下命令: ```shell ./npm-uploadbatch.sh ``` ## linux上传 - 把npm文件夹下的所有内容上传到Linux服务器 - cd 到npm文件夹目录下 - 输入以下命令运行脚本(同理运行脚本前,将脚本里面的配置信息更改为你的私服信息) ```shell ./npm-uploadbatch.sh ```