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

pull/640/head v4.2.2
Andrew Kahr 2024-03-16 21:31:46 -07:00 committed by GitHub
parent fc0a52b805
commit 0c16aab353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 16 deletions

12
dist/index.js generated vendored
View File

@ -7757,9 +7757,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const node_fs_1 = __importDefault(__nccwpck_require__(87561));
const node_path_1 = __importDefault(__nccwpck_require__(49411));
class UnityVersioning {
static get versionPattern() {
return /20\d{2}\.\d\.\w{3,4}|3/;
}
static determineUnityVersion(projectPath, unityVersion) {
if (unityVersion === 'auto') {
return UnityVersioning.read(projectPath);
@ -7774,11 +7771,12 @@ class UnityVersioning {
return UnityVersioning.parse(node_fs_1.default.readFileSync(filePath, 'utf8'));
}
static parse(projectVersionTxt) {
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];
}
}
exports["default"] = UnityVersioning;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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', () => {

View File

@ -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);
@ -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];
}
}