Support new unity versioning scheme with regex matching groups

pull/264/head
Andrew Kahr 2024-03-16 17:49:00 -07:00
parent 35b5a08132
commit 056d560f58
4 changed files with 1378 additions and 1375 deletions

2730
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

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('UnityVersionParser', () => {
m_EditorVersionWithRevision: 2022.3.7f1 (b16b3b16c7a0)`;
expect(UnityVersionParser.parse(projectVersionContents)).toBe('2022.3.7f1');
});
it('parses Unity 6000 and newer from ProjectVersion.txt', () => {
const projectVersionContents = `m_EditorVersion: 6000.0.0f1
m_EditorVersionWithRevision: 6000.0.0f1 (cb45f9cae8b7)`;
expect(UnityVersionParser.parse(projectVersionContents)).toBe('6000.0.0f1');
});
});
describe('read', () => {

View File

@ -2,16 +2,15 @@ import fs from 'fs';
import path from 'path';
const UnityVersionParser = {
get versionPattern() {
return /20\d{2}\.\d\.\w{3,4}|3/;
},
parse(projectVersionTxt) {
const matches = projectVersionTxt.match(UnityVersionParser.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];
},
read(projectPath) {