Skip to content

Commit

Permalink
feat(dev-tools): add new modes to ocular-publish (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress committed Apr 24, 2024
1 parent 2ff6a7f commit 964bc6c
Show file tree
Hide file tree
Showing 5 changed files with 2,279 additions and 3,568 deletions.
1 change: 1 addition & 0 deletions .gitignore
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
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.

## npm-tag

Expand Down
2 changes: 1 addition & 1 deletion modules/dev-tools/package.json
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
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

0 comments on commit 964bc6c

Please sign in to comment.