mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-09 17:28:58 +00:00
fix: fix some bug
This commit is contained in:
parent
f054bb799e
commit
44120e28b6
9 changed files with 298 additions and 57 deletions
27
bin/ocr.js
27
bin/ocr.js
|
|
@ -1,11 +1,36 @@
|
|||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const { spawnSync } = require("child_process");
|
||||
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(), ".open-code-review");
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue