From dfcdcff04a94dcd618f09853edaf006c30db59fb Mon Sep 17 00:00:00 2001 From: Idan Cohen Date: Sun, 13 Mar 2022 09:23:34 +0200 Subject: [PATCH] feat: :sparkles: custom repository and download many packages --- npm-install.sh | 56 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/npm-install.sh b/npm-install.sh index e9685d4..7744d93 100755 --- a/npm-install.sh +++ b/npm-install.sh @@ -1,5 +1,17 @@ #!/bin/bash +print_help() { + echo -e + echo -e "For DOWNLOAD" + echo -e "$0 OR $0 ." + echo -e + echo -e "For UPLOAD" + echo -e "$0 " + echo -e "Like this:" + echo -e "/service/rest/v1/components?repository=" + echo -e +} + npm_cretae_package_lock_file() { if [[ $# > 0 ]]; then local package=$1 @@ -12,9 +24,20 @@ download_package() { wget $url_package } -npm_publish_package() { - local package_filename=$1 - npm publish $package_filename +# npm_publish_package() { +# local package_filename=$1 +# npm publish $package_filename +# } + +# insert nexus_host, repository and package to upload +upload_package() { + local nexus_host=$1 + local repository=$2 + local package=$3 + curl -X POST "$nexus_host/service/rest/v1/components?repository=$repository" \ + -H "accept: application/json" \ + -H "Content-Type: multipart/form-data" \ + -F "npm.asset=@$package" -i } get_all_packages_urls() { @@ -33,13 +56,12 @@ publish_all_packages() { local packages_filenames=($(ls *.tgz)) for package_name in ${packages_filenames[@]}; do - npm_publish_package $package_name + upload_package $@ $package_name done } remove_all_local_packages_and_json() { - rm *.tgz - rm *.json + rm *.tgz *.json } echo_npm_registry() { @@ -47,19 +69,17 @@ echo_npm_registry() { } -if [[ -n $(ls *.tgz) ]]; then - echo "NPM Registry is $(echo_npm_registry)" - echo "Are you sure you want publish to this registry?[y/n]:" - read -n 1 ans - if [[ ${ans^^} == "Y" ]]; then - publish_all_packages - remove_all_local_packages_and_json - fi -else - if npm_cretae_package_lock_file $1; then +main() { + if [[ $# -eq 1 ]]; then + npm_cretae_package_lock_file $@ urls_packages=($(get_all_packages_urls)) download_all_package ${urls_packages[@]} - else + elif [[ $# -eq 2 ]]; then + publish_all_packages $@ remove_all_local_packages_and_json + else + print_help fi -fi +} + +main $@