1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __importStar = (this && this.__importStar) || function (mod) {
|
7 | if (mod && mod.__esModule) return mod;
|
8 | var result = {};
|
9 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
10 | result["default"] = mod;
|
11 | return result;
|
12 | };
|
13 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
14 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
15 | };
|
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
17 | const path = __importStar(require("path"));
|
18 | const utils = __importStar(require("./utils"));
|
19 | const package_json_1 = __importDefault(require("package-json"));
|
20 | const commander_1 = __importDefault(require("commander"));
|
21 | const semver_1 = __importDefault(require("semver"));
|
22 |
|
23 |
|
24 |
|
25 | async function handlePackage(packagePath) {
|
26 | const cmds = [];
|
27 |
|
28 | packagePath = path.join(packagePath, 'package.json');
|
29 | let data;
|
30 | try {
|
31 | data = utils.readJSONFile(packagePath);
|
32 | }
|
33 | catch (e) {
|
34 | console.debug('Skipping package ' + packagePath);
|
35 | return cmds;
|
36 | }
|
37 | if (data.private) {
|
38 | return cmds;
|
39 | }
|
40 | const pkg = data.name;
|
41 | const npmData = await package_json_1.default(pkg, { allVersions: true });
|
42 | const versions = Object.keys(npmData.versions).sort(semver_1.default.rcompare);
|
43 | const tags = npmData['dist-tags'];
|
44 |
|
45 |
|
46 | const next = semver_1.default.prerelease(versions[0]) ? versions[0] : undefined;
|
47 | const latest = versions.find(i => !semver_1.default.prerelease(i));
|
48 | if (latest && latest !== tags.latest) {
|
49 | cmds.push(`npm dist-tag add ${pkg}@${latest} latest`);
|
50 | }
|
51 |
|
52 |
|
53 | if (!next && tags.next) {
|
54 | cmds.push(`npm dist-tag rm ${pkg} next`);
|
55 | }
|
56 | else if (next && next !== tags.next) {
|
57 | cmds.push(`npm dist-tag add ${pkg}@${next} next`);
|
58 | }
|
59 | return cmds;
|
60 | }
|
61 | exports.handlePackage = handlePackage;
|
62 | function flatten(a) {
|
63 | return a.reduce((acc, val) => acc.concat(val), []);
|
64 | }
|
65 | commander_1.default
|
66 | .description(`Print out commands to update npm 'latest' and 'next' dist-tags
|
67 | so that 'latest' points to the latest stable release and 'next'
|
68 | points to the latest prerelease after it.`)
|
69 | .option('--lerna', 'Update dist-tags in all lerna packages')
|
70 | .option('--path [path]', 'Path to package or monorepo to update')
|
71 | .action(async (args) => {
|
72 | const basePath = path.resolve(args.path || '.');
|
73 | let cmds = [];
|
74 | let paths = [];
|
75 | if (args.lerna) {
|
76 | paths = utils.getLernaPaths(basePath).sort();
|
77 | cmds = await Promise.all(paths.map(handlePackage));
|
78 | }
|
79 | cmds.push(await handlePackage(basePath));
|
80 | const out = flatten(cmds).join('\n');
|
81 | if (out) {
|
82 | console.debug(out);
|
83 | }
|
84 | });
|
85 | if (require.main === module) {
|
86 | commander_1.default.parse(process.argv);
|
87 | }
|
88 |
|
\ | No newline at end of file |