66 * found in the LICENSE file at https://angular.io/license
77 */
88// tslint:disable:no-implicit-dependencies
9- import { logging } from '@angular-devkit/core' ;
9+ import { logging , tags } from '@angular-devkit/core' ;
1010import { spawnSync } from 'child_process' ;
1111import { packages } from '../lib/packages' ;
1212import build from './build' ;
1313
1414
15+ export interface PublishArgs {
16+ tag ?: string ;
17+ branchCheck ?: boolean ;
18+ }
19+
20+
1521function _exec ( command : string , args : string [ ] , opts : { cwd ?: string } , logger : logging . Logger ) {
1622 const { status, error, stderr, stdout } = spawnSync ( command , args , { ...opts } ) ;
1723
@@ -29,7 +35,28 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
2935}
3036
3137
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+
3360 logger . info ( 'Building...' ) ;
3461 await build ( { } , logger . createChild ( 'build' ) ) ;
3562
0 commit comments