6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
// tslint:disable:no-implicit-dependencies
9
- import { logging } from '@angular-devkit/core' ;
9
+ import { logging , tags } from '@angular-devkit/core' ;
10
10
import { spawnSync } from 'child_process' ;
11
11
import { packages } from '../lib/packages' ;
12
12
import build from './build' ;
13
13
14
14
15
+ export interface PublishArgs {
16
+ tag ?: string ;
17
+ branchCheck ?: boolean ;
18
+ }
19
+
20
+
15
21
function _exec ( command : string , args : string [ ] , opts : { cwd ?: string } , logger : logging . Logger ) {
16
22
const { status, error, stderr, stdout } = spawnSync ( command , args , { ...opts } ) ;
17
23
@@ -29,7 +35,28 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
29
35
}
30
36
31
37
32
- export default async function ( args : { tag ?: string } , logger : logging . Logger ) {
38
+ function _branchCheck ( args : PublishArgs , logger : logging . Logger ) {
39
+ logger . info ( 'Checking branch...' ) ;
40
+ const ref = _exec ( 'git' , [ 'symbolic-ref' , 'HEAD' ] , { } , logger ) ;
41
+ const branch = ref . trim ( ) . replace ( / ^ r e f s \/ h e a d s \/ / , '' ) ;
42
+
43
+ switch ( branch ) {
44
+ case 'master' :
45
+ if ( args . tag !== 'next' ) {
46
+ throw new Error ( tags . oneLine `
47
+ Releasing from master requires a next tag. Use --branchCheck=false to skip this check.
48
+ ` ) ;
49
+ }
50
+ }
51
+ }
52
+
53
+
54
+ export default async function ( args : PublishArgs , logger : logging . Logger ) {
55
+ if ( args . branchCheck === undefined || args . branchCheck === true ) {
56
+ _branchCheck ( args , logger ) ;
57
+ }
58
+
59
+
33
60
logger . info ( 'Building...' ) ;
34
61
await build ( { } , logger . createChild ( 'build' ) ) ;
35
62
0 commit comments