commit 2d3525a988390938d50482f8aa88eb69722f096f Author: Idan Cohen Date: Thu Feb 10 16:10:08 2022 +0200 First upload diff --git a/README.md b/README.md new file mode 100644 index 0000000..598c022 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Usage + +# Download +### package.json +1. Put in the folder `package.json` file. +2. Run `./npm-install`. +### Specific Package +1. Run `./npm-install `. + +## Publish +1. Make sure have the all package you will publish in the same folder (`tgz` files). +2. Run `./npm-install`. +3. After published, the all packages and json file will remove. diff --git a/npm-install.sh b/npm-install.sh new file mode 100755 index 0000000..e9685d4 --- /dev/null +++ b/npm-install.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +npm_cretae_package_lock_file() { + if [[ $# > 0 ]]; then + local package=$1 + fi + npm i --package-lock-only $package +} + +download_package() { + local url_package=$1 + wget $url_package +} + +npm_publish_package() { + local package_filename=$1 + npm publish $package_filename +} + +get_all_packages_urls() { + echo $(grep -Eo "https://.+(.tgz)" package-lock.json | sort | uniq) +} + +download_all_package() { + local urls_packages=$@ + for url_package in ${urls_packages[@]}; + do + download_package $url_package + done +} + +publish_all_packages() { + local packages_filenames=($(ls *.tgz)) + for package_name in ${packages_filenames[@]}; + do + npm_publish_package $package_name + done +} + +remove_all_local_packages_and_json() { + rm *.tgz + rm *.json +} + +echo_npm_registry() { + npm get 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 + urls_packages=($(get_all_packages_urls)) + download_all_package ${urls_packages[@]} + else + remove_all_local_packages_and_json + fi +fi