6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- // tslint:disable: no-implicit-dependencies
9
+ // tslint:disable: no-implicit-dependencies we import @angular-devkit/core but
10
+ // it is not in package.json, which is fine, this is just a script.
10
11
11
12
import { logging } from '@angular-devkit/core' ;
12
13
import { execSync } from 'child_process' ;
13
14
import { packages , stableToExperimentalVersion } from '../lib/packages' ;
14
15
15
16
interface DistTagOptions {
16
17
/**
17
- * Version must be specified in format d+.d+.d+ where d is a 0-9 digit.
18
- * This must be a stable version with major version > 0.
19
- * The script will automatically convert stable version to experimental.
18
+ * The version of CLI packages published to NPM.
19
+ * Version must begin with d+.d+.d+ where d is a 0-9 digit.
20
+ * For example, `1.2.3`, `10.0.0-next.0`, or `10.0.0-rc.0`.
21
+ * Since we publish both stable and experimental packages to NPM, the version
22
+ * provided here must be a stable version with major version > 0.
23
+ * The script will automatically convert stable version to experimental for
24
+ * experimental packages.
20
25
*/
21
26
version : string ;
22
27
/**
23
28
* Tag is usually "latest" or "next", but could also be "v10-lts" for example.
24
29
*/
25
30
tag : string ;
31
+ /**
32
+ * If true, prints the help message.
33
+ */
34
+ help : boolean ;
26
35
}
27
36
28
37
/**
29
38
* This function adds a tag to all public packages in the CLI repo.
30
39
*/
31
40
export default function ( args : DistTagOptions , logger : logging . Logger ) {
41
+ if ( args . help ) {
42
+ logger . info ( `dist-tag adds a tag to all public packages in the CLI repo.
43
+
44
+ If the packages already have a tag associated with them, then dist-tag will
45
+ retag the packages.
46
+
47
+ Usage:
48
+ --version the version of CLI packages published to NPM.
49
+ --tag the tag to add to CLI packages` ) ;
50
+
51
+ return ;
52
+ }
32
53
const { version, tag} = args ;
33
54
if ( ! version || version . startsWith ( 'v' ) ) {
34
55
throw new Error ( 'Version must be specified in format d+.d+.d+' ) ;
35
56
}
36
57
if ( version . startsWith ( '0' ) ) {
37
- throw new Error ( 'Version must be "stable", with major version > 0' ) ;
58
+ throw new Error ( `Major version must be > 0, did you mean ${ stableToExperimentalVersion ( version ) } ?` ) ;
38
59
}
39
60
if ( ! tag ) {
40
61
throw new Error ( 'Tag must be non-empty, for example: latest, next, v10-lts, etc' ) ;
@@ -43,7 +64,7 @@ export default function(args: DistTagOptions, logger: logging.Logger) {
43
64
for ( const { name, experimental} of publicPackages ) {
44
65
const actualVersion = experimental ? stableToExperimentalVersion ( version ) : version ;
45
66
// See https://docs.npmjs.com/cli/dist-tag for documentation
46
- const cmd = `npm dist-tag add ${ name } @${ actualVersion } ${ tag } ` ;
67
+ const cmd = `npm dist-tag add ' ${ name } @${ actualVersion } ' ' ${ tag } ' ` ;
47
68
logger . debug ( cmd ) ; // print debug output by specifying --verbose
48
69
const output = execSync ( cmd , { encoding : 'utf8' } ) ;
49
70
logger . info ( output . trim ( ) ) ;
0 commit comments