Support new unity versioning scheme with regex matching groups
parent
35b5a08132
commit
056d560f58
|
@ -1462,15 +1462,13 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const UnityVersionParser = {
|
const UnityVersionParser = {
|
||||||
get versionPattern() {
|
|
||||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
|
||||||
},
|
|
||||||
parse(projectVersionTxt) {
|
parse(projectVersionTxt) {
|
||||||
const matches = projectVersionTxt.match(UnityVersionParser.versionPattern);
|
const versionRegex = /m_EditorVersion: (\d+\.\d+\.\d+[A-Za-z]?\d+)/;
|
||||||
if (!matches || matches.length === 0) {
|
const matches = projectVersionTxt.match(versionRegex);
|
||||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
if (!matches || matches.length < 2) {
|
||||||
|
throw new Error(`Failed to extract version from "${projectVersionTxt}".`);
|
||||||
}
|
}
|
||||||
return matches[0];
|
return matches[1];
|
||||||
},
|
},
|
||||||
read(projectPath) {
|
read(projectPath) {
|
||||||
const filePath = path_1.default.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
const filePath = path_1.default.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,6 +11,12 @@ describe('UnityVersionParser', () => {
|
||||||
m_EditorVersionWithRevision: 2022.3.7f1 (b16b3b16c7a0)`;
|
m_EditorVersionWithRevision: 2022.3.7f1 (b16b3b16c7a0)`;
|
||||||
expect(UnityVersionParser.parse(projectVersionContents)).toBe('2022.3.7f1');
|
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', () => {
|
describe('read', () => {
|
||||||
|
|
|
@ -2,16 +2,15 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
const UnityVersionParser = {
|
const UnityVersionParser = {
|
||||||
get versionPattern() {
|
|
||||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
|
||||||
},
|
|
||||||
|
|
||||||
parse(projectVersionTxt) {
|
parse(projectVersionTxt) {
|
||||||
const matches = projectVersionTxt.match(UnityVersionParser.versionPattern);
|
const versionRegex = /m_EditorVersion: (\d+\.\d+\.\d+[A-Za-z]?\d+)/;
|
||||||
if (!matches || matches.length === 0) {
|
const matches = projectVersionTxt.match(versionRegex);
|
||||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
|
||||||
|
if (!matches || matches.length < 2) {
|
||||||
|
throw new Error(`Failed to extract version from "${projectVersionTxt}".`);
|
||||||
}
|
}
|
||||||
return matches[0];
|
|
||||||
|
return matches[1];
|
||||||
},
|
},
|
||||||
|
|
||||||
read(projectPath) {
|
read(projectPath) {
|
||||||
|
|
Loading…
Reference in New Issue