@@ -12,6 +12,9 @@ export const releasePackages = [
12
12
'flex-layout'
13
13
] ;
14
14
15
+ /** Regular Expression that matches valid version numbers of Angular Material. */
16
+ export const validVersionRegex = / ^ \d + \. \d + \. \d + ( - ( a l p h a | b e t a | r c ) \. \d + ) ? $ / ;
17
+
15
18
/** Parse command-line arguments for release task. */
16
19
const argv = minimist ( process . argv . slice ( 3 ) ) ;
17
20
@@ -38,22 +41,40 @@ task(':publish:whoami', execTask('npm', ['whoami'], {
38
41
task ( ':publish:logout' , execTask ( 'npm' , [ 'logout' ] ) ) ;
39
42
40
43
task ( ':publish' , async ( ) => {
41
- const label = argv [ 'tag' ] ;
44
+ const tag = argv [ 'tag' ] ;
42
45
const version = buildConfig . projectVersion ;
43
46
const currentDir = process . cwd ( ) ;
44
47
48
+ if ( ! version . match ( validVersionRegex ) ) {
49
+ console . log ( red ( `Error: Cannot publish due to an invalid version name. Version "${ version } " ` +
50
+ `is not following our semver format.` ) ) ;
51
+ console . log ( yellow ( `A version should follow this format: d.d.d, d.d.d-beta.x, d.d.d-alpha.x, ` +
52
+ `d.d.d-rc.x` ) ) ;
53
+ return ;
54
+ }
55
+
45
56
console . log ( '' ) ;
46
- if ( ! label ) {
47
- console . log ( yellow ( ' You can use a label with --tag=labelName.') ) ;
48
- console . log ( yellow ( `Publishing version ${ version } using the latest tag.` ) ) ;
57
+ if ( ! tag ) {
58
+ console . log ( grey ( '> You can specify the tag by passing --tag=labelName.\n ') ) ;
59
+ console . log ( green ( `Publishing version " ${ version } " to the latest tag.. .` ) ) ;
49
60
} else {
50
- console . log ( yellow ( `Publishing ${ version } using the ${ label } tag.` ) ) ;
61
+ console . log ( yellow ( `Publishing version " ${ version } " to the ${ tag } tag.. .` ) ) ;
51
62
}
52
63
console . log ( '' ) ;
53
64
65
+
66
+ // TODO(CaerusKaru): uncomment when Layout exits beta/rc
67
+ // if (version.match(/(alpha|beta|rc)/) && (!tag || tag === 'latest')) {
68
+ // console.log(red(`Publishing ${version} to the "latest" tag is not allowed.`));
69
+ // console.log(red(`Alpha, Beta or RC versions shouldn't be published to "latest".`));
70
+ // console.log();
71
+ // return;
72
+ // }
73
+
54
74
if ( releasePackages . length > 1 ) {
55
75
console . warn ( red ( 'Warning: Multiple packages will be released if proceeding.' ) ) ;
56
- console . warn ( red ( 'Warning: Packages to be released: ' , releasePackages . join ( ', ' ) ) ) ;
76
+ console . warn ( red ( 'Warning: Packages to be released:' , releasePackages . join ( ', ' ) ) ) ;
77
+ console . log ( ) ;
57
78
}
58
79
59
80
console . log ( yellow ( '> Make sure to check the "angularVersion" in the build config.' ) ) ;
@@ -62,13 +83,13 @@ task(':publish', async () => {
62
83
63
84
// Iterate over every declared release package and publish it on NPM.
64
85
for ( const packageName of releasePackages ) {
65
- await _execNpmPublish ( label , packageName ) ;
86
+ await _execNpmPublish ( tag , packageName ) ;
66
87
}
67
88
68
89
process . chdir ( currentDir ) ;
69
90
} ) ;
70
91
71
- function _execNpmPublish ( label : string , packageName : string ) : Promise < { } > | undefined {
92
+ function _execNpmPublish ( tag : string , packageName : string ) : Promise < { } > | undefined {
72
93
const packageDir = join ( buildConfig . outputDir , 'releases' , packageName ) ;
73
94
74
95
if ( ! statSync ( packageDir ) . isDirectory ( ) ) {
@@ -89,8 +110,8 @@ function _execNpmPublish(label: string, packageName: string): Promise<{}> | unde
89
110
const command = 'npm' ;
90
111
const args = [ 'publish' , '--access' , 'public' ] ;
91
112
92
- if ( label ) {
93
- args . push ( '--tag' , label ) ;
113
+ if ( tag ) {
114
+ args . push ( '--tag' , tag ) ;
94
115
}
95
116
96
117
return new Promise ( ( resolve , reject ) => {
0 commit comments