open-code-review/bin/ocr.js
kite 5053e6dca8 refactor(config): rename config directory from .open-code-review to .opencodereview
Unify the config folder name to `.opencodereview` across all runtime paths,
  tests, docs, and i18n strings. Also make defaultConfigPath() return an error
  instead of silently falling back to a current-directory file when $HOME is
  unresolvable.
2026-05-25 23:07:36 +08:00

39 lines
1.1 KiB
JavaScript
Executable file

#!/usr/bin/env node
"use strict";
const { spawnSync, spawn } = require("child_process");
const path = require("path");
const fs = require("fs");
const os = require("os");
const binaryPath = path.join(__dirname, "opencodereview");
if (!process.env.OCR_NO_UPDATE) {
const stateDir = path.join(os.homedir(), ".opencodereview");
const tsFile = path.join(stateDir, "last-update-check");
const cooldownMs =
(parseInt(process.env.OCR_UPDATE_INTERVAL, 10) || 60) * 60 * 1000;
let shouldCheck = true;
try {
const mt = fs.statSync(tsFile).mtimeMs;
if (Date.now() - mt < cooldownMs) shouldCheck = false;
} catch (_) {}
if (shouldCheck) {
const updateScript = path.join(__dirname, "..", "scripts", "update.js");
const child = spawn(process.execPath, [updateScript], {
detached: true,
stdio: "ignore",
env: Object.assign({}, process.env, { OCR_NO_UPDATE: "1" }),
});
child.unref();
}
}
const result = spawnSync(binaryPath, process.argv.slice(2), {
stdio: "inherit",
env: process.env,
});
process.exit(result.status ?? (result.error ? 1 : 0));