Created
May 13, 2019 08:21
-
-
Save davidbarral/17f942ac22f4547acb049cca8f797222 to your computer and use it in GitHub Desktop.
Monorepo: new publish script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
REPO=$@ | |
publishable() { | |
export REPO | |
/usr/bin/env node <<'SCRIPT' | |
const { execSync } = require("child_process"); | |
const local = require("./package.json"); | |
try { | |
const info = execSync(`npm info ${local.name} --json ${process.env.REPO} 2> /dev/null`).toString(); | |
const remote = JSON.parse(info); | |
if (remote.versions.includes(local.version)) { | |
console.log(`[skip] ${local.name}@${local.version}`); | |
process.exit(1); | |
} else { | |
console.log(`[publish] ${local.name}@${local.version} (was ${remote.version})`); | |
process.exit(0); | |
} | |
} catch(e) { | |
console.log(`[publish] ${local.name}@${local.version} (new package)` ); | |
process.exit(0); | |
} | |
SCRIPT | |
} | |
publish() { | |
( | |
cd $1 | |
publishable && npm publish $REPO || echo -n "" | |
) | |
} | |
for i in ./packages/awesome-*; do publish $i; done |
Do you have to copy .npmrc
file from the root project to each leaf package before publishing?
I have tried and got the unauthorized error so many times until today I figure out that npm
does not read the .npmrc
file from the root project. The private registry I'm using is Verdaccio.
For us is enough to have an .npmrc in the root of the project. Our CI (Jenkins + Docker) setups this .npmrc file before publishing. We use Nexus as our private registry. Our customer CI (Bamboo) uses an .npmrc in the home folder. They use Artifactory.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should have mentioned that we call these script like this:
That's the reason why we do not put the
--registry
flag in the script.