Skip to content

Commit 6fad7fc

Browse files
committed
Generalize package manager APM -> PM
1 parent d6ee783 commit 6fad7fc

21 files changed

+440
-500
lines changed

src/commands/increase.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { CommandModule } from "yargs";
2-
import { increaseFromLocalVersion } from "../utils/versions/increaseFromLocalVersion";
3-
import { CliGlobalOptions, ReleaseType } from "../types";
2+
import semver, { ReleaseType } from "semver";
3+
import { CliGlobalOptions } from "../types";
44
import { defaultComposeFileName, defaultDir } from "../params";
5+
import { readManifest, writeManifest } from "../utils/manifest";
6+
import {
7+
readCompose,
8+
updateComposeImageTags,
9+
writeCompose
10+
} from "../utils/compose";
511

612
export const command = "increase [type]";
713

@@ -38,9 +44,24 @@ export async function increaseHandler({
3844
dir = defaultDir,
3945
compose_file_name = defaultComposeFileName
4046
}: CliCommandOptions): Promise<string> {
41-
return await increaseFromLocalVersion({
42-
type: type as ReleaseType,
43-
dir,
44-
compose_file_name
45-
});
47+
const composeFileName = compose_file_name;
48+
49+
// Load manifest
50+
const { manifest, format } = readManifest({ dir });
51+
52+
const currentVersion = manifest.version;
53+
54+
// Increase the version
55+
const nextVersion = semver.inc(currentVersion, type as ReleaseType);
56+
if (!nextVersion) throw Error(`Invalid increase: ${currentVersion} ${type}`);
57+
manifest.version = nextVersion;
58+
59+
// Mofidy and write the manifest and docker-compose
60+
writeManifest(manifest, format, { dir });
61+
const { name, version } = manifest;
62+
const compose = readCompose({ dir, composeFileName });
63+
const newCompose = updateComposeImageTags(compose, { name, version });
64+
writeCompose(newCompose, { dir, composeFileName });
65+
66+
return nextVersion;
4667
}

src/commands/next.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { CommandModule } from "yargs";
2-
import { getNextVersionFromApm } from "../utils/versions/getNextVersionFromApm";
3-
import { verifyEthConnection } from "../utils/verifyEthConnection";
2+
import semver from "semver";
43
import { CliGlobalOptions, ReleaseType } from "../types";
54
import { defaultDir } from "../params";
5+
import { getPM, verifyEthConnection } from "../providers/pm";
6+
import { readManifest } from "../utils/manifest";
67

78
interface CliCommandOptions extends CliGlobalOptions {
89
type: string;
@@ -11,7 +12,7 @@ interface CliCommandOptions extends CliGlobalOptions {
1112

1213
export const next: CommandModule<CliGlobalOptions, CliCommandOptions> = {
1314
command: "next [type]",
14-
describe: "Compute the next release version from local",
15+
describe: "Compute the next release version from published repo",
1516

1617
builder: yargs =>
1718
yargs
@@ -45,12 +46,18 @@ export async function nextHandler({
4546
}: CliCommandOptions): Promise<string> {
4647
const ethProvider = provider;
4748

48-
await verifyEthConnection(ethProvider);
49+
const pm = getPM(ethProvider);
50+
await verifyEthConnection(pm);
51+
52+
const { manifest } = readManifest({ dir });
53+
const latestVersion = await pm.getLatestVersion(manifest.name);
54+
55+
const nextVersion = semver.inc(latestVersion, type as ReleaseType);
56+
if (!nextVersion)
57+
throw Error(
58+
`Error computing next version, is this increase type correct? type: ${type}`
59+
);
4960

5061
// Execute command
51-
return await getNextVersionFromApm({
52-
type: type as ReleaseType,
53-
ethProvider,
54-
dir
55-
});
62+
return nextVersion;
5663
}

src/commands/publish.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { buildAndUpload } from "../tasks/buildAndUpload";
77
import { generatePublishTx } from "../tasks/generatePublishTx";
88
import { createGithubRelease } from "../tasks/createGithubRelease";
99
// Utils
10-
import { getCurrentLocalVersion } from "../utils/versions/getCurrentLocalVersion";
11-
import { increaseFromApmVersion } from "../utils/versions/increaseFromApmVersion";
12-
import { verifyEthConnection } from "../utils/verifyEthConnection";
13-
import { getInstallDnpLink, getPublishTxLink } from "../utils/getLinks";
10+
import { increaseFromRemoteVersion } from "../utils/increaseFromRemoteVersion";
11+
import { getInstallDnpLink } from "../utils/getLinks";
1412
import { defaultComposeFileName, defaultDir, YargsError } from "../params";
1513
import { CliGlobalOptions, ReleaseType, releaseTypes, TxData } from "../types";
1614
import { printObject } from "../utils/print";
1715
import { UploadTo } from "../releaseUploader";
16+
import { getPM, verifyEthConnection } from "../providers/pm";
1817

1918
const typesList = releaseTypes.join(" | ");
2019

@@ -88,9 +87,12 @@ export const publish: CommandModule<CliGlobalOptions, CliCommandOptions> = {
8887
}),
8988

9089
handler: async args => {
91-
const { txData, nextVersion, releaseMultiHash } = await publishHanlder(
92-
args
93-
);
90+
const {
91+
txData,
92+
nextVersion,
93+
releaseMultiHash,
94+
txPublishLink
95+
} = await publishHanlder(args);
9496

9597
if (!args.silent) {
9698
const txDataToPrint = {
@@ -113,7 +115,7 @@ export const publish: CommandModule<CliGlobalOptions, CliCommandOptions> = {
113115
114116
${"You can also execute this transaction with Metamask by following this pre-filled link"}
115117
116-
${chalk.cyan(getPublishTxLink(txData))}
118+
${chalk.cyan(txPublishLink)}
117119
`);
118120
}
119121
}
@@ -143,6 +145,7 @@ export async function publishHanlder({
143145
txData: TxData;
144146
nextVersion: string;
145147
releaseMultiHash: string;
148+
txPublishLink: string;
146149
}> {
147150
// Parse optionsalias: "release",
148151
let ethProvider = provider || eth_provider;
@@ -195,27 +198,22 @@ export async function publishHanlder({
195198
`Invalid release type "${type}", must be: ${typesList}`
196199
);
197200

198-
await verifyEthConnection(ethProvider);
201+
const pm = getPM(ethProvider);
202+
await verifyEthConnection(pm);
199203

200204
const publishTasks = new Listr(
201205
[
202206
// 1. Fetch current version from APM
203207
{
204208
title: "Fetch current version from APM",
205209
task: async (ctx, task) => {
206-
let nextVersion;
207-
try {
208-
nextVersion = await increaseFromApmVersion({
209-
type: type as ReleaseType,
210-
ethProvider,
211-
dir,
212-
composeFileName
213-
});
214-
} catch (e) {
215-
if (e.message.includes("NOREPO"))
216-
nextVersion = getCurrentLocalVersion({ dir });
217-
else throw e;
218-
}
210+
const nextVersion = await increaseFromRemoteVersion({
211+
type: type as ReleaseType,
212+
pm,
213+
dir,
214+
composeFileName
215+
});
216+
219217
ctx.nextVersion = nextVersion;
220218
ctx.buildDir = path.join(dir, `build_${nextVersion}`);
221219
task.title = task.title + ` (next version: ${nextVersion})`;
@@ -276,6 +274,11 @@ export async function publishHanlder({
276274
);
277275

278276
const tasksFinalCtx = await publishTasks.run();
279-
const { txData, nextVersion, releaseMultiHash } = tasksFinalCtx;
280-
return { txData, nextVersion, releaseMultiHash };
277+
const {
278+
txData,
279+
nextVersion,
280+
releaseMultiHash,
281+
txPublishLink
282+
} = tasksFinalCtx;
283+
return { txData, nextVersion, releaseMultiHash, txPublishLink };
281284
}

0 commit comments

Comments
 (0)