diff --git a/package.json b/package.json index fd6fdc1..88a7d55 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "test": "forge test", "version:bump": "yarn workspace @zk-kit/${0}.sol version ${1} && yarn remove:stable-version-field ${0} && NO_HOOK=1 git commit -am \"chore(${0}): v${1}\" && git tag ${0}.sol-v${1}", - "version:publish": "yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public", + "version:publish": "scripts/publish.sh", "version:release": "changelogithub", "format": "prettier -c . && forge fmt --check", "format:write": "prettier -w . && forge fmt", diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..564920d --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +set -eu + +publish_npm() { + yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public +} + +clean_root() { + pkg="$1" + exclude_regex="\./\.git\|\./packages\|\./\|\./packages/$pkg\|\./LICENSE" + find . -maxdepth 1 -not -regex "$exclude_regex" -exec rm -rf {} + +} + +publish_forge_pkg() { + pkg="$1" + version=$(jq -r '.version' "packages/$pkg/package.json") + + clean_root "$pkg" + mv "packages/$pkg/{src,README.md}" . + rm -fr "packages/$pkg" + + git checkout -b "$package" + git commit -am "$version" + git push origin "$package" +} + +main() { + pkg="$1" + clean_root "$pkg" + publish_forge + publish_npm +} + +main "$@"