Skip to content

Commit

Permalink
fix(projects): fix version
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 2, 2024
1 parent 8474360 commit a639640
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function getTotalChangelogMarkdown(options?: Partial<ChangelogOptio
export async function generateChangelog(options?: Partial<ChangelogOption>) {
const opts = await createOptions(options);

const existContent = await isVersionInMarkdown(opts.to, opts.newVersion, opts.output);
const existContent = await isVersionInMarkdown(opts.newVersion, opts.output);

if (!opts.regenerate && existContent) return;

Expand Down
27 changes: 6 additions & 21 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFile, writeFile } from 'node:fs/promises';
import dayjs from 'dayjs';
import { convert } from 'convert-gitmoji';
import { capitalize, groupBy, join, partition } from './shared';
import { VERSION_REG, VERSION_REG_OF_MARKDOWN, VERSION_WITH_RELEASE } from './constant';
import { VERSION_REG_OF_MARKDOWN, VERSION_WITH_RELEASE } from './constant';
import type { ChangelogOption, GitCommit, Reference, ResolvedAuthor } from './types';

function formatReferences(references: Reference[], githubRepo: string, type: 'issues' | 'hash'): string {
Expand Down Expand Up @@ -151,14 +151,12 @@ export function generateMarkdown(params: {

const lines: string[] = [];

const { version, isNewVersion } = getVersionInfo(options.to, options.newVersion);

const url = `https://github.com/${options.github.repo}/compare/${options.from}...${version}`;
const url = `https://github.com/${options.github.repo}/compare/${options.from}...${options.newVersion}`;

if (showTitle) {
const date = isNewVersion ? dayjs().format('YY-MM-DD') : options.tagDateMap.get(options.to);
const date = options.tagDateMap.get(options.newVersion) || dayjs().format('YY-MM-DD');

let title = `## [${version}](${url})`;
let title = `## [${options.newVersion}](${url})`;

if (date) {
title += ` (${date})`;
Expand Down Expand Up @@ -199,7 +197,7 @@ export function generateMarkdown(params: {
return md;
}

export async function isVersionInMarkdown(to: string, newVersion: string, mdPath: string) {
export async function isVersionInMarkdown(newVersion: string, mdPath: string) {
let isIn = false;

let md = '';
Expand All @@ -211,9 +209,7 @@ export async function isVersionInMarkdown(to: string, newVersion: string, mdPath
const matches = md.match(VERSION_REG_OF_MARKDOWN);

if (matches?.length) {
const { version } = getVersionInfo(to, newVersion);

const versionInMarkdown = `## [${version}]`;
const versionInMarkdown = `## [${newVersion}]`;

isIn = matches.includes(versionInMarkdown);
}
Expand All @@ -222,17 +218,6 @@ export async function isVersionInMarkdown(to: string, newVersion: string, mdPath
return isIn;
}

function getVersionInfo(to: string, newVersion: string) {
const isNewVersion = !VERSION_REG.test(to);

const version = isNewVersion ? newVersion : to;

return {
version,
isNewVersion
};
}

export async function writeMarkdown(md: string, mdPath: string, regenerate = false) {
let changelogMD: string = '';

Expand Down

0 comments on commit a639640

Please sign in to comment.