Skip to content

Commit

Permalink
feat: print build info to console
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Apr 7, 2024
1 parent 6c7cbf3 commit 19ea288
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"prettier-plugin-tailwindcss": "^0.5.13",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.4",
"unplugin-info": "^1.1.0",
"vite": "^5.2.8"
},
"engines": {
Expand Down
116 changes: 116 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./app";
import "./print-build-info";

import { App } from "./app.tsx";
import "./globals.css";

ReactDOM.createRoot(document.getElementById("root")!).render(
Expand Down
22 changes: 22 additions & 0 deletions src/print-build-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isCI } from "~build/ci";
import { abbreviatedSha, github } from "~build/git";
import { name, version } from "~build/package";
import time from "~build/time";

const printBuildInfo = () => {
if (process.env.NODE_ENV === "development") {
return;
}
console.group("Build info");
console.log("Project:", name);
console.log("Build date:", time ? time.toLocaleString() : "Unknown");
console.log("Environment:", `${process.env.NODE_ENV}${isCI ? "(ci)" : ""}`);
console.log("Version:", `${version}-${abbreviatedSha}`);
console.log(
`${name} is an open source project, you can view its source code on Github!`,
);
console.log(`${github}/tree/${abbreviatedSha}`);
console.groupEnd();
};

printBuildInfo();
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="vite/client" />
/// <reference types="unplugin-info/client" />

// Polyfill for `showOpenFilePicker` API
// See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/wicg-file-system-access/index.d.ts
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import path from "path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import Info from "unplugin-info/vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), Info()],
base: "./",
resolve: {
alias: {
Expand Down

0 comments on commit 19ea288

Please sign in to comment.