diff --git a/Tasks/qlrepo/extra.sh b/Tasks/qlrepo/extra.sh index db795d8..546d413 100644 --- a/Tasks/qlrepo/extra.sh +++ b/Tasks/qlrepo/extra.sh @@ -110,15 +110,71 @@ ql repo https://github.com/Wenmoux/scripts.git "chinnkarahoi_jd_bookshop" "" "" # 依赖 -install_dependencies(){ -## Python 3 安装 requests -pip3 install requests -## 安装 canvas,适用于柠檬胖虎代维护 lxk0301 仓库,宠汪汪二代目和宠汪汪兑换,只支持国内机 -apk add --no-cache build-base g++ cairo-dev pango-dev giflib-dev && cd scripts && npm install canvas --build-from-source -## 安装 png-js,适用于 JDHelloWorld 和 he1pu 的宠汪汪二代目和宠汪汪兑奖品二代目 -npm install png-js -S -## 安装 date-fns axios crypto-js ts-md5 tslib @types/node ,用于解决新版惊喜财富岛依赖问题 -npm i -S date-fns axios crypto-js ts-md5 tslib @types/node dotenv +package_name="canvas png-js date-fns axios crypto-js ts-md5 tslib @types/node dotenv" + +install_dependencies_normal(){ + for i in $@; do + case $i in + canvas) + if [[ "$(npm ls $i)" =~ (empty) ]]; then + apk add --no-cache build-base g++ cairo-dev pango-dev giflib-dev && npm install $i --build-from-source + fi + ;; + *) + if [[ "$(npm ls $i -g)" =~ (empty) ]]; then + if [[ "$(npm ls $i)" =~ $i ]]; then + npm uninstall $i + fi + npm i $i -g + fi + ;; + esac + done } -install_dependencies & +install_dependencies_force(){ + for i in $@; do + if [[ "$(npm ls $i)" =~ $i ]]; then + npm uninstall $i + rm -rf /ql/scripts/node_modules/$i + rm -rf /ql/scripts/node_modules/lodash + elif [[ "$(npm ls $i -g)" =~ $i ]]; then + npm uninstall -g $i + rm -rf /usr/local/lib/node_modules/$i + rm -rf /usr/local/lib/node_modules/lodash + fi + case $i in + canvas) + if [[ "$(npm ls $i)" =~ (empty) ]]; then + apk add --no-cache build-base g++ cairo-dev pango-dev giflib-dev && npm install $i --build-from-source + fi + ;; + *) + if [[ "$(npm ls $i -g)" =~ (empty) ]]; then + if [[ "$(npm ls $i)" =~ $i ]]; then + npm uninstall $i + fi + npm i $i -g + fi + ;; + esac + done +} + +install_dependencies_all(){ + install_dependencies_normal $package_name + for i in $package_name; do + if [[ "$(npm ls $i -g)" =~ (empty) ]] && [[ "$(npm ls $i)" =~ (empty) ]]; then + install_dependencies_force $i + fi + done +} + +install_dependencies_all & + +:<