Skip to content

Commit 54b0cf4

Browse files
unity-cli@v1.0.12 (#13)
- fixed semver build matching - added unity-version.tests.ts - added `UnityHub.ListAvailableReleases`
1 parent 9dfb341 commit 54b0cf4

5 files changed

Lines changed: 297 additions & 116 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rage-against-the-pixel/unity-cli",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "A command line utility for the Unity Game Engine.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/unity-hub.ts

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export class UnityHub {
9595
'Invalid key: The GraphQL query at the field at',
9696
'You have to request `id` or `_id` fields for all selection sets or create a custom `keys` config for `UnityReleaseLabel`.',
9797
'Entities without keys will be embedded directly on the parent entity. If this is intentional, create a `keys` config for `UnityReleaseLabel` that always returns null.',
98-
'https://bit.ly/2XbVrpR#15'
98+
'https://bit.ly/2XbVrpR#15',
99+
'Interaction is not allowed with the Security Server." (-25308)'
99100
];
100101

101102
try {
@@ -453,25 +454,33 @@ chmod -R 777 "$hubPath"`]);
453454
];
454455

455456
this.logger.ci(`Getting release info for Unity ${unityVersion.toString()}...`);
456-
let editorPath = await this.checkInstalledEditors(unityVersion, false);
457+
let resolvedVersion = unityVersion;
457458

458-
// attempt to resolve the full version with the changeset if we don't have one already
459-
if (!unityVersion.isLegacy() && !editorPath && !unityVersion.changeset) {
459+
if (!resolvedVersion.isLegacy()) {
460460
try {
461-
const releases = await this.getLatestHubReleases();
462-
unityVersion = unityVersion.findMatch(releases);
463-
const unityReleaseInfo: UnityRelease = await this.getEditorReleaseInfo(unityVersion);
464-
unityVersion = new UnityVersion(unityReleaseInfo.version, unityReleaseInfo.shortRevision, unityVersion.architecture);
461+
if (!resolvedVersion.isFullyQualified()) {
462+
const releases = await this.getLatestHubReleases();
463+
resolvedVersion = resolvedVersion.findMatch(releases);
464+
}
465+
466+
if (!resolvedVersion.changeset) {
467+
const unityReleaseInfo: UnityRelease = await this.getEditorReleaseInfo(resolvedVersion);
468+
resolvedVersion = new UnityVersion(unityReleaseInfo.version, unityReleaseInfo.shortRevision, resolvedVersion.architecture);
469+
}
465470
} catch (error) {
466-
this.logger.warn(`Failed to get Unity release info for ${unityVersion.toString()}! falling back to legacy search...\n${error}`);
471+
this.logger.warn(`Failed to get Unity release info for ${resolvedVersion.toString()}! falling back to legacy search...\n${error}`);
467472
try {
468-
unityVersion = await this.fallbackVersionLookup(unityVersion);
473+
resolvedVersion = await this.fallbackVersionLookup(resolvedVersion);
469474
} catch (fallbackError) {
470-
this.logger.warn(`Failed to lookup changeset for Unity ${unityVersion.toString()}!\n${fallbackError}`);
475+
this.logger.warn(`Failed to lookup changeset for Unity ${resolvedVersion.toString()}!\n${fallbackError}`);
471476
}
472477
}
473478
}
474479

480+
const allowPartialMatches = !resolvedVersion.isFullyQualified();
481+
let editorPath = await this.checkInstalledEditors(resolvedVersion, false, undefined, allowPartialMatches);
482+
unityVersion = resolvedVersion;
483+
475484
let installPath: string | undefined = undefined;
476485

477486
if (!editorPath) {
@@ -546,7 +555,23 @@ chmod -R 777 "$hubPath"`]);
546555
.map(line => line.trim());
547556
}
548557

549-
private async checkInstalledEditors(unityVersion: UnityVersion, failOnEmpty: boolean, installPath: string | undefined = undefined): Promise<string | undefined> {
558+
/**
559+
* Lists the available Unity releases.
560+
* @returns A list of available Unity release versions.
561+
*/
562+
public async ListAvailableReleases(): Promise<string[]> {
563+
const output = await this.Exec(['editors', '--releases']);
564+
return output.split('\n')
565+
.filter(line => line.trim().length > 0)
566+
.map(line => line.trim());
567+
}
568+
569+
private async checkInstalledEditors(
570+
unityVersion: UnityVersion,
571+
failOnEmpty: boolean,
572+
installPath: string | undefined = undefined,
573+
allowPartialMatches: boolean = true
574+
): Promise<string | undefined> {
550575
let editorPath = undefined;
551576

552577
if (!installPath) {
@@ -565,7 +590,7 @@ chmod -R 777 "$hubPath"`]);
565590

566591
if (exactMatch) {
567592
editorPath = exactMatch.groups!.editorPath;
568-
} else {
593+
} else if (allowPartialMatches) {
569594
// Fallback: semver satisfies
570595
const versionMatches = matches.filter(match => match?.groups?.version && unityVersion.satisfies(match.groups.version));
571596

@@ -578,21 +603,32 @@ chmod -R 777 "$hubPath"`]);
578603
'X86_64': 'Intel',
579604
};
580605

581-
for (const match of versionMatches) {
582-
if (!match || !match.groups || !match.groups.version || !match.groups.editorPath) {
606+
const sortedMatches = versionMatches
607+
.map(match => ({
608+
match: match!,
609+
parsed: new UnityVersion(match!.groups!.version!, null, undefined)
610+
}))
611+
.sort((a, b) => UnityVersion.compare(b.parsed, a.parsed));
612+
613+
for (const candidate of sortedMatches) {
614+
const match = candidate.match;
615+
if (!match.groups || !match.groups.version || !match.groups.editorPath) {
583616
continue;
584617
}
585-
// If no architecture is set, or no arch in match, accept the version match
618+
586619
if (!unityVersion.architecture || !match.groups.arch) {
587620
editorPath = match.groups.editorPath;
621+
break;
588622
}
589-
// If architecture is set and present in match, check for match
590-
else if (archMap[unityVersion.architecture] === match.groups.arch) {
623+
624+
if (archMap[unityVersion.architecture] === match.groups.arch) {
591625
editorPath = match.groups.editorPath;
626+
break;
592627
}
593-
// Fallback: check if editorPath includes architecture string (case-insensitive)
594-
else if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
628+
629+
if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
595630
editorPath = match.groups.editorPath;
631+
break;
596632
}
597633
}
598634
}

0 commit comments

Comments
 (0)