diff --git a/src/constants.ts b/src/constants.ts index fe74a2d..1175ae1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,9 @@ export const DEFAULT_APP_NAME = 'RnDiffApp' export const DEFAULT_APP_PACKAGE = 'com.rndiffapp' +export const FIRST_PRE_060_VERSION = '0.60' +export const FIRST_PRE_070_VERSION = '0.70' + export const PACKAGE_NAMES = { RN: 'react-native', RNM: 'react-native-macos', diff --git a/src/utils.ts b/src/utils.ts index 1ae109e..ef89df9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,8 @@ import { DEFAULT_APP_PACKAGE, PACKAGE_NAMES, RN_CHANGELOG_URLS, + FIRST_PRE_060_VERSION, + FIRST_PRE_070_VERSION, } from './constants' import versions from './releases' @@ -127,6 +129,27 @@ export const getVersionsContentInDiff = ({ }) } +const getOldVersionsChangelogURL = ({ + version, + packageName, +}: { + version: string + packageName: string +}) => { + const urlOldVersion = RN_CHANGELOG_URLS[packageName].replace('/CHANGELOG.md', '') + let formattedVersion = version.replaceAll('.', '') + + if (version.split('.').length === 2) formattedVersion += '0' + + if (version < FIRST_PRE_060_VERSION) { + return `${urlOldVersion}/CHANGELOG-pre-060.md#v${formattedVersion}` + } + + if (version < FIRST_PRE_070_VERSION) { + return `${urlOldVersion}/CHANGELOG-pre-070.md#v${formattedVersion}` + } +} + export const getChangelogURL = ({ version, packageName, @@ -138,6 +161,10 @@ export const getChangelogURL = ({ return `${RN_CHANGELOG_URLS[packageName]}v${version}` } + if (version < FIRST_PRE_070_VERSION) { + return getOldVersionsChangelogURL({ packageName, version }) + } + return `${RN_CHANGELOG_URLS[packageName]}#v${version.replaceAll('.', '')}` }