Skip to content

Commit 80fbe6d

Browse files
LeoYuanliujuping
authored andcommitted
chore: get release version from git branch name (support beta identifier)
1 parent 176583f commit 80fbe6d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/engine/build.plugin.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
const { execSync } = require('child_process');
22
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
3+
const fse = require('fs-extra');
34

4-
function getReleaseVersion() {
5+
// get version from git branch name,
6+
// e.g. release/1.0.7 => 1.0.7
7+
// release/1.0.7-beta => 1.0.7 (beta)
8+
function getVersion() {
59
const gitBranchName = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf-8' });
6-
const reBranchVersion = /^(?:[\w-]+\/)(\d+\.\d+\.\d+)$/im;
10+
const reBranchVersion = /^(?:[\w-]+\/)(\d+\.\d+\.\d+)(-?beta)?$/im;
11+
712
const match = reBranchVersion.exec(gitBranchName);
813
if (!match) {
9-
throw new Error(`[engine] gitBranchName: ${gitBranchName} is not valid`);
14+
console.warn(`[engine] gitBranchName: ${gitBranchName}`);
15+
return 'N/A';
1016
}
1117

12-
return match[1];
18+
const [_, version, beta] = match;
19+
20+
return beta && beta.endsWith('beta') ? `${version}(beta)` : version;
1321
}
1422

15-
const version = getReleaseVersion();
23+
const releaseVersion = getVersion();
1624

1725
module.exports = ({ context, onGetWebpackConfig }) => {
1826
onGetWebpackConfig((config) => {
@@ -24,7 +32,7 @@ module.exports = ({ context, onGetWebpackConfig }) => {
2432
config
2533
.plugin('define')
2634
.use(context.webpack.DefinePlugin, [{
27-
VERSION_PLACEHOLDER: JSON.stringify(version),
35+
VERSION_PLACEHOLDER: JSON.stringify(releaseVersion),
2836
}]);
2937
config.plugins.delete('hot');
3038
config.devServer.hot(false);

0 commit comments

Comments
 (0)