Skip to content

Commit

Permalink
feat: add upgrade version output (#58)
Browse files Browse the repository at this point in the history
* feat: add upgradeOption

* docs: readme

* feat: fix wrong compare

* feat: pref upgrade

* fix: change description

* feat: add version log in upgrade

* docs: update README.md

* feat: update upgrade-action

* feat: update index.ts

---------

Co-authored-by: winches <329487092@qq.com>
  • Loading branch information
hasmokan and winchesHe committed Apr 30, 2024
1 parent 507bd6c commit fe30335
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/helpers/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
fillAnsiLength,
getColorVersion,
getVersionAndMode,
isMajorUpdate,
isMinorUpdate,
strip,
transformPeerVersion,
versionModeRegex
} from './utils';
Expand All @@ -28,6 +31,8 @@ export interface UpgradeOption {

const DEFAULT_SPACE = ''.padEnd(7);

const MISSING = 'Missing';

interface Upgrade {
isNextUIAll: boolean;
allDependencies?: Record<string, SAFE_ANY>;
Expand Down Expand Up @@ -84,6 +89,9 @@ export async function upgrade<T extends Upgrade = Upgrade>(options: ExtractUpgra
!upgradeOption.isLatest && index === arr.findIndex((c) => c.package === upgradeOption.package)
);

// Output upgrade count
outputUpgradeCount(result);

return result;
}

Expand Down Expand Up @@ -294,7 +302,7 @@ export async function getPackageUpgradeData(packageNameList: string[]) {
isLatest: false,
latestVersion,
package: packageName,
version: chalk.red('Missing'),
version: chalk.red(MISSING),
versionMode: ''
};

Expand All @@ -303,3 +311,44 @@ export async function getPackageUpgradeData(packageNameList: string[]) {

return result;
}

function outputUpgradeCount(outputList: UpgradeOption[]) {
const count = {
major: 0,
minor: 0,
patch: 0
};

for (const component of outputList) {
if (component.version === MISSING) {
count.major++;
continue;
}
const stripLatestVersion = strip(component.latestVersion);

if (isMajorUpdate(component.version, stripLatestVersion)) {
count.major++;
} else if (isMinorUpdate(component.version, stripLatestVersion)) {
count.minor++;
} else {
count.patch++;
}
}

const outputInfo = Object.entries(count)
.reduce((acc, [key, value]) => {
if (!value) {
return acc;
}

return `${acc}${chalk.yellowBright(value)} ${key}, `;
}, '')
.replace(/, $/, '');

if (outputInfo) {
Logger.log(outputInfo);
Logger.newLine();
}

return count;
}

0 comments on commit fe30335

Please sign in to comment.