All files / web/scripts generate-build-info.js

0% Statements 0/63
0% Branches 0/1
0% Functions 0/1
0% Lines 0/63

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
#!/usr/bin/env node

/**
 * Generate build information for deployment tracking
 * This script captures git commit, branch, timestamp, and other metadata
 */

const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')

function exec(command) {
  try {
    return execSync(command, { encoding: 'utf-8' }).trim()
  } catch (_error) {
    return null
  }
}

function getBuildInfo() {
  // Try to get git info from environment variables first (for Docker builds)
  // Fall back to git commands (for local development)
  const gitCommit = process.env.GIT_COMMIT || exec('git rev-parse HEAD')
  const gitCommitShort = process.env.GIT_COMMIT_SHORT || exec('git rev-parse --short HEAD')
  const gitBranch = process.env.GIT_BRANCH || exec('git rev-parse --abbrev-ref HEAD')
  const gitTag = process.env.GIT_TAG || exec('git describe --tags --exact-match 2>/dev/null')
  const gitDirty =
    process.env.GIT_DIRTY !== undefined
      ? process.env.GIT_DIRTY === 'true'
      : exec('git diff --quiet || echo "dirty"') === 'dirty'

  const packageJson = require('../package.json')

  return {
    version: packageJson.version,
    buildTime: new Date().toISOString(),
    buildTimestamp: Date.now(),
    git: {
      commit: gitCommit,
      commitShort: gitCommitShort,
      branch: gitBranch,
      tag: gitTag,
      isDirty: gitDirty,
    },
    environment: process.env.NODE_ENV || 'development',
    buildNumber: process.env.BUILD_NUMBER || null,
    nodeVersion: process.version,
  }
}

const buildInfo = getBuildInfo()
const outputPath = path.join(__dirname, '..', 'src', 'generated', 'build-info.json')

// Ensure directory exists
const dir = path.dirname(outputPath)
if (!fs.existsSync(dir)) {
  fs.mkdirSync(dir, { recursive: true })
}

fs.writeFileSync(outputPath, JSON.stringify(buildInfo, null, 2))

console.log('✅ Build info generated:', outputPath)
console.log(JSON.stringify(buildInfo, null, 2))