问题说明:公司前端使用Verdaccio 作为私有仓库,但是存在上传包失败的情况。后面查看Verdaccio 配置信息,找到Verdaccio存储包的文件夹storage,直接将本地所有依赖包复制到仓库文件夹,重启服务后页面不能搜索手动复制的npm包,后面查资料才发现包的信息存在storage/.verdaccio-db.json文件中。将新增的包信息添加到配置文件的list列表中后,重启服务发现可以搜索了。 考虑到包文件实在太多,后面写了个脚本直接扫描所有包并创建.verdaccio-db.json文件 以下是脚本内容:
#!/bin/bash
if [ -z $1 ]
then
echo "请输入Verdaccio仓库路径"
exit
fi
currentPath=`pwd`
if [ -e ${currentPath}/npmFile.txt ]
then
rm -f ${currentPath}/npmFile.txt
fi
cd $1
echo "当前路径`pwd`"
allNpm=`ls $1`
for npm in ${allNpm}
do
echo "文件夹名称:${npm}"
cd $1/${npm}
if [ -e package.json ]
then
echo "${npm}" >> ${currentPath}/npmFile.txt
cd $1
else
cd $1
subFile=`ls $1/${npm}`
for subNpm in ${subFile}
do
echo "子文件夹:${subNpm}"
cd $1/${npm}/${subNpm}
if [ -e package.json ]
then
echo "${npm}/${subNpm}" >> ${currentPath}/npmFile.txt
cd $1
fi
done
fi
done
cd ${currentPath}
echo "处理内容路径${currentPath}"
if [ -e ${currentPath}/.verdaccio.json ]
then
rm -f ${currentPath}/.verdaccio.json
fi
echo "{\"list\":[" >> ${currentPath}/.verdaccio.json
t=`cat ${currentPath}/npmFile.txt|wc -l`
n=0
cat ${currentPath}/npmFile.txt |while read line
do
n=`expr $n + 1`
if [ $n -eq $t ]
then
echo "\"${line}\"" >> ${currentPath}/.verdaccio.json
else
echo "\"${line}\"," >> ${currentPath}/.verdaccio.json
fi
done
echo "],\"secret\":\"需要替换为本机的secret,可从stroge/.verdaccio-db.json文件中查询\"}" >> ${currentPath}/.verdaccio.json
if [ -e .verdaccio-db.json.backup ]
then
rm -f ${currentPath}/storage/.verdaccio-db.json.backup
fi
cp ${currentPath}/storage/.verdaccio-db.json ${currentPath}/storage/.verdaccio-db.json.backup
cp ${currentPath}/.verdaccio.json ${currentPath}/storage/.verdaccio-db.json