Skip to content

Commit fb7b1e1

Browse files
kyliaualan-agius4
authored andcommitted
build: Add script for retagging CLI packages
1 parent 4f08350 commit fb7b1e1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

scripts/dist-tag.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
// tslint:disable: no-implicit-dependencies
10+
11+
import { logging } from '@angular-devkit/core';
12+
import { execSync } from 'child_process';
13+
import { packages, stableToExperimentalVersion } from '../lib/packages';
14+
15+
interface DistTagOptions {
16+
/**
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.
20+
*/
21+
version: string;
22+
/**
23+
* Tag is usually "latest" or "next", but could also be "v10-lts" for example.
24+
*/
25+
tag: string;
26+
}
27+
28+
/**
29+
* This function adds a tag to all public packages in the CLI repo.
30+
*/
31+
export default function(args: DistTagOptions, logger: logging.Logger) {
32+
const {version, tag} = args;
33+
if (!version || version.startsWith('v')) {
34+
throw new Error('Version must be specified in format d+.d+.d+');
35+
}
36+
if (version.startsWith('0')) {
37+
throw new Error('Version must be "stable", with major version > 0');
38+
}
39+
if (!tag) {
40+
throw new Error('Tag must be non-empty, for example: latest, next, v10-lts, etc');
41+
}
42+
const publicPackages = Object.values(packages).filter(p => !p.private);
43+
for (const {name, experimental} of publicPackages) {
44+
const actualVersion = experimental ? stableToExperimentalVersion(version) : version;
45+
// See https://docs.npmjs.com/cli/dist-tag for documentation
46+
const cmd = `npm dist-tag add ${name}@${actualVersion} ${tag}`;
47+
logger.debug(cmd); // print debug output by specifying --verbose
48+
const output = execSync(cmd, { encoding: 'utf8' });
49+
logger.info(output.trim());
50+
}
51+
}

0 commit comments

Comments
 (0)