Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active February 27, 2024 17:19
Show Gist options
  • Save huksley/0e681e12de92951c7c9d9e83d8e9dbd8 to your computer and use it in GitHub Desktop.
Save huksley/0e681e12de92951c7c9d9e83d8e9dbd8 to your computer and use it in GitHub Desktop.
#!/bin/bash
function zerodep() {
if [ -z "$1" ]; then
echo "Usage: zerodep <package>"
return
fi
F=node_modules/$1/package.json;
SRC=$(jq -r ".homepage" $F);
REPO=$(jq -r ".repository" $F);
if [ "$REPO" = "null" ]; then
REPO=$SRC
fi
# repo is github:org/repo
if [[ $REPO == "github:"* ]]; then
RTYPE="github"
REPO=$(echo $REPO | cut -d':' -f2-)
RURL="https://github.com/$REPO"
RNAME="GitHub"
elif [[ $REPO == "https://github.com/"* ]]; then
RTYPE="github"
RURL=$REPO
REPO=$(echo $REPO | cut -d'/' -f4-5)
RNAME="GitHub"
elif [[ $REPO == "{"* ]]; then
# repo is an object
URL=$(jq -r ".url" <<< $REPO)
if [[ $URL == *"github.com"* ]]; then
RTYPE="github"
REPO=$(echo $URL | cut -d'/' -f4-5 | cut -d'.' -f1)
RURL="https://github.com/$REPO"
RNAME="GitHub"
elif [[ $URL == *"gitlab.com"* ]]; then
RTYPE="gitlab"
REPO=$(echo $URL | cut -d'/' -f4-5 | cut -d'.' -f1)
RURL="https://gitlab.com/$REPO"
RNAME="GitLab"
elif [[ $URL == *"bitbucket.org"* ]]; then
RTYPE="bitbucket"
REPO=$(echo $URL | cut -d'/' -f4-5 | cut -d'.' -f1)
RURL="https://bitbucket.org/$REPO"
RNAME="BitBucket"
fi
elif [[ $REPO == "https://gitlab.com/"* ]]; then
RTYPE="gitlab"
RURL=$REPO
REPO=$(echo $REPO | cut -d'/' -f4-5)
RNAME="GitLab"
elif [[ $REPO == "https://bitbucket.org/"* ]]; then
RTYPE="bitbucket"
RURL=$REPO
REPO=$(echo $REPO | cut -d'/' -f4-5)
RNAME="BitBucket"
elif [[ $REPO == *"/$1" ]]; then
# probably a github repo
RTYPE="github"
RURL="https://github.com/$REPO"
RNAME="GitHub"
else
echo "No repo found for $1, repo link $REPO"
return
fi
echo "| summary | \`npm i $1\` | [$RNAME]($RURL) | [![https://img.shields.io/badge/npm/v/$1-blue](https://img.shields.io/npm/v/$1?label=$1)](https://npmjs.com/package/$1) | ![types](https://badgen.net/npm/types/$1) | [![dependencies](https://badgen.net/bundlephobia/dependency-count/$1?label=$1)](https://bundlephobia.com/package/$1) | [![last update](https://badgen.net/$RTYPE/last-commit/$REPO)]($RURL) |";
}
zerodep $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment