README.md 2.1 KB
Newer Older
H
hexiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75


# 批量上传npm依赖到私服脚本操作

当前文件夹下有

- tgz文件夹(**里面存放要上传的.tgz包**
- npm-uploadbatch.sh

⚠下载到本地后,莫修改当前文件下的相对路径以及文件夹名!

## 修改脚本配置信息

```shell
#!/bin/bash
targetDir=./tgz
publishRestful=http://<nexus npm hosed address>/service/rest/v1/components?repository=<npm hosed repository name>
echo ">>> 文件所在目录:$targetDir <<<"
dir=$(ls -l $targetDir | awk '/.tgz$/ {print $NF}')
cd $targetDir
 
for file in $dir
do
  echo ">>> $targetDir/$file 上传开始 \n"
  ret=`curl -u <nexus username>:<nexus password> -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 npm hosed address>`:你nexus私服的IP:端口
- `<npm hosed repository name>`:你nexus私服的npm(hosted)仓库名
- `<nexus username>`:你nexus私服的用户名(一般为admin管理员)
- `<nexus password>`:你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
```