monorepo-publish
Version:
Publishes a monorepo.
37 lines (36 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tmp = require("tmp");
const exec_1 = require("./util/exec");
const monorepo_build_1 = require("monorepo-build");
const path = require("path");
const fs = require("fs-extra");
const Debug = require("debug");
const debug = Debug('monorepo-publish');
function publish(cloneUrl, sha, { tagname = 'contrib', userName = undefined, userEmail = undefined, packagesDirectory = './packages/', exclude = [], preRepkg = function (cwd) { }, postRepkg = function (cwd) { }, prePublish = function (cwd) { }, postPublish = function (cwd) { }, npmToken = null, lernaPath = './node_modules/.bin/lerna', } = {}) {
const { name: cwd } = tmp.dirSync();
const packages = monorepo_build_1.build(cwd, cloneUrl, sha, {
userName,
userEmail,
packagesDirectory,
exclude,
preRepkg,
postRepkg,
});
debug('calling prePublish ...');
prePublish(cwd);
debug('(ok)');
if (npmToken != null) {
for (const { name, directory } of packages) {
debug(`creating .npmrc for ${name} ...`);
fs.writeFileSync(path.join(directory, '.npmrc'), `//registry.npmjs.org/:_authToken=${npmToken}`);
}
}
debug('publishing ...');
exec_1.execSync(cwd, `${lernaPath} publish --independent --exact --force-publish=* --cd-version=prepatch --preid=${sha.slice(0, 7)} --yes --skip-git --npm-tag=${tagname}`);
debug('(ok)');
debug('calling postPublish ...');
postPublish(cwd);
debug('(ok)');
}
exports.publish = publish;