Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion web/src/routes/version.json/+server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
import { json } from "@sveltejs/kit";
import { getCommit, getBranch, getRemote, getVersion } from "@imput/version-info";
import { exec } from "child_process";
import { promisify } from "util";

const execAsync = promisify(exec);

async function getCommit(): Promise<string> {
const { stdout } = await execAsync("git rev-parse HEAD");
return stdout.trim();
}

async function getBranch(): Promise<string> {
const { stdout } = await execAsync("git rev-parse --abbrev-ref HEAD");
return stdout.trim();
}

async function getRemote(): Promise<string> {
const { stdout } = await execAsync("git config --get remote.origin.url");
return stdout.trim();
}

async function getVersion(): Promise<string> {
const { stdout } = await execAsync("git describe --tags --always");
return stdout.trim();
}

export async function GET() {
return json({
Expand All @@ -11,3 +34,5 @@ export async function GET() {
}

export const prerender = true;