Skip to content

Commit

Permalink
feat(repo): add --local to release and publish script (#2323)
Browse files Browse the repository at this point in the history
This allows for easier publishing to a local npm registry (i.e. Verdaccio)
  • Loading branch information
juristr authored and FrozenPandaz committed Jan 20, 2020
1 parent 121d070 commit 7729879
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
16 changes: 11 additions & 5 deletions scripts/nx-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ const fs = require('fs');
const path = require('path');

const parsedArgs = yargsParser(process.argv, {
boolean: ['dry-run', 'nobazel'],
boolean: ['dry-run', 'nobazel', 'local'],
alias: {
d: 'dry-run',
h: 'help'
h: 'help',
l: 'local'
}
});

console.log('parsedArgs', parsedArgs);

if (!process.env.GITHUB_TOKEN_RELEASE_IT_NX) {
if (!parsedArgs.local && !process.env.GITHUB_TOKEN_RELEASE_IT_NX) {
console.error('process.env.GITHUB_TOKEN_RELEASE_IT_NX is not set');
process.exit(1);
}
Expand All @@ -35,6 +36,7 @@ if (parsedArgs.help) {
Options:
--dry-run Do not touch or write anything, but show the commands
--help Show this message
--local Publish to local npm registry (IMPORTANT: install & run Verdaccio first & set registry in .npmrc)
`);
process.exit(0);
Expand Down Expand Up @@ -174,7 +176,9 @@ const options = {
* The environment variable containing a valid GitHub
* auth token with "repo" access (no other permissions required)
*/
token: process.env.GITHUB_TOKEN_RELEASE_IT_NX
token: !parsedArgs.local
? process.env.GITHUB_TOKEN_RELEASE_IT_NX
: 'dummy-gh-token'
},
npm: {
/**
Expand Down Expand Up @@ -203,7 +207,9 @@ releaseIt(options)
* We always use either "latest" or "next" (i.e. no separate tags for alpha, beta etc)
*/
const npmTag = parsedVersion.isPrerelease ? 'next' : 'latest';
const npmPublishCommand = `./scripts/publish.sh ${output.version} ${npmTag}`;
const npmPublishCommand = `./scripts/publish.sh ${
output.version
} ${npmTag} ${parsedArgs.local ? '--local' : ''}`;
console.log('Executing publishing script for all packages:');
console.log(`> ${npmPublishCommand}`);
console.log(
Expand Down
29 changes: 28 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@

VERSION=$1
TAG=$2
LOCALBUILD=$3
PACKAGE_SOURCE=build/packages
NPM_DEST=build/npm
ORIG_DIRECTORY=`pwd`
NPM_REGISTRY=`npm config get registry` # for local releases

# We are running inside of a child_process, so we need to reauth
npm adduser

if [ "$LOCALBUILD" = "--local" ]; then
echo
echo "Publishing to npm registry $NPM_REGISTRY"

if [[ ! $NPM_REGISTRY == http://localhost* ]]; then
echo "------------------"
echo "💣 WARNING 💣 => $NPM_REGISTRY does not look like a local registry!"
echo "You may want to set registry with 'npm config set registry ...'"
echo "------------------"
fi

read -p "Continue? (y/n)" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
else
echo "Publishing to public npm"
fi

for package in $NPM_DEST/*/
do

Expand All @@ -21,7 +43,12 @@ do
PACKAGE_NAME=`node -e "console.log(require('./package.json').name)"`

echo "Publishing ${PACKAGE_NAME}@${VERSION} --tag ${TAG}"
npm publish --tag $TAG --access public

if [ "$LOCALBUILD" = "--local" ]; then
npm publish --tag $TAG --access public --registry=NPM_REGISTRY
else
npm publish --tag $TAG --access public
fi

cd $ORIG_DIRECTORY
done
Expand Down

0 comments on commit 7729879

Please sign in to comment.