diff --git a/.changeset/bruno-build-info.md b/.changeset/bruno-build-info.md new file mode 100644 index 00000000..7e2b5ae6 --- /dev/null +++ b/.changeset/bruno-build-info.md @@ -0,0 +1,5 @@ +--- +"@usebruno/api-docs": patch +--- + +Expose the build's commit, branch, version and environment as `Bruno.build` in the browser console diff --git a/packages/bruno-api-docs/src/standalone.ts b/packages/bruno-api-docs/src/standalone.ts index 819ee546..2c0f3efb 100644 --- a/packages/bruno-api-docs/src/standalone.ts +++ b/packages/bruno-api-docs/src/standalone.ts @@ -121,6 +121,7 @@ if (typeof window !== 'undefined') { globals.OpenCollection = OpenCollectionRenderer; globals.Bruno = { ...globals.Bruno, + build: __BRUNO_BUILD__, apiDocs: (target: HTMLElement, { content, repositoryUrl, gitCollectionUrl, ...options }: ApiDocsOptions) => new OpenCollectionRenderer({ target, diff --git a/packages/bruno-api-docs/src/vite-env.d.ts b/packages/bruno-api-docs/src/vite-env.d.ts index f718c9a8..094fc6ac 100644 --- a/packages/bruno-api-docs/src/vite-env.d.ts +++ b/packages/bruno-api-docs/src/vite-env.d.ts @@ -1,5 +1,7 @@ /// +declare const __BRUNO_BUILD__: Record<'sha' | 'ref' | 'version' | 'env' | 'run' | 'built_at', string | null>; + declare module 'atob/node-atob' { const atob: (input: string) => string; export default atob; diff --git a/packages/bruno-api-docs/vite.config.standalone.ts b/packages/bruno-api-docs/vite.config.standalone.ts index 4684b3ab..40f8622a 100644 --- a/packages/bruno-api-docs/vite.config.standalone.ts +++ b/packages/bruno-api-docs/vite.config.standalone.ts @@ -5,6 +5,15 @@ import { fileURLToPath } from 'node:url'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); +const build = { + sha: process.env.BUILD_SHA ?? null, + ref: process.env.BUILD_REF ?? null, + version: process.env.BUILD_VERSION ?? null, + env: process.env.BUILD_ENV ?? null, + run: process.env.BUILD_RUN ?? null, + built_at: process.env.BUILD_TIME ?? null +}; + // https://vitejs.dev/config/ export default defineConfig({ resolve: { @@ -17,7 +26,8 @@ export default defineConfig({ react() ], define: { - 'process.env.NODE_ENV': '"production"' + 'process.env.NODE_ENV': '"production"', + '__BRUNO_BUILD__': JSON.stringify(build) }, build: { lib: {