First upload
This commit is contained in:
13
README.md
Normal file
13
README.md
Normal file
@@ -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 <your-package>`.
|
||||||
|
|
||||||
|
## 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.
|
||||||
65
npm-install.sh
Executable file
65
npm-install.sh
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user