Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

695 B
Raw Blame
import { execFileSync } from 'node:child_process';

export const git = (...args: string[]): string =>
  execFileSync('git', args, {
    encoding: 'utf8',
    maxBuffer: 256 * 1024 * 1024,
    // Expected misses (no earlier tag) would otherwise print "fatal: ..." into CI logs.
    stdio: ['ignore', 'pipe', 'pipe'],
  }).trim();

// Absent refs are normal here (no earlier tag), so they return null rather than throw.
export const gitOrNull = (...args: string[]): string | null => {
  try {
    return git(...args);
  } catch {
    return null;
  }
};

export const lines = (text: string | null): string[] =>
  (text ?? '')
    .split('\n')
    .map((line) => line.trim())
    .filter(Boolean);