@tinymce/beehive-flow
Version:
A CLI tool implementing the beehive flow git branching process
67 lines • 3.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.release = void 0;
const tslib_1 = require("tslib");
const O = tslib_1.__importStar(require("fp-ts/Option"));
const yesno_1 = tslib_1.__importDefault(require("yesno"));
const Version = tslib_1.__importStar(require("../core/Version"));
const Git = tslib_1.__importStar(require("../utils/Git"));
const AdvanceVersion = tslib_1.__importStar(require("../core/AdvanceVersion"));
const PackageJson = tslib_1.__importStar(require("../core/PackageJson"));
const PromiseUtils = tslib_1.__importStar(require("../utils/PromiseUtils"));
const BranchLogic_1 = require("../core/BranchLogic");
const Changelog = tslib_1.__importStar(require("../keepachangelog/Changelog"));
const Messages_1 = require("../core/Messages");
const updateChangelog = async (git, version, module) => {
const changelogFile = module.changelogFile;
if (module.changelogFormat === 'keepachangelog') {
await Changelog.updateFromFile(changelogFile, version);
await git.add(changelogFile);
}
else {
console.log('No changelog file found');
}
};
const release = async (args) => {
(0, Messages_1.printHeaderMessage)(args);
// If we are releasing from the working directory, check for un-pushed local changes
if (O.isNone(args.gitUrl)) {
const hasLocalChanges = await Git.hasLocalChanges(args.workingDir, args.branchName);
if (hasLocalChanges) {
return PromiseUtils.fail('Local changes are ahead of origin. Commit and/or push local changes and try again.');
}
}
const gitUrl = await Git.resolveGitUrl(args.gitUrl, args.workingDir);
const { dir, git } = await Git.cloneInTempFolder(gitUrl, args.temp);
await Git.checkout(git, args.branchName);
const branchDetails = await (0, BranchLogic_1.getBranchDetails)(dir);
if (branchDetails.branchState !== "releaseCandidate" /* BranchState.ReleaseCandidate */) {
return PromiseUtils.fail('Branch is not in Release Candidate state - can\'t release.');
}
const rootModule = branchDetails.rootModule;
if (!args.allowPreReleaseDeps) {
await PackageJson.shouldNotHavePreReleasePackages(rootModule.packageJson);
}
const newVersion = AdvanceVersion.updateToStable(branchDetails.version);
console.log(`Updating version from ${Version.versionToString(branchDetails.version)} to ${Version.versionToString(newVersion)}`);
await PackageJson.writePackageJsonFileWithNewVersion(rootModule.packageJson, newVersion, rootModule.packageJsonFile);
if (!args.noChangelog) {
await updateChangelog(git, newVersion, rootModule);
}
await git.add(rootModule.packageJsonFile);
await git.commit('Branch is ready for release - setting release version');
if (!args.noDiff) {
console.log('Changes:');
const diff = await git.diff(['--color', 'HEAD~1']);
console.log(diff);
}
if (!args.yes) {
const kontinue = await (0, yesno_1.default)({ question: `Push changes and release ${Version.versionToString(newVersion)}? (Y/n)`, defaultValue: true });
if (!kontinue) {
throw new Error('Aborted!');
}
}
await Git.pushUnlessDryRun(dir, git, args.dryRun);
};
exports.release = release;
//# sourceMappingURL=Release.js.map