mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-02-04 10:59:06 +08:00
Refactor to typescript (#158)
* Refactor to typescript * Fix platform and workflow * Fix workflow and platform * Update husky and image-tag * Use 'yarn lint-staged' instead of 'npx lint-staged'
This commit is contained in:
28
src/model/unity-version-parser.ts
Normal file
28
src/model/unity-version-parser.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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}".`);
|
||||
}
|
||||
return matches[0];
|
||||
},
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user