-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathincrease.ts
More file actions
67 lines (55 loc) · 1.98 KB
/
increase.ts
File metadata and controls
67 lines (55 loc) · 1.98 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
64
65
66
67
import { CommandModule } from "yargs";
import semver, { ReleaseType } from "semver";
import { CliGlobalOptions } from "../types";
import { defaultComposeFileName, defaultDir } from "../params";
import { readManifest, writeManifest } from "../utils/manifest";
import {
readCompose,
updateComposeImageTags,
writeCompose
} from "../utils/compose";
export const command = "increase [type]";
export const describe = "Increases the version defined in the manifest";
interface CliCommandOptions extends CliGlobalOptions {
type: string;
}
export const increase: CommandModule<CliGlobalOptions, CliCommandOptions> = {
command: "increase [type]",
describe: "Increases the version defined in the manifest",
builder: yargs =>
yargs.positional("type", {
description: "Semver update type: [ major | minor | patch ]",
choices: ["major", "minor", "patch"],
type: "string",
demandOption: true
}),
handler: async (args): Promise<void> => {
const nextVersion = await increaseHandler(args);
// Output result: "0.1.8"
console.log(nextVersion);
}
};
/**
* Common handler for CLI and programatic usage
*/
export async function increaseHandler({
type,
dir = defaultDir,
compose_file_name = defaultComposeFileName
}: CliCommandOptions): Promise<string> {
const composeFileName = compose_file_name;
// Load manifest
const { manifest, format } = readManifest({ dir });
const currentVersion = manifest.version;
// Increase the version
const nextVersion = semver.inc(currentVersion, type as ReleaseType);
if (!nextVersion) throw Error(`Invalid increase: ${currentVersion} ${type}`);
manifest.version = nextVersion;
// Mofidy and write the manifest and docker-compose
writeManifest(manifest, format, { dir });
const { name, version } = manifest;
const compose = readCompose({ dir, composeFileName });
const newCompose = updateComposeImageTags(compose, { name, version });
writeCompose(newCompose, { dir, composeFileName });
return nextVersion;
}