Skip to content

Instantly share code, notes, and snippets.

@evertonfraga
Created September 16, 2020 21:47
Show Gist options
  • Save evertonfraga/27a3b13786d49c41624639779e0317d5 to your computer and use it in GitHub Desktop.
Save evertonfraga/27a3b13786d49c41624639779e0317d5 to your computer and use it in GitHub Desktop.
Public package
Add the script directory to your $PATH environment variable.
Run:
`public-package`
print_help () {
cat << EOI
==============
Public package
==============
Usage: public-package [path]
Generates a gitpkg.now.sh URL, so you can install said package manually from
that URL, without needing to publish it to the NPM registry.
It needs to be run from the root of your repository.
Supports various git origins, meaning it will display URLs for both source and
forked repositories.
Normal usage:
$ public-package
> https://gitpkg.now.sh/ethereumjs/ethereumjs-devp2p?master
Nested package use (eg: monorepo):
$ public-package packages/lint
> https://gitpkg.now.sh/ethereumjs/ethereumjs-config/packages/lint?master
Options
path Relative path to the npm package
-h or --help Shows this help message.
Limitations:
- it does not check wether local branch is published remotely
- currently, it does not automatically builds the package, so no dist files.
EOI
exit 0
}
if [[ $1 = "-h" ]] || [[ $1 = "--help" ]]; then
print_help
fi
red() {
echo "\033[0;31m$1\033[0m"
}
# Target format:
# https://gitpkg.now.sh/ethereumjs/ethereumjs-config/packages/coverage?master
# 1. Get branch name
BRANCH=$(git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
if [ ! $BRANCH ]; then
red "You must be in a branch to get the correct package URL."
exit 1
fi
# 2. get all git origins
git_root () {
GIT_CONFIG=$(pwd)/.git/config
if [ -f $GIT_CONFIG ]; then
echo "$GIT_CONFIG"
else
red "It appears we're not in a git repo."
exit 2
fi
}
# 3. Get all git origins (source repo and possible forks)
REPO_NAME=$(cat $(git_root) | grep -Eo "github.com.+" | sed -E "s/(github.com:|.git)//g" )
# 4. [Optional] Get package path, if provided. Useful for monorepos.
PATH=$1
for ORIGIN in $REPO_NAME
do
echo "https://gitpkg.now.sh/$ORIGIN/$PATH?$BRANCH"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment