mirror of
https://github.com/LukeHagar/usage-statistics.git
synced 2025-12-06 04:21:55 +00:00
chore: bump version to 1.0.10 and build action
This commit is contained in:
32
dist/summaries/github.js
vendored
32
dist/summaries/github.js
vendored
@@ -4,6 +4,28 @@ import { Canvas } from 'skia-canvas';
|
||||
import semver from "semver";
|
||||
// Register all Chart.js controllers
|
||||
Chart.register(...registerables);
|
||||
/**
|
||||
* Safely compare two version strings using semver
|
||||
* Falls back to string comparison if semver parsing fails
|
||||
*/
|
||||
function safeSemverCompare(a, b) {
|
||||
try {
|
||||
// Clean and validate versions
|
||||
const cleanA = a.trim();
|
||||
const cleanB = b.trim();
|
||||
// Check if versions are valid semver
|
||||
if (!semver.valid(cleanA) || !semver.valid(cleanB)) {
|
||||
// Fall back to string comparison for invalid semver
|
||||
return cleanA.localeCompare(cleanB);
|
||||
}
|
||||
return semver.compare(cleanA, cleanB);
|
||||
}
|
||||
catch (error) {
|
||||
console.warn(`Semver comparison failed for "${a}" vs "${b}":`, error);
|
||||
// Fall back to string comparison
|
||||
return a.trim().localeCompare(b.trim());
|
||||
}
|
||||
}
|
||||
export function formatGitHubSummary(summary, platformMetrics) {
|
||||
let totalStars = 0;
|
||||
let totalForks = 0;
|
||||
@@ -81,7 +103,7 @@ export async function createGitHubReleaseChart(platformMetrics, outputPath) {
|
||||
function groupByReleaseCumulative(releaseRange) {
|
||||
const releases = {};
|
||||
for (const release of releaseRange.sort((a, b) => {
|
||||
return semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim());
|
||||
return safeSemverCompare(a.tagName || '0.0.0', b.tagName || '0.0.0');
|
||||
})) {
|
||||
if (!release.tagName) {
|
||||
continue;
|
||||
@@ -95,7 +117,7 @@ function groupByReleaseCumulative(releaseRange) {
|
||||
}
|
||||
let cumulativeDownloads = 0;
|
||||
for (const release of Object.keys(releases).sort((a, b) => {
|
||||
return semver.compare(a.trim(), b.trim());
|
||||
return safeSemverCompare(a, b);
|
||||
})) {
|
||||
cumulativeDownloads += releases[release].downloads;
|
||||
releases[release].downloads = cumulativeDownloads;
|
||||
@@ -106,7 +128,7 @@ export async function createDownloadsPerReleaseChart(metric, outputPath) {
|
||||
const downloadsRange = metric.metrics?.downloadRange || [];
|
||||
const svgOutputPath = `${outputPath}/${metric.name.replace('/', '-')}-release-downloads.svg`;
|
||||
const sortedReleases = downloadsRange.sort((a, b) => {
|
||||
return semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim());
|
||||
return safeSemverCompare(a.tagName || '0.0.0', b.tagName || '0.0.0');
|
||||
});
|
||||
const canvas = new Canvas(1000, 800);
|
||||
const chart = new Chart(canvas, {
|
||||
@@ -163,7 +185,7 @@ export async function createCumulativeDownloadsChart(metric, outputPath) {
|
||||
const groupedDownloads = groupByReleaseCumulative(downloadsRange);
|
||||
// Sort months chronologically
|
||||
const semVerSortedReleases = Object.keys(groupedDownloads).sort((a, b) => {
|
||||
return semver.compare(a.trim(), b.trim());
|
||||
return safeSemverCompare(a, b);
|
||||
});
|
||||
const canvas = new Canvas(1000, 800);
|
||||
const chart = new Chart(canvas, {
|
||||
@@ -224,7 +246,7 @@ export async function createReleaseDownloadsChart(metric, outputPath) {
|
||||
.filter((release) => release.tagName && release.downloads > 0)
|
||||
.sort((a, b) => b.downloads - a.downloads)
|
||||
.slice(0, 10) // Show top 10 releases
|
||||
.sort((a, b) => semver.compare((a.tagName || '0.0.0').trim(), (b.tagName || '0.0.0').trim()));
|
||||
.sort((a, b) => safeSemverCompare(a.tagName || '0.0.0', b.tagName || '0.0.0'));
|
||||
if (sortedReleases.length === 0) {
|
||||
// Return empty chart if no releases
|
||||
return svgOutputPath;
|
||||
|
||||
Reference in New Issue
Block a user