update git-check
This commit is contained in:
@@ -885,3 +885,7 @@ export function stringifySorted<T extends Record<string, any>>(
|
||||
return value;
|
||||
}, space);
|
||||
}
|
||||
|
||||
export function stringifyPretty(object: any): string {
|
||||
return JSON.stringify(object, null, 2);
|
||||
}
|
||||
|
||||
@@ -98,12 +98,12 @@
|
||||
},
|
||||
"git-check.ts": {
|
||||
"script_name": "git-check.ts",
|
||||
"script_length": 2683,
|
||||
"script_sha256": "1267cfdaeace4c5379caf5171be48b0769e5432de9fca9008379c1f0087ffa66",
|
||||
"script_length": 2543,
|
||||
"script_sha256": "88e15260ebcef098c737c49eb229adf3649da10bba69f757792fe1223d9b31cb",
|
||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/git-check.ts",
|
||||
"single_script_file": true,
|
||||
"publish_time": 1770541896791,
|
||||
"update_time": 1770542007498
|
||||
"update_time": 1770546895115
|
||||
},
|
||||
"helloworld-bun.ts": {
|
||||
"script_name": "helloworld-bun.ts",
|
||||
|
||||
@@ -6,22 +6,22 @@ import {
|
||||
log,
|
||||
ProcessBar,
|
||||
readFileToString,
|
||||
stringifyPretty,
|
||||
uint8ArrayToHexString,
|
||||
writeStringToFile,
|
||||
} from "https://script.hatter.ink/@29/deno-commons-mod.ts";
|
||||
} from "https://script.hatter.ink/@34/deno-commons-mod.ts";
|
||||
import {getGitLocalRev, getGitRemoteRev,} from "https://script.hatter.ink/@0/deno-git-mod.ts";
|
||||
|
||||
async function sha256OfString(input: string): Promise<string> {
|
||||
const data = new TextEncoder().encode(input);
|
||||
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join(
|
||||
"",
|
||||
);
|
||||
return uint8ArrayToHexString(new Uint8Array(hashBuffer));
|
||||
}
|
||||
|
||||
async function getPwd(): Promise<string> {
|
||||
const pwd = await execCommand("pwd");
|
||||
pwd.assertSuccess();
|
||||
return pwd.stdout.trim();
|
||||
return (await execCommand("pwd"))
|
||||
.assertSuccess()
|
||||
.stdout.trim();
|
||||
}
|
||||
|
||||
interface GitCheckCache {
|
||||
@@ -43,35 +43,28 @@ async function main() {
|
||||
if (gitCheckCache) {
|
||||
const timeBefore = Date.now() - gitCheckCache.lastCheckTime;
|
||||
if (timeBefore < 60 * 60 * 1000) {
|
||||
const lastCheckTime = new Date(gitCheckCache.lastCheckTime);
|
||||
const timeBeforeHuman = formatHumanTime(timeBefore);
|
||||
log.info(
|
||||
`Last check at ${new Date(
|
||||
gitCheckCache.lastCheckTime,
|
||||
)}, in ${
|
||||
formatHumanTime(timeBefore)
|
||||
}, skip check git remote rev`,
|
||||
`Last check at ${lastCheckTime}, in ${timeBeforeHuman}, skip check git remote rev`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const localRev = await getGitLocalRev();
|
||||
const remoteRev = await new ProcessBar("Checking rev").call(
|
||||
async (): Promise<string> => {
|
||||
return await getGitRemoteRev();
|
||||
},
|
||||
const remoteRev = await new ProcessBar("Checking remote rev").call(
|
||||
getGitRemoteRev,
|
||||
);
|
||||
if (localRev === remoteRev) {
|
||||
log.success(`Check rev successfully, rev: ${localRev}`);
|
||||
await writeStringToFile(
|
||||
gitCheckCacheFile,
|
||||
JSON.stringify(
|
||||
{
|
||||
const gitCheckCache: GitCheckCache = {
|
||||
path: pwd,
|
||||
lastCheckTime: Date.now(),
|
||||
} as GitCheckCache,
|
||||
null,
|
||||
2,
|
||||
),
|
||||
};
|
||||
await writeStringToFile(
|
||||
gitCheckCacheFile,
|
||||
stringifyPretty(gitCheckCache),
|
||||
);
|
||||
} else {
|
||||
log.error(
|
||||
@@ -83,5 +76,5 @@ async function main() {
|
||||
|
||||
await main();
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T171322+08:00.MEYCIQDvczD6qSfdlDkZCiN+
|
||||
// 9VKrEX6Fqd7/yZQLXjuWpOOX9AIhAIF/bVRRxFcawTy8DIt6G5Zxv3UqB82KgM0aQIAESMM5
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260208T183447+08:00.MEYCIQCizSoZCohVIszX24vf
|
||||
// kYa6qKDOpEBl0xwcMz8oY4U4wAIhAM0QzPVsFVZMO5379wA2nQdp0KrjDDzAr2zdd2kVMd7z
|
||||
|
||||
Reference in New Issue
Block a user