Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Publish
run: pnpm run pub
run: bash ./scripts/publish_npm_packages.sh smart-contracts niljs create-nil-hardhat-project
shell: bash
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"build": "pnpm --filter '!nil-monorepo' run build",
"lint": "pnpm --filter '!nil-monorepo' run lint",
"lint:fix": "pnpm --filter '!nil-monorepo' run lint:fix",
"pub": "pnpm --filter '!nil-monorepo' run pub",
"preinstall": "npx only-allow pnpm"
},
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ packages:
- "wallet-extension"
- "docs_ai_backend"
- "rollup-bridge-contracts"
- "academy/*"
- "academy/lending-protocol"
60 changes: 60 additions & 0 deletions scripts/publish_npm_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# This script publishes packages to npm registry making them publicly available.
# First it checks if the packages are already published, then it runs the publish command.
# It publishes only packages that have 'pub' script in their package.json file.
# Script accepts pnpm workspaces names as arguments. E.g. `./scripts/publish_npm_packages.sh my-workspace`

set -euo pipefail

COLOR_END="\033[0m"
COLOR_GREEN="\033[0;32m"
COLOR_YELLOW="\033[0;33m"

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
REPO_ROOT="$SCRIPT_DIR/.."

if ! command -v node >/dev/null 2>&1; then
echo "nodejs should be installed to run this script."
exit 1
fi

if ! command -v pnpm >/dev/null 2>&1; then
echo "pnpm should be installed to run this script."
exit 1
fi

if ! command -v jq &>/dev/null; then
echo "jq is not installed, please install it before running this script."
exit 1
fi

cd "$REPO_ROOT"

for package in "$@"; do
cd "$REPO_ROOT/$package"

PACKAGE_JSON="./package.json"

if [[ ! -f "$PACKAGE_JSON" ]]; then
echo "⚠️ No package.json found in $package, skipping..."
continue
fi

PACKAGE_NAME=$(jq -r '.name' "$PACKAGE_JSON")
LOCAL_VERSION=$(jq -r '.version' "$PACKAGE_JSON")

PUBLISHED_VERSION=$(pnpm show "$PACKAGE_NAME" version 2>/dev/null || echo "not_published")

if [[ "$PUBLISHED_VERSION" == "not_published" ]]; then
echo -e "🚀 Package ${COLOR_YELLOW}$PACKAGE_NAME${COLOR_END} is not published yet!"
elif [[ "$LOCAL_VERSION" == "$PUBLISHED_VERSION" ]]; then
echo -e "✅ Package ${COLOR_YELLOW}$PACKAGE_NAME${COLOR_END} is already published (version $LOCAL_VERSION)."
else
echo -e "🔄 Package ${COLOR_YELLOW}$PACKAGE_NAME${COLOR_END} has a new version ($LOCAL_VERSION) compared to npm ($PUBLISHED_VERSION)."

echo -e "${COLOR_YELLOW}Publishing $PACKAGE_NAME...${COLOR_END}"
pnpm run pub
echo -e "${COLOR_GREEN}Published ${COLOR_YELLOW}$PACKAGE_NAME${COLOR_END}"
fi
done