From 39a5e91eebf153ded8c57e92cee9b93cee344e6b Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Wed, 23 Sep 2026 05:18:53 +0100 Subject: [PATCH] Add build info JSON file after builds --- bun.lock | 6 ++++++ dist/commands/build/index.js | 9 ++++++++- dist/types/index.d.ts | 5 +++++ dist/utils/grab-dir-names.d.ts | 1 + dist/utils/grab-dir-names.js | 2 ++ package.json | 6 ++++-- src/commands/build/index.ts | 16 +++++++++++++++- src/types/index.ts | 6 ++++++ src/utils/grab-dir-names.ts | 5 +++++ 9 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bun.lock b/bun.lock index b9eb893..c21fb2b 100644 --- a/bun.lock +++ b/bun.lock @@ -24,12 +24,14 @@ "react-dom": "^19.2.4", "tailwindcss": "^4.2.2", "typescript": "^5.0.0", + "uuid": "^14.0.2", }, "devDependencies": { "@testing-library/dom": "^10.4.1", "@types/chokidar": "^2.1.7", "@types/lodash": "^4.17.24", "@types/micromatch": "^4.0.10", + "@types/uuid": "^11.0.0", "happy-dom": "^20.8.4", }, }, @@ -179,6 +181,8 @@ "@types/react-dom": ["@types/react-dom@19.2.3", "", { "peerDependencies": { "@types/react": "^19.2.0" } }, "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ=="], + "@types/uuid": ["@types/uuid@11.0.0", "", { "dependencies": { "uuid": "*" } }, "sha512-HVyk8nj2m+jcFRNazzqyVKiZezyhDKrGUA3jlEcg/nZ6Ms+qHwocba1Y/AaVaznJTAM9xpdFSh+ptbNrhOGvZA=="], + "@types/whatwg-mimetype": ["@types/whatwg-mimetype@3.0.2", "", {}, "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA=="], "@types/ws": ["@types/ws@8.18.1", "", { "dependencies": { "@types/node": "*" } }, "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg=="], @@ -323,6 +327,8 @@ "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], + "uuid": ["uuid@14.0.2", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-xZe/16rV4aa+HGSOCiY2YeLT1OybRLrrkL/Rqaq7p7GMVXjFh+6wN4oMYgjFmnSnhY8t6Xpdl2l9qmnHYuMHwQ=="], + "whatwg-mimetype": ["whatwg-mimetype@3.0.0", "", {}, "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q=="], "ws": ["ws@8.19.0", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg=="], diff --git a/dist/commands/build/index.js b/dist/commands/build/index.js index e3d42b5..5658ad4 100644 --- a/dist/commands/build/index.js +++ b/dist/commands/build/index.js @@ -4,7 +4,8 @@ import grabDirNames from "../../utils/grab-dir-names"; import { rmSync, writeFileSync } from "fs"; import bunextInit from "../../functions/bunext-init"; import pagesSSRBundler from "../../functions/bundler/pages-ssr-bundler"; -const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, ROOT_DIR, } = grabDirNames(); +import { v4 } from "uuid"; +const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, BUILD_INFO_JSON, } = grabDirNames(); export default function () { return new Command("build") .description("Build Project") @@ -29,6 +30,12 @@ export default function () { let ssr_bundler_ctx_json_str = JSON.stringify(global.BUNEXT_SSR_BUNDLER_CTX_MAP); writeFileSync(SSR_BUNDLER_CTX_MAP_JSON, ssr_bundler_ctx_json_str, "utf-8"); } + const build_data = { + build_id: v4(), + build_date_unix: Date.now(), + build_date: Date(), + }; + writeFileSync(BUILD_INFO_JSON, JSON.stringify(build_data, null, 4), "utf-8"); log.success("Modules Built Successfully!"); process.exit(); }); diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts index 8f29fe5..e6ab379 100644 --- a/dist/types/index.d.ts +++ b/dist/types/index.d.ts @@ -356,3 +356,8 @@ export type BunextAPIRouteHandler & { cmd: string[]; }; +export type BuildDataType = { + build_id: string; + build_date_unix: number; + build_date: string; +}; diff --git a/dist/utils/grab-dir-names.d.ts b/dist/utils/grab-dir-names.d.ts index 19124a5..1dcd536 100644 --- a/dist/utils/grab-dir-names.d.ts +++ b/dist/utils/grab-dir-names.d.ts @@ -28,5 +28,6 @@ export type DirNames = { BUNX_LOGS_DIR: string; BUNDLER_CTX_MAP_JSON: string; SSR_BUNDLER_CTX_MAP_JSON: string; + BUILD_INFO_JSON: string; }; export default function grabDirNames(): DirNames; diff --git a/dist/utils/grab-dir-names.js b/dist/utils/grab-dir-names.js index 572a9e6..f2b0832 100644 --- a/dist/utils/grab-dir-names.js +++ b/dist/utils/grab-dir-names.js @@ -31,6 +31,7 @@ export default function grabDirNames() { const BUNX_ROOT_404_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_404_FILE_NAME}.tsx`); const BUNDLER_CTX_MAP_JSON = path.join(BUNX_CWD_DIR, "bundler-ctx-map.json"); const SSR_BUNDLER_CTX_MAP_JSON = path.join(BUNX_CWD_DIR, "ssr-bundler-ctx-map.json"); + const BUILD_INFO_JSON = path.join(BUNX_CWD_DIR, "build-info.json"); return { ROOT_DIR, SRC_DIR, @@ -61,6 +62,7 @@ export default function grabDirNames() { BUNX_LOGS_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, + BUILD_INFO_JSON, }; } // const NODE_MODULES_DIR = path.resolve( diff --git a/package.json b/package.json index c6ebb4d..b7adcf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/bunext", - "version": "1.1.12", + "version": "1.1.13", "main": "dist/index.js", "module": "index.ts", "dependencies": { @@ -22,13 +22,15 @@ "react": "^19.2.4", "react-dom": "^19.2.4", "tailwindcss": "^4.2.2", - "typescript": "^5.0.0" + "typescript": "^5.0.0", + "uuid": "^14.0.2" }, "devDependencies": { "@testing-library/dom": "^10.4.1", "@types/chokidar": "^2.1.7", "@types/lodash": "^4.17.24", "@types/micromatch": "^4.0.10", + "@types/uuid": "^11.0.0", "happy-dom": "^20.8.4" }, "exports": { diff --git a/src/commands/build/index.ts b/src/commands/build/index.ts index c4be43d..1ee2337 100644 --- a/src/commands/build/index.ts +++ b/src/commands/build/index.ts @@ -4,6 +4,8 @@ import grabDirNames from "../../utils/grab-dir-names"; import { rmSync, writeFileSync } from "fs"; import bunextInit from "../../functions/bunext-init"; import pagesSSRBundler from "../../functions/bundler/pages-ssr-bundler"; +import type { BuildDataType } from "../../types"; +import { v4 } from "uuid"; const { HYDRATION_DST_DIR, @@ -11,7 +13,7 @@ const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, - ROOT_DIR, + BUILD_INFO_JSON, } = grabDirNames(); export default function () { @@ -56,6 +58,18 @@ export default function () { ); } + const build_data: BuildDataType = { + build_id: v4(), + build_date_unix: Date.now(), + build_date: Date(), + }; + + writeFileSync( + BUILD_INFO_JSON, + JSON.stringify(build_data, null, 4), + "utf-8", + ); + log.success("Modules Built Successfully!"); process.exit(); diff --git a/src/types/index.ts b/src/types/index.ts index 1d8b55d..d1c4f26 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -424,3 +424,9 @@ export type BunSpawnOptions = Bun.SpawnOptions.SpawnOptions< > & { cmd: string[]; }; + +export type BuildDataType = { + build_id: string; + build_date_unix: number; + build_date: string; +}; diff --git a/src/utils/grab-dir-names.ts b/src/utils/grab-dir-names.ts index 98cddc2..3638b4b 100644 --- a/src/utils/grab-dir-names.ts +++ b/src/utils/grab-dir-names.ts @@ -30,6 +30,7 @@ export type DirNames = { BUNX_LOGS_DIR: string; BUNDLER_CTX_MAP_JSON: string; SSR_BUNDLER_CTX_MAP_JSON: string; + BUILD_INFO_JSON: string; }; export default function grabDirNames(): DirNames { @@ -90,11 +91,14 @@ export default function grabDirNames(): DirNames { BUNX_CWD_DIR, "bundler-ctx-map.json", ); + const SSR_BUNDLER_CTX_MAP_JSON = path.join( BUNX_CWD_DIR, "ssr-bundler-ctx-map.json", ); + const BUILD_INFO_JSON = path.join(BUNX_CWD_DIR, "build-info.json"); + return { ROOT_DIR, SRC_DIR, @@ -125,6 +129,7 @@ export default function grabDirNames(): DirNames { BUNX_LOGS_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, + BUILD_INFO_JSON, }; }