mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-14 03:04:46 +00:00
feat(cli): add standalone CLI tool for semantic versioning
This commit is contained in:
parent
bdf7908364
commit
726912b971
55 changed files with 2305 additions and 2850 deletions
|
|
@ -1,25 +1,37 @@
|
|||
import { ConfigurationProvider } from './ConfigurationProvider';
|
||||
import { VersionResult } from './VersionResult';
|
||||
import { VersionType } from './providers/VersionType';
|
||||
import { UserInfo } from './providers/UserInfo';
|
||||
import { VersionInformation } from './providers/VersionInformation';
|
||||
import { DebugManager } from './DebugManager';
|
||||
import { ConfigurationProvider } from "./ConfigurationProvider";
|
||||
import { VersionResult } from "./VersionResult";
|
||||
import { VersionType } from "./providers/VersionType";
|
||||
import { UserInfo } from "./providers/UserInfo";
|
||||
import { VersionInformation } from "./providers/VersionInformation";
|
||||
import { DebugManager } from "./DebugManager";
|
||||
|
||||
export async function runAction(configurationProvider: ConfigurationProvider): Promise<VersionResult> {
|
||||
|
||||
const currentCommitResolver = configurationProvider.GetCurrentCommitResolver();
|
||||
export async function runAction(
|
||||
configurationProvider: ConfigurationProvider,
|
||||
): Promise<VersionResult> {
|
||||
const currentCommitResolver =
|
||||
configurationProvider.GetCurrentCommitResolver();
|
||||
const lastReleaseResolver = configurationProvider.GetLastReleaseResolver();
|
||||
const commitsProvider = configurationProvider.GetCommitsProvider();
|
||||
const versionClassifier = configurationProvider.GetVersionClassifier();
|
||||
const versionFormatter = configurationProvider.GetVersionFormatter();
|
||||
const tagFormatter = configurationProvider.GetTagFormatter(await currentCommitResolver.ResolveBranchNameAsync());
|
||||
const tagFormatter = configurationProvider.GetTagFormatter(
|
||||
await currentCommitResolver.ResolveBranchNameAsync(),
|
||||
);
|
||||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
|
||||
const debugManager = DebugManager.getInstance();
|
||||
|
||||
if (await currentCommitResolver.IsEmptyRepoAsync()) {
|
||||
|
||||
const versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false, false);
|
||||
const versionInfo = new VersionInformation(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
VersionType.None,
|
||||
[],
|
||||
false,
|
||||
false,
|
||||
);
|
||||
return new VersionResult(
|
||||
versionInfo.major,
|
||||
versionInfo.minor,
|
||||
|
|
@ -30,34 +42,51 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
|
|||
tagFormatter.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
versionInfo.isTagged,
|
||||
userFormatter.Format('author', []),
|
||||
'',
|
||||
'',
|
||||
tagFormatter.Parse(tagFormatter.Format(versionInfo)).join('.'),
|
||||
debugManager.getDebugOutput(true)
|
||||
userFormatter.Format("author", []),
|
||||
"",
|
||||
"",
|
||||
tagFormatter.Parse(tagFormatter.Format(versionInfo)).join("."),
|
||||
debugManager.getDebugOutput(true),
|
||||
);
|
||||
}
|
||||
|
||||
const currentCommit = await currentCommitResolver.ResolveAsync();
|
||||
const lastRelease = await lastReleaseResolver.ResolveAsync(currentCommit, tagFormatter);
|
||||
const commitSet = await commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
|
||||
const classification = await versionClassifier.ClassifyAsync(lastRelease, commitSet);
|
||||
const lastRelease = await lastReleaseResolver.ResolveAsync(
|
||||
currentCommit,
|
||||
tagFormatter,
|
||||
);
|
||||
const commitSet = await commitsProvider.GetCommitsAsync(
|
||||
lastRelease.hash,
|
||||
currentCommit,
|
||||
);
|
||||
const classification = await versionClassifier.ClassifyAsync(
|
||||
lastRelease,
|
||||
commitSet,
|
||||
);
|
||||
|
||||
const { isTagged } = lastRelease;
|
||||
const { major, minor, patch, increment, type, changed } = classification;
|
||||
|
||||
// At this point all necessary data has been pulled from the database, create
|
||||
// version information to be used by the formatters
|
||||
let versionInfo = new VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed, isTagged);
|
||||
let versionInfo = new VersionInformation(
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
increment,
|
||||
type,
|
||||
commitSet.commits,
|
||||
changed,
|
||||
isTagged,
|
||||
);
|
||||
|
||||
// Group all the authors together, count the number of commits per author
|
||||
const allAuthors = versionInfo.commits
|
||||
.reduce((acc: any, commit) => {
|
||||
const key = `${commit.author} <${commit.authorEmail}>`;
|
||||
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
|
||||
acc[key].c++;
|
||||
return acc;
|
||||
}, {});
|
||||
const allAuthors = versionInfo.commits.reduce((acc: any, commit) => {
|
||||
const key = `${commit.author} <${commit.authorEmail}>`;
|
||||
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
|
||||
acc[key].c++;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const authors = Object.values(allAuthors)
|
||||
.map((u: any) => new UserInfo(u.n, u.e, u.c))
|
||||
|
|
@ -73,10 +102,10 @@ export async function runAction(configurationProvider: ConfigurationProvider): P
|
|||
tagFormatter.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
versionInfo.isTagged,
|
||||
userFormatter.Format('author', authors),
|
||||
userFormatter.Format("author", authors),
|
||||
currentCommit,
|
||||
lastRelease.hash,
|
||||
`${lastRelease.major}.${lastRelease.minor}.${lastRelease.patch}`,
|
||||
debugManager.getDebugOutput()
|
||||
debugManager.getDebugOutput(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue