-
Notifications
You must be signed in to change notification settings - Fork 535
/
Copy pathlatest.ts
68 lines (58 loc) · 2.22 KB
/
latest.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
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import { Command, Flags } from "@oclif/core";
import { getLatestReleaseFromList } from "../../schemes";
/**
* The `version latest` command is used to find the latest (highest) version in a list of versions. The command takes
* the Fluid internal version scheme into account, and handles prerelease versions properly.
*
* Once scenario where this is useful is for Fluid customers who want to consume the most recent version from npm. The
* standard tools (e.g. `npm show versions`) don't fully work in that scenario because the Fluid internal version scheme
* overloads the semver prerelease field.
*/
// eslint-disable-next-line import/no-default-export
export default class LatestCommand extends Command {
static readonly description =
"Find the latest version from a list of version strings, accounting for the Fluid internal version scheme.";
static readonly enableJsonFlag = true;
static readonly flags = {
versions: Flags.string({
char: "r",
description:
"The versions to evaluate. The argument can be passed multiple times to provide multiple versions, or a space-delimited list of versions can be provided using a single argument.",
multiple: true,
required: true,
}),
prerelease: Flags.boolean({
default: false,
description:
"Include prerelease versions. By default, prerelease versions are excluded.",
}),
} as const;
static readonly examples = [
{
description: "You can use the --versions (-r) flag multiple times.",
command:
"<%= config.bin %> <%= command.id %> -r 2.0.0 -r 2.0.0-internal.1.0.0 -r 1.0.0 -r 0.56.1000",
},
{
description:
"You can omit the repeated --versions (-r) flag and pass a space-delimited list instead.",
command:
"<%= config.bin %> <%= command.id %> -r 2.0.0 2.0.0-internal.1.0.0 1.0.0 0.56.1000",
},
];
async run(): Promise<{
latest: string;
}> {
const { flags } = await this.parse(LatestCommand);
const data = {
latest: getLatestReleaseFromList(flags.versions, flags.prerelease),
};
this.log(data.latest);
// When the --json flag is passed, the command will return the raw data as JSON.
return data;
}
}