Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dev-tools): add new modes to ocular-publish #461

Merged
merged 3 commits into from
Apr 24, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
dist/

.idea/
.nx/
yarn-error.log
.DS_Store
.vscode/
Expand Down
3 changes: 3 additions & 0 deletions modules/dev-tools/docs/cli/ocular-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ npx ocular-publish [mode] [npm-tag]

- `beta` - bump pre-release version and publish with beta flag.
- `prod` - bump patch version and publish.
- `version-only-beta` - bump pre-release version only.
- `version-only-prod` - bump patch version only.
- `from-git`: publish from the current git tag.
Pessimistress marked this conversation as resolved.
Show resolved Hide resolved

## npm-tag

Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.0.0",
"glob": "^7.1.4",
"lerna": "^3.14.1",
"lerna": "^8.1.0",
"minimatch": "^3.0.0",
"prettier": "3.0.3",
"prettier-check": "2.0.0",
Expand Down
144 changes: 73 additions & 71 deletions modules/dev-tools/scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,86 @@ usage() {
open "https://uber-web.github.io/ocular/docs/dev-tools/cli/ocular-publish"
}

BASEDIR=$(dirname "$0")
# beta, prod, version-only-beta, version-only-prod or from-git
MODE=$1

ocular-bootstrap
ocular-test
ocular-test dist
bumpVersion() {
local versionType
if [[ $1 == "beta" ]]; then
versionType=prerelease
else
versionType=patch
fi

# beta or prod
MODE=$1
# custom tag
TAG=$2
if [ -d "modules" ]; then
(set -x; npx lerna version $versionType --force-publish --exact --no-commit-hooks)
else
# -f includes any changes in the version commit
(set -x; npm version $versionType --force)
# push to branch
(set -x; git push && git push --tags)
fi
}

if [ -d "modules" ]; then
case $MODE in
"help")
usage
;;
publishToNPM() {
local tag=$1
if [ -d "modules" ]; then
if [ -z $tag ]; then
# use default tag ('latest' or publishConfig.tag in package.json)
(set -x; npx lerna publish from-git --force-publish --no-commit-hooks)
else
(set -x; npx lerna publish from-git --force-publish --dist-tag $tag --no-commit-hooks)
fi
else
if [ -z $tag ]; then
(set -x; npm publish)
else
(set -x; npm publish --tag $tag)
fi
fi
}

"beta")
# npm-tag argument: npm publish --tag <beta>
# cd-version argument: increase <prerelease> version
if [ -z "$TAG" ]
then
(set -x; lerna publish prerelease --force-publish --exact --dist-tag beta --no-commit-hooks)
else
(set -x; lerna publish prerelease --force-publish --exact --dist-tag $TAG --no-commit-hooks)
fi
;;
if [[ $MODE != "version-only-"* && $MODE != "help" ]]; then
# will build and publish to NPM
ocular-bootstrap
ocular-test
ocular-test dist
fi

"prod")
if [ -z "$TAG" ]
then
# latest
(set -x; lerna publish patch --force-publish --exact --no-commit-hooks)
else
(set -x; lerna publish patch --force-publish --exact --dist-tag $TAG --no-commit-hooks)
fi
;;
case $MODE in
"help")
usage
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta']\033[0m"
exit 1;;
esac
else
case $MODE in
"help")
usage
;;
"version-only-beta")
bumpVersion beta
;;

"beta")
# -f includes any changes in the version commit
(set -x; npm version prerelease --force)
# push to branch
(set -x; git push && git push --tags)
if [ -z "$TAG" ]
then
(set -x; npm publish --tag beta)
else
(set -x; npm publish --tag $TAG)
fi
;;
"version-only-prod")
bumpVersion prod
;;

"prod")
# -f includes any changes in the version commit
(set -x; npm version patch --force)
# push to branch
(set -x; git push && git push --tags)
"beta")
bumpVersion beta
publishToNPM ${2:-beta}
;;

if [ -z "$TAG" ]
then
# latest
(set -x; npm publish)
else
(set -x; npm publish --tag $TAG)
fi
;;
"prod")
bumpVersion beta
publishToNPM $2
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta']\033[0m"
exit 1;;
esac
fi
"from-git")
# publish from existing tag
gitTag=$(git describe)
if [[ $gitTag == *"-"* ]]; then
publishToNPM ${2:-beta}
else
publishToNPM $2
fi
;;

*)
echo -e "\033[91mUnknown publish mode. ocular-publish ['prod' | 'beta' | 'version-only-prod' | 'version-only-beta' | 'from-git']\033[0m"
exit 1;;
esac
Loading
Loading