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

Use capture group to find Unity version to support new 6000 versions #639

Merged
merged 1 commit into from
Mar 17, 2024
Merged
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
12 changes: 5 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/model/unity-versioning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ describe('Unity Versioning', () => {
m_EditorVersionWithRevision: 2021.3.4f1 (cb45f9cae8b7)`;
expect(UnityVersioning.parse(projectVersionContents)).toBe('2021.3.4f1');
});

it('parses Unity 6000 and newer from ProjectVersion.txt', () => {
const projectVersionContents = `m_EditorVersion: 6000.0.0f1
m_EditorVersionWithRevision: 6000.0.0f1 (cb45f9cae8b7)`;
expect(UnityVersioning.parse(projectVersionContents)).toBe('6000.0.0f1');
});
});

describe('read', () => {
Expand Down
14 changes: 6 additions & 8 deletions src/model/unity-versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import fs from 'node:fs';
import path from 'node:path';

export default class UnityVersioning {
static get versionPattern() {
return /20\d{2}\.\d\.\w{3,4}|3/;
}

static determineUnityVersion(projectPath: string, unityVersion: string) {
if (unityVersion === 'auto') {
return UnityVersioning.read(projectPath);
Expand All @@ -24,11 +20,13 @@ export default class UnityVersioning {
}

static parse(projectVersionTxt: string) {
const matches = projectVersionTxt.match(UnityVersioning.versionPattern);
if (!matches || matches.length === 0) {
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
const versionRegex = /m_EditorVersion: (\d+\.\d+\.\d+[A-Za-z]?\d+)/;
const matches = projectVersionTxt.match(versionRegex);

if (!matches || matches.length < 2) {
throw new Error(`Failed to extract version from "${projectVersionTxt}".`);
}

return matches[0];
return matches[1];
}
}
Loading