Files
unity-test-runner/src/model/unity-version-parser.ts
Andrew Kahr fea469be8c Support new unity versioning scheme with regex matching groups (#264)
* Support new unity versioning scheme with regex matching groups

* Update github action packages

* Pin windows runner image version to 2022. Fix artifact name. Remove max-parallel cap for tests
2024-05-06 22:49:20 +01:00

28 lines
796 B
TypeScript

import fs from 'fs';
import path from 'path';
const UnityVersionParser = {
parse(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[1];
},
read(projectPath) {
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
if (!fs.existsSync(filePath)) {
throw new Error(
`Project settings file not found at "${filePath}". Have you correctly set the projectPath?`,
);
}
return UnityVersionParser.parse(fs.readFileSync(filePath, 'utf8'));
},
};
export default UnityVersionParser;