Skip to content

Commit

Permalink
feat: log copyright and build date to console
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiZapic committed Mar 27, 2024
1 parent 8211aca commit d64b2be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@ async function init() {
}

document.addEventListener("DOMContentLoaded", () => initOnce());

console.log(
`%c Matecho %c By Zapic \n`,
"color: #fff; background: #E91E63; padding:5px 0;",
"background: #efefef; padding:5px 0;",
`${__BUILD_COMMIT_ID__} @ ${__BUILD_DATE__} `
);
3 changes: 3 additions & 0 deletions src/matecho.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ declare global {
declare interface Window {
__MATECHO_ANTI_SPAM__: string;
}

declare const __BUILD_DATE__: string;
declare const __BUILD_COMMIT_ID__: string;
16 changes: 16 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ import fg from "fast-glob";
import Matecho from "./plugins/Matecho";
import PrismJS from "./plugins/Prism";
import UnoCSSClassMangle from "./plugins/UnoCSSClassMangle";
import fs from "node:fs";

export default defineConfig(async env => {
const isProd = env.mode === "production";
let COMMIT_ID = "unknown";
try {
const id = fs
.readFileSync(__dirname + "/.git/HEAD")
.toString("utf-8")
.trim();
console.log("Current head @ " + id);
COMMIT_ID = id.startsWith("ref:") ? id : id.substring(0, 7);
} catch (_) {
/**/
}

return {
plugins: [
Expand Down Expand Up @@ -52,6 +64,10 @@ export default defineConfig(async env => {
minify: isProd,
cssMinify: isProd
},
define: {
__BUILD_DATE__: JSON.stringify(new Date().toString()),
__BUILD_COMMIT_ID__: JSON.stringify(COMMIT_ID)
},
base: "/__VIRTUAL_THEME_ROOT__"
} as UserConfig;
});

0 comments on commit d64b2be

Please sign in to comment.