-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathnext.ts
More file actions
63 lines (54 loc) · 1.73 KB
/
next.ts
File metadata and controls
63 lines (54 loc) · 1.73 KB
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
import { CommandModule } from "yargs";
import semver from "semver";
import { CliGlobalOptions, ReleaseType } from "../types";
import { defaultDir } from "../params";
import { getPM, verifyEthConnection } from "../providers/pm";
import { readManifest } from "../utils/manifest";
interface CliCommandOptions extends CliGlobalOptions {
type: string;
provider: string;
}
export const next: CommandModule<CliGlobalOptions, CliCommandOptions> = {
command: "next [type]",
describe: "Compute the next release version from published repo",
builder: yargs =>
yargs
.positional("type", {
description: "Semver update type: [ major | minor | patch ]",
choices: ["major", "minor", "patch"],
type: "string"
})
.option("provider", {
alias: "p",
description: `Specify an ipfs provider: "dappnode" (default), "infura", "localhost:5002"`,
default: "dappnode",
type: "string"
})
.require("type"),
handler: async (args): Promise<void> => {
const nextVersion = await nextHandler(args);
// Output result: "0.1.8"
console.log(nextVersion);
}
};
/**
* Common handler for CLI and programatic usage
*/
export async function nextHandler({
type,
provider,
dir = defaultDir
}: CliCommandOptions): Promise<string> {
const ethProvider = provider;
const pm = getPM(ethProvider);
await verifyEthConnection(pm);
const { manifest } = readManifest({ dir });
const latestVersion = await pm.getLatestVersion(manifest.name);
const nextVersion = semver.inc(latestVersion, type as ReleaseType);
if (!nextVersion)
throw Error(
`Error computing next version, is this increase type correct? type: ${type}`
);
// Execute command
return nextVersion;
}