feat: ✨ custom repository and download many packages
This commit is contained in:
@@ -1,5 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
print_help() {
|
||||||
|
echo -e
|
||||||
|
echo -e "For DOWNLOAD"
|
||||||
|
echo -e "$0 <package> OR $0 ."
|
||||||
|
echo -e
|
||||||
|
echo -e "For UPLOAD"
|
||||||
|
echo -e "$0 <nexus_host> <repository>"
|
||||||
|
echo -e "Like this:"
|
||||||
|
echo -e "<nexus_host>/service/rest/v1/components?repository=<repository>"
|
||||||
|
echo -e
|
||||||
|
}
|
||||||
|
|
||||||
npm_cretae_package_lock_file() {
|
npm_cretae_package_lock_file() {
|
||||||
if [[ $# > 0 ]]; then
|
if [[ $# > 0 ]]; then
|
||||||
local package=$1
|
local package=$1
|
||||||
@@ -12,9 +24,20 @@ download_package() {
|
|||||||
wget $url_package
|
wget $url_package
|
||||||
}
|
}
|
||||||
|
|
||||||
npm_publish_package() {
|
# npm_publish_package() {
|
||||||
local package_filename=$1
|
# local package_filename=$1
|
||||||
npm publish $package_filename
|
# 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() {
|
get_all_packages_urls() {
|
||||||
@@ -33,13 +56,12 @@ publish_all_packages() {
|
|||||||
local packages_filenames=($(ls *.tgz))
|
local packages_filenames=($(ls *.tgz))
|
||||||
for package_name in ${packages_filenames[@]};
|
for package_name in ${packages_filenames[@]};
|
||||||
do
|
do
|
||||||
npm_publish_package $package_name
|
upload_package $@ $package_name
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_all_local_packages_and_json() {
|
remove_all_local_packages_and_json() {
|
||||||
rm *.tgz
|
rm *.tgz *.json
|
||||||
rm *.json
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo_npm_registry() {
|
echo_npm_registry() {
|
||||||
@@ -47,19 +69,17 @@ echo_npm_registry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ -n $(ls *.tgz) ]]; then
|
main() {
|
||||||
echo "NPM Registry is $(echo_npm_registry)"
|
if [[ $# -eq 1 ]]; then
|
||||||
echo "Are you sure you want publish to this registry?[y/n]:"
|
npm_cretae_package_lock_file $@
|
||||||
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
|
|
||||||
urls_packages=($(get_all_packages_urls))
|
urls_packages=($(get_all_packages_urls))
|
||||||
download_all_package ${urls_packages[@]}
|
download_all_package ${urls_packages[@]}
|
||||||
else
|
elif [[ $# -eq 2 ]]; then
|
||||||
|
publish_all_packages $@
|
||||||
remove_all_local_packages_and_json
|
remove_all_local_packages_and_json
|
||||||
|
else
|
||||||
|
print_help
|
||||||
fi
|
fi
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
main $@
|
||||||
|
|||||||
Reference in New Issue
Block a user