11const { execSync } = require ( 'child_process' ) ;
22const 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 + ) ( - ? b e t a ) ? $ / 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
1725module . 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