code-baseline 1.6.0

Enforce architectural decisions AI coding tools keep ignoring
Documentation
#!/usr/bin/env node

const { spawnSync } = require("child_process");
const { existsSync, chmodSync, statSync } = require("fs");
const path = require("path");

const PLATFORMS = {
  "darwin-arm64": "@code-baseline/cli-darwin-arm64",
  "darwin-x64": "@code-baseline/cli-darwin-x64",
  "linux-x64": "@code-baseline/cli-linux-x64",
  "linux-arm64": "@code-baseline/cli-linux-arm64",
  "win32-x64": "@code-baseline/cli-win32-x64",
};

function getBinaryPath() {
  // Allow override via environment variable
  const override = process.env.BASELINE_BINARY;
  if (override) {
    return override;
  }

  const platformKey = `${process.platform}-${process.arch}`;
  const pkg = PLATFORMS[platformKey];

  if (!pkg) {
    console.error(
      `Unsupported platform: ${platformKey}\n` +
        `code-baseline does not ship a prebuilt binary for your platform.\n\n` +
        `You can install from source with:\n` +
        `  cargo install code-baseline\n`
    );
    process.exit(1);
  }

  const binaryName = process.platform === "win32" ? "baseline.exe" : "baseline";

  // Both packages live as siblings in the same node_modules directory
  // __dirname = .../node_modules/code-baseline/bin
  // sibling   = .../node_modules/<platform-pkg>/baseline
  const nodeModulesDir = path.resolve(__dirname, "..", "..");
  const binaryPath = path.join(nodeModulesDir, pkg, binaryName);

  if (existsSync(binaryPath)) {
    // Ensure the binary is executable (npm tarballs may not preserve permissions)
    if (process.platform !== "win32") {
      const mode = statSync(binaryPath).mode;
      if (!(mode & 0o111)) {
        chmodSync(binaryPath, mode | 0o755);
      }
    }
    return binaryPath;
  }

  console.error(
    `Could not find the binary for ${pkg}.\n` +
      `This usually means the optional dependency was not installed.\n\n` +
      `Try reinstalling:\n` +
      `  npm install -g code-baseline\n\n` +
      `Or install from source:\n` +
      `  cargo install code-baseline\n`
  );
  process.exit(1);
}

const binary = getBinaryPath();
const result = spawnSync(binary, process.argv.slice(2), {
  stdio: "inherit",
});

if (result.error) {
  console.error(`Failed to execute baseline: ${result.error.message}`);
  process.exit(1);
}

process.exit(result.status ?? 1);