-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
show.ts
72 lines (59 loc) · 2.08 KB
/
show.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import cliui from 'cliui';
import pc from 'picocolors';
import type { WithWorkspaces } from '@onerepo/builders';
import { withWorkspaces } from '@onerepo/builders';
import type { Workspace } from '@onerepo/graph';
import type { Builder, Handler } from '@onerepo/yargs';
import type { VersionPlan } from './utils';
import { buildChangelog, getVersionable } from './utils';
export const command = ['show'];
export const description = 'Preview the next versions and changelogs for Workspaces.';
type Argv = WithWorkspaces & {
format: 'json' | 'plain';
};
export const builder: Builder<Argv> = (yargs) =>
withWorkspaces(yargs.usage(`$0 ${command[0]}`)).option('format', {
type: 'string',
choices: ['json', 'plain'] as const,
default: 'plain' as const,
description: 'Choose how the results will be returned.',
});
export const handler: Handler<Argv> = async (argv, { getWorkspaces, graph }) => {
const { format } = argv;
const workspaces = await getWorkspaces();
const versionPlans = await getVersionable(graph);
const deps = graph.dependencies(workspaces, true);
const toVersion: Array<Workspace> = Array.from(versionPlans.keys()).filter((ws) => deps.includes(ws));
if (format === 'json') {
process.stdout.write(
JSON.stringify(
toVersion.reduce(
(memo, ws) => {
memo[ws.name] = versionPlans.get(ws)!;
return memo;
},
{} as Record<string, VersionPlan>,
),
) + '\n',
);
return;
}
const ui = cliui({ width: Math.min(160, process.stdout.columns) });
for (const ws of toVersion) {
const plan = versionPlans.get(ws)!;
ui.div(
{ text: pc.cyan(pc.bold(pc.underline(ws.name))), padding: [1, 0, 0, 0] },
{ text: `${ws.version} ${pc.dim('→')} ${pc.bold(plan.version)}`, padding: [1, 0, 0, 0] },
);
const deps = graph.dependencies(ws);
const depPlans = new Map<Workspace, VersionPlan>();
for (const dep of deps) {
const depPlan = versionPlans.get(dep);
if (depPlan) {
depPlans.set(dep, depPlan);
}
}
ui.div({ text: await buildChangelog(plan, depPlans), padding: [0, 2, 0, 2] });
}
process.stdout.write(ui.toString() + '\n');
};