Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
apply(auto: Auto) {
const isVerbose =
auto.logger.logLevel === 'verbose' ||
auto.logger.logLevel === 'veryVerbose';
const verboseArgs = isVerbose ? verbose : [];
const prereleaseBranches = auto.config?.prereleaseBranches!;
const branch = getCurrentBranch();
// if ran from master we publish the prerelease to the first
// configured prerelease branch
const prereleaseBranch =
branch && prereleaseBranches.includes(branch)
? branch
: prereleaseBranches[0];
auto.hooks.beforeShipIt.tap(this.name, async () => {
if (!isCi) {
return;
}
auto.checkEnv(this.name, 'NPM_TOKEN');
});
auto.hooks.getAuthor.tapPromise(this.name, async () => {
auto.hooks.next.tapPromise(this.name, async (preReleaseVersions, bump) => {
if (!auto.git) {
return preReleaseVersions;
}
const prereleaseBranches = auto.config?.prereleaseBranches!;
const branch = getCurrentBranch() || '';
const prereleaseBranch = prereleaseBranches.includes(branch)
? branch
: prereleaseBranches[0];
const lastRelease = await auto.git.getLatestRelease();
const current =
(await auto.git.getLastTagNotInBaseBranch(prereleaseBranch)) ||
(await auto.getCurrentVersion(lastRelease));
const prerelease = determineNextVersion(
lastRelease,
current,
bump,
prereleaseBranch
);
await execPromise('git', ['tag', prerelease]);
await execPromise('git', ['push', '--tags']);
auto.hooks.version.tapPromise(this.name, async version => {
if (!auto.git) {
return;
}
const lastTag = await auto.git.getLatestTagInBranch();
const newTag = inc(lastTag, version as ReleaseType);
const branch = getCurrentBranch() || '';
if (!newTag) {
return;
}
await execPromise('git', ['tag', newTag]);
await execPromise('git', [
'push',
'--follow-tags',
'--set-upstream',
'origin',
branch || auto.baseBranch
]);
});