Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Correctly Updates Generic Version Configs #91

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/update-global-version-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ recast.visit(ast, {
recast.types.builders.property(
'init',
recast.types.builders.identifier('badge'),
recast.types.builders.literal(false),
recast.types.builders.literal(true),
),
);

Expand Down
45 changes: 35 additions & 10 deletions scripts/update-pixi-version-configs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable radix */
const { resolve } = require('path');
const { readFileSync, existsSync } = require('fs');
const shell = require('shelljs');
Expand All @@ -11,6 +12,7 @@ shell.exec('npm view pixi.js --json > scripts/pixiVersions.json');
// Import the compiled list of versions
const pixiVersions = require('./pixiVersions.json');
const tags = pixiVersions['dist-tags'];
const allVersions = pixiVersions.versions;

const ROOT = resolve(__dirname, '..');

Expand All @@ -29,18 +31,37 @@ console.log('Updating any outdated pixi version configs...');
versionFiles.forEach((file) =>
{
const config = JSON.parse(readFileSync(file, 'utf8'));
const { version } = config;
const { version, versionLabel: label, prerelease } = config;

console.log(`Checking ${config.versionLabel} (v${version}) config`);

const tag = Object.entries(tags).find(([k, v]) => v === version)?.[0];
const isGeneric = label.includes('.x');
let newVersion = version;

const parts = version.split('.');
// For generic versions, we also want to update the config to the latest version within the specified major version
if (isGeneric)
{
// Get the major version number
const majorVersion = parseInt(version.split('.')[0]);

// Get all versions within the same major version
const sameMajorVersions = allVersions
.filter((v) => parseInt(v.split('.')[0]) === majorVersion)
// Exclude meta-releases if config is not marked as pre-release
.filter((v) => prerelease || !v.includes('-'));

// Find the maximum version within the same major version
newVersion = sameMajorVersions.reduce((a, b) => (compareVersions(a, b) >= 0 ? a : b));
}

const tag = Object.entries(tags).find(([k, v]) => v === newVersion)?.[0];

const parts = newVersion.split('.');
const major = parts[0];
const minor = parts[1];
const patch = parts[2].split('-')[0];
const isPrelease = parts[2].includes('-rc');
const isLatest = version === tags.latest;
const isLatest = newVersion === tags.latest;
let versionLabel;

if (isLatest)
Expand All @@ -53,18 +74,22 @@ versionFiles.forEach((file) =>

versionLabel = extracted.match(/^\d/) ? `v${extracted}` : extracted;
}
else if (isGeneric)
{
versionLabel = `v${[major, 'x'].join('.')}`;
}
else
{
versionLabel = `v${version}`;
versionLabel = `v${newVersion}`;
}

const newConfig = {
versionLabel,
version,
releaseNotes: `https://github.com/pixijs/pixijs/releases/tag/v${version}`,
build: `https://pixijs.download/v${version}/pixi.min.js`,
docs: `https://pixijs.download/v${version}/docs/index.html`,
npm: version,
version: newVersion,
releaseNotes: `https://github.com/pixijs/pixijs/releases/tag/v${newVersion}`,
build: `https://pixijs.download/v${newVersion}/pixi.min.js`,
docs: `https://pixijs.download/v${newVersion}/docs/index.html`,
npm: newVersion,
prerelease: isPrelease,
latest: isLatest,
};
Expand Down
Loading