UNPKG

@tinymce/beehive-flow

Version:

A CLI tool implementing the beehive flow git branching process

50 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.revive = void 0; const tslib_1 = require("tslib"); const O = tslib_1.__importStar(require("fp-ts/Option")); const function_1 = require("fp-ts/function"); const BranchLogic_1 = require("../core/BranchLogic"); const AdvanceVersion = tslib_1.__importStar(require("../core/AdvanceVersion")); const Messages_1 = require("../core/Messages"); const Version = tslib_1.__importStar(require("../core/Version")); const ArrayUtils = tslib_1.__importStar(require("../utils/ArrayUtils")); const OptionUtils = tslib_1.__importStar(require("../utils/OptionUtils")); const PromiseUtils = tslib_1.__importStar(require("../utils/PromiseUtils")); const Git = tslib_1.__importStar(require("../utils/Git")); const getLatestTagForVersion = async (git, version) => { const tags = await Git.getTags(git); const tagDetails = OptionUtils.somes(tags.map((tag) => (0, function_1.pipe)(Version.parseVersionE(tag), O.fromEither, O.filter((v) => Version.compareMajorMinorVersions(v, version) === 0 /* Comparison.EQ */), O.map((v) => ({ version: v, name: tag }))))); const sortedDetails = ArrayUtils.sort(tagDetails, (td1, td2) => Version.compareVersions(td1.version, td2.version)); return PromiseUtils.optionToPromise(O.fromNullable(sortedDetails[sortedDetails.length - 1]), `Failed to find any tags matching version: ${Version.majorMinorVersionToString(version)}`); }; const revive = async (args) => { (0, Messages_1.printHeaderMessage)(args); const gitUrl = await Git.resolveGitUrl(args.gitUrl, args.workingDir); const { dir, git } = await Git.cloneInTempFolder(gitUrl, args.temp); // Verify the branch doesn't already exist await Git.branchShouldNotExist(git, args.branchName); // Verify we're not trying to setup the version for something that's in main const version = await (0, BranchLogic_1.versionFromReleaseBranch)(args.branchName); await Git.checkoutMainBranch(git); const mainBranchDetails = await (0, BranchLogic_1.getBranchDetails)(dir); if (Version.compareMajorMinorVersions(mainBranchDetails.version, version) === 0 /* Comparison.EQ */) { return PromiseUtils.fail(`main branch is still at version: ${Version.majorMinorVersionToString(version)}`); } // Find the latest git tag that matches the release branch to be created const latestTag = await getLatestTagForVersion(git, version); await Git.checkout(git, latestTag.name); // Rebuild the release branch from the tag const releaseBranchName = (0, BranchLogic_1.getReleaseBranchName)(latestTag.version); await (0, BranchLogic_1.createReleaseBranch)(releaseBranchName, git, dir); const branchDetails = await (0, BranchLogic_1.getBranchDetails)(dir); // Advance the version to the new patch release const rootModule = branchDetails.rootModule; await AdvanceVersion.advancePatch(latestTag.version, rootModule.packageJson, rootModule.packageJsonFile, git); await Git.pushUnlessDryRun(dir, git, args.dryRun); }; exports.revive = revive; //# sourceMappingURL=Revive.js.map