mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
ae23df6609
* support engine version validation * support exit code for checkout engine version * optimize repo path
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
const fs = require('fs');
|
|
const ps = require('path');
|
|
const vGit = require('v-git');
|
|
|
|
const repo = vGit.init(ps.join(__dirname, '../'));
|
|
const branchName = repo.branch;
|
|
const branchRegExp = /^v?(\d+\.\d+\.\d+)(?:-.*)?$/
|
|
const matchResult = branchName.match(branchRegExp);
|
|
if (!(matchResult && matchResult[1])) {
|
|
console.warn(`Invalid branch name: "${branchName}", skip engine version validation.`)
|
|
process.exit(0);
|
|
}
|
|
const branchVersion = matchResult[1];
|
|
|
|
const versionRegExpMap = {
|
|
'./package.json': /"version": "(.*)"/,
|
|
'./cocos/core/global-exports.ts': /engineVersion = '(.*)'/,
|
|
};
|
|
for (filePath in versionRegExpMap) {
|
|
const regExp = versionRegExpMap[filePath];
|
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
const version = content.match(regExp)[1];
|
|
if (version !== branchVersion) {
|
|
console.error(`Wrong engine version "${version}" in file "${filePath}", need to match branch name "${branchName}".`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
console.log('Engine version validation complete!');
|
|
process.exit(0);
|