@auto-canary/git-tag
Version:
Manage your projects version through just a git tag
59 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@auto-it/core");
const semver_1 = require("semver");
const child_process_1 = require("child_process");
/** When the next hook is running branch is also the tag to publish under (ex: next, beta) */
const branch = child_process_1.execSync('git symbolic-ref --short HEAD', { encoding: 'utf8' });
/** Manage your projects version through just a git tag. */
class GitTagPlugin {
constructor() {
/** The name of the plugin */
this.name = 'Git Tag';
}
/** Tap into auto plugin points. */
apply(auto) {
auto.hooks.getPreviousVersion.tapPromise(this.name, async () => {
if (!auto.git) {
throw new Error("Can't calculate previous version without Git initialized!");
}
return auto.git.getLatestTagInBranch();
});
auto.hooks.version.tapPromise(this.name, async (version) => {
if (!auto.git) {
return;
}
const lastTag = await auto.git.getLatestTagInBranch();
const newTag = semver_1.inc(lastTag, version);
if (!newTag) {
return;
}
await core_1.execPromise('git', ['tag', newTag]);
await core_1.execPromise('git', [
'push',
'--follow-tags',
'--set-upstream',
'origin',
auto.baseBranch
]);
});
auto.hooks.next.tapPromise(this.name, async (preReleaseVersions, bump) => {
var _a;
if (!auto.git) {
return preReleaseVersions;
}
const prereleaseBranches = (_a = auto.config) === null || _a === void 0 ? void 0 : _a.prereleaseBranches;
const prereleaseBranch = prereleaseBranches.includes(branch)
? branch
: prereleaseBranches[0];
const lastRelease = await auto.git.getLatestRelease();
const current = await auto.getCurrentVersion(lastRelease);
const prerelease = core_1.determineNextVersion(lastRelease, current, bump, prereleaseBranch);
await core_1.execPromise('git', ['tag', prerelease]);
await core_1.execPromise('git', ['push', '--tags']);
return preReleaseVersions;
});
}
}
exports.default = GitTagPlugin;
//# sourceMappingURL=index.js.map