Add release to the footer
This commit is contained in:
parent
dde46dc5d1
commit
455898f3c9
5 changed files with 108 additions and 4 deletions
|
|
@ -1,6 +1,33 @@
|
|||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { sveltekit } from "@sveltejs/kit/vite";
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import { execSync } from "node:child_process";
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
function git(cmd: string): string {
|
||||
try {
|
||||
return execSync(`git ${cmd}`, { stdio: ["ignore", "pipe", "ignore"] })
|
||||
.toString()
|
||||
.trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Version comes from package.json; a build that is not exactly the tagged
|
||||
// release commit (or has local changes) carries the commit as build metadata,
|
||||
// e.g. 0.3.0+a1b2c3d or 0.3.0+a1b2c3d.dirty, so bug reports tell them apart.
|
||||
function version(): { version: string; commit: string } {
|
||||
const pkg = JSON.parse(readFileSync("package.json", "utf8"));
|
||||
const commit = git("rev-parse --short HEAD");
|
||||
const tagged = git("tag --points-at HEAD")
|
||||
.split("\n")
|
||||
.includes(`v${pkg.version}`);
|
||||
const dirty = git("status --porcelain --untracked-files=no") !== "";
|
||||
let v = pkg.version;
|
||||
if (commit && (!tagged || dirty)) v += `+${commit}${dirty ? ".dirty" : ""}`;
|
||||
return { version: v, commit };
|
||||
}
|
||||
|
||||
// PUBLIC_SSR is a build-time decision (it also picks the adapter in
|
||||
// svelte.config.js), so it is compiled in as a constant rather than read from
|
||||
|
|
@ -8,8 +35,13 @@ import { defineConfig, loadEnv } from "vite";
|
|||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), "PUBLIC_");
|
||||
const ssr = (process.env.PUBLIC_SSR ?? env.PUBLIC_SSR) === "yes";
|
||||
const build = version();
|
||||
return {
|
||||
plugins: [tailwindcss(), sveltekit()],
|
||||
define: { __SQUALK_SSR__: JSON.stringify(ssr) },
|
||||
define: {
|
||||
__SQUALK_SSR__: JSON.stringify(ssr),
|
||||
__SQUALK_VERSION__: JSON.stringify(build.version),
|
||||
__SQUALK_COMMIT__: JSON.stringify(build.commit),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue