Skip to content

Commit

Permalink
chore: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Dec 29, 2024
1 parent c487bd5 commit cc32146
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 274 deletions.
69 changes: 3 additions & 66 deletions cli/helpers/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "path";
import { promises as fs } from "fs";
import { ZemVer } from "@zyrouge/zemver";
import { Paths } from "./paths";

export class Versioner {
Expand All @@ -17,14 +18,14 @@ export class Versioner {
if (!versionName) {
throw new Error("Unable to parse version name");
}
const version = Version.parse(versionName);
const version = ZemVer.parse(versionName);
if (version.code.toString() !== versionCode) {
throw new Error("Mismatching version code and version name");
}
return version;
}

static async updateVersion(version: Version) {
static async updateVersion(version: ZemVer) {
let content = (await fs.readFile(this.appBuildGradlePath)).toString();
content = content.replace(
this.versionCodeRegex,
Expand All @@ -37,67 +38,3 @@ export class Versioner {
await fs.writeFile(this.appBuildGradlePath, content);
}
}

export class Version {
constructor(
public readonly year: number,
public readonly month: number,
public readonly code: number,
public readonly prerelease?: string,
public readonly build?: string,
) {}

bump() {
const date = new Date();
return new Version(
date.getFullYear(),
date.getMonth() + 1,
this.code + 1,
this.prerelease,
);
}

bumpBuild() {
if (
typeof this.build === "string" &&
!Version.numericRegex.test(this.build)
) {
throw new Error("Build is not numeric");
}
return new Version(
this.year,
this.month,
this.code,
this.prerelease,
(parseInt(this.build ?? "0") + 1).toString(),
);
}

toString() {
let version = `${this.year}.${this.month}.${this.code}`;
if (this.prerelease) {
version += `-${this.prerelease}`;
}
if (this.build) {
version += `+${this.build}`;
}
return version;
}

static numericRegex = /^\d+$/;
static versionRegex =
/^(\d{4})\.(\d{1,2})\.(\d+)(?:\-([^+]+))?(?:\+(.+))?$/;

static parse(value: string) {
const match = value.match(this.versionRegex);
if (match === null) {
throw new Error("Unable to parse version");
}
const year = parseInt(match[1]!);
const month = parseInt(match[2]!);
const code = parseInt(match[3]!);
const prerelease = match[4];
const build = match[5];
return new Version(year, month, code, prerelease, build);
}
}
13 changes: 0 additions & 13 deletions cli/version/bump-build.ts

This file was deleted.

16 changes: 8 additions & 8 deletions cli/version/print-canary.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Git } from "../helpers/git";
import { Version, Versioner } from "../helpers/version";
import { Versioner } from "../helpers/version";

const main = async () => {
const pVersion = await Versioner.getVersion();
const sha = await Git.getLatestRevisionShort();
const time = await Git.getRevisionDate(sha);
const version = new Version(
time.getFullYear(),
time.getMonth() + 1,
pVersion.code + 1,
"canary",
sha,
);
const version = pVersion.copyWith({
year: time.getFullYear(),
month: time.getMonth() + 1,
code: pVersion.code + 1,
prerelease: "nightly",
build: sha,
});
console.log(version.toString());
};

Expand Down
16 changes: 8 additions & 8 deletions cli/version/print-nightly.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Git } from "../helpers/git";
import { Version, Versioner } from "../helpers/version";
import { Versioner } from "../helpers/version";

const main = async () => {
const pVersion = await Versioner.getVersion();
const sha = await Git.getLatestRevisionShort();
const time = await Git.getRevisionDate(sha);
const version = new Version(
time.getFullYear(),
time.getMonth() + 1,
pVersion.code + 1,
"nightly",
sha,
);
const version = pVersion.copyWith({
year: time.getFullYear(),
month: time.getMonth() + 1,
code: pVersion.code + 1,
prerelease: "nightly",
build: sha,
});
console.log(version.toString());
};

Expand Down
Loading

0 comments on commit cc32146

Please sign in to comment.