Skip to content

Instantly share code, notes, and snippets.

@nhhockeyplayer
Last active August 5, 2022 11:46
Show Gist options
  • Save nhhockeyplayer/4a96e273aaee70f95792637bb5dc2802 to your computer and use it in GitHub Desktop.
Save nhhockeyplayer/4a96e273aaee70f95792637bb5dc2802 to your computer and use it in GitHub Desktop.
sh-deploy-all-nrwl-nx-libs-from-root-dist-folder.sh
#!/bin/bash
ROOT_DIR=$(pwd)
cd "$ROOT_DIR/dist/libs"
recurseAndDeploy() {
if [[ -f package.json ]]; # target case, unwind
then
npm publish --registry https://registry.npmjs.org --no-git-tag-version --no-push --yes
return;
else
for LIBRARY in */; do
cd $LIBRARY;
echo PUBLISHING "$LIBRARY"
recurseAndDeploy; # recursion
cd ..
done
fi
}
for DIR in */; do
recurseAndDeploy; # recursion
done
cd ..
cd ..
@nhhockeyplayer
Copy link
Author

nhhockeyplayer commented Aug 5, 2022

say you have 50 libs you want to deploy in one sweep

If you have a @nrwl/nx monorepo, this gist will function from your root dir and navigate into your dist folder and traverse all child directories in your libs folder publishing every library it encounters where a libary's resident package.json lives

this is one way to deploy ALL nx libs to your registry in one hit/sweep

this gist could be rigged in a scripts folder under tools and triggered from a custom deploy task within your project

        "deploy": {
            "executor": "@nrwl/workspace:run-script",
            "options": {
                "script": "sh-deploy-all-nrwl-nx-libs-from-root-dist-folder.sh"
            }
        }

OR
it could be run as a root package.json npm script
"deploy": "source ./tools/scripts/deploy.sh",

use at your own discretion

terminal cmd line usage is as follows

      `source ./sh-deploy-all-nrwl-nx-libs-from-root-dist-folder.sh`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment