@tinymce/beehive-flow
Version:
A CLI tool implementing the beehive flow git branching process
92 lines • 4.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.publish = void 0;
const tslib_1 = require("tslib");
const cross_spawn_promise_1 = tslib_1.__importDefault(require("cross-spawn-promise"));
const simple_git_1 = require("simple-git");
const BranchLogic_1 = require("../core/BranchLogic");
const NpmTags = tslib_1.__importStar(require("../core/NpmTags"));
const Version = tslib_1.__importStar(require("../core/Version"));
const Changelog = tslib_1.__importStar(require("../keepachangelog/Changelog"));
const PromiseUtils = tslib_1.__importStar(require("../utils/PromiseUtils"));
const Git = tslib_1.__importStar(require("../utils/Git"));
const Messages_1 = require("../core/Messages");
const publish = async (args) => {
(0, Messages_1.printHeaderMessage)(args);
const dir = args.workingDir;
const git = (0, simple_git_1.gitP)(dir);
const r = await (0, BranchLogic_1.getBranchDetails)(dir);
await checkVersion(r.version, r.rootModule);
const tags = await NpmTags.pickTagsNpm(r.currentBranch, r.branchState, r.version, dir, r.rootModule.packageJson.name);
const [mainTag] = tags;
const dryRunArgs = args.dryRun ? ['--dry-run'] : [];
await npmPublish(mainTag, dryRunArgs, args.workingDir, args.distDir);
await npmTag(args, tags, r, args.workingDir);
await gitTag(r, git, args);
};
exports.publish = publish;
const checkVersion = async (version, module) => {
if (module.changelogFormat === 'keepachangelog') {
await Changelog.checkVersionFromFile(module.changelogFile, version);
}
};
const npmPublish = async (mainTag, dryRunArgs, dir, distDir) => {
const publishCmd = ['publish', distDir, '--tag', mainTag, ...dryRunArgs];
console.log(['npm', ...publishCmd].join(' '));
await (0, cross_spawn_promise_1.default)('npm', publishCmd, { stdio: 'inherit', cwd: dir });
};
const npmTag = async (args, tags, r, dir) => {
/*
Yes, we're setting the mainTag again in this loop.
If this is the very first publish of a package, the --tag above is ignored
and "latest" is used. At least on Verdaccio - need to test other NPM registries.
Even if the extra dist-tag call is not required, it doesn't hurt.
*/
if (args.dryRun) {
console.log('dry run - not tagging');
console.log('Would have added tags: ', tags);
}
else {
console.log('Setting NPM tags.');
console.log('This will likely fail a few times, until the package is available in the registry - this is normal.');
for (const t of tags) {
const fullPackageName = r.rootModule.packageJson.name + '@' + Version.versionToString(r.version);
const tagCmd = ['dist-tag', 'add', fullPackageName, t];
console.log(['npm', ...tagCmd].join(' '));
/*
NPM registries can have a delay after publishing before the package is available.
If we try and set other tags too early, it'll fail.
So, retry for a while.
A 60s timeout was recommended by CloudSmith support. Using 30s for now - might need to increase later.
In initial testing, CloudSmith packages seemed to be ok after about 4s.
A side effect of this is that after `beehive-flow publish` is run, we can be sure the package is available
*/
await PromiseUtils.poll(() => (0, cross_spawn_promise_1.default)('npm', tagCmd, { stdio: 'inherit', cwd: dir }), 30000, 3000);
}
}
};
const gitTag = async (r, git, args) => {
if (r.branchState === "releaseReady" /* BranchState.ReleaseReady */) {
// TODO TINY-6994: Implement tagging logic:
/*
Tag X.Y.Z for the primary module in a repo.
In a single-module repo this will be the one and only module.
For a multi-project repos this might be the root module (which might not be published) or a special project.
Tag package@X.Y.Z for all modules other than the primary.
*/
// const tagName = r.packageJson.name + '@' + Version.versionToString(r.version);
const tagName = Version.versionToString(r.version);
console.log(`Tagging as ${tagName}`);
await git.addTag(tagName);
if (args.dryRun) {
console.log('Dry run - not pushing tags');
}
else {
await Git.pushOneTag(git, tagName);
}
}
else {
console.log('Not release ready - not git tagging.');
}
};
//# sourceMappingURL=Publish.js.map