update commit.ts
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env runts -- --runtime-bun
|
#!/usr/bin/env runts -- --runtime-bun
|
||||||
|
|
||||||
import {spawn} from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
import {existsSync} from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import {createInterface} from "node:readline/promises";
|
import { createInterface } from "node:readline/promises";
|
||||||
import {stdin, stdout} from "node:process";
|
import { stdin, stdout } from "node:process";
|
||||||
|
|
||||||
class ProcessOutput {
|
class ProcessOutput {
|
||||||
code: number;
|
code: number;
|
||||||
@@ -72,7 +72,7 @@ async function execCommandShell(
|
|||||||
args: string[],
|
args: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const ps = spawn(command, args, {
|
const ps = spawn(command, args, {
|
||||||
shell: true,
|
// shell: true,
|
||||||
stdio: ["inherit", "inherit", "inherit"],
|
stdio: ["inherit", "inherit", "inherit"],
|
||||||
});
|
});
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -229,6 +229,14 @@ class ProcessBar {
|
|||||||
constructor(message?: string) {
|
constructor(message?: string) {
|
||||||
this.message = message || "Processing";
|
this.message = message || "Processing";
|
||||||
}
|
}
|
||||||
|
async call<T>(cb: () => Promise<T>, clearLine?: boolean): Promise<T> {
|
||||||
|
this.start();
|
||||||
|
try {
|
||||||
|
return await cb();
|
||||||
|
} finally {
|
||||||
|
this.stop(clearLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
start(): void {
|
start(): void {
|
||||||
const startMs = new Date().getTime();
|
const startMs = new Date().getTime();
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@@ -251,11 +259,12 @@ class ProcessBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkRev(): Promise<boolean> {
|
async function checkRev(): Promise<boolean> {
|
||||||
const processBar = new ProcessBar("Checking rev");
|
|
||||||
processBar.start();
|
|
||||||
const localRev = await getGitLocalRev();
|
const localRev = await getGitLocalRev();
|
||||||
const remoteRev = await getGitRemoteRev();
|
const remoteRev = await new ProcessBar("Checking rev").call(
|
||||||
processBar.stop();
|
async (): Promise<string> => {
|
||||||
|
return await getGitRemoteRev();
|
||||||
|
},
|
||||||
|
);
|
||||||
if (localRev === remoteRev) {
|
if (localRev === remoteRev) {
|
||||||
console.log(`Check rev successfully, rev: ${localRev}`);
|
console.log(`Check rev successfully, rev: ${localRev}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -263,10 +272,6 @@ async function checkRev(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sleep(ms: number): Promise<void> {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await checkRev(); // check local rev <--> remote rev equals
|
await checkRev(); // check local rev <--> remote rev equals
|
||||||
const gitStatus = await getGitStatus();
|
const gitStatus = await getGitStatus();
|
||||||
@@ -285,7 +290,7 @@ async function main() {
|
|||||||
console.log("Too many empty messages, then exit");
|
console.log("Too many empty messages, then exit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
message = await readline.question("Input your commit message> ");
|
message = await readline.question("Input your commit message > ");
|
||||||
} while (message.length == 0);
|
} while (message.length == 0);
|
||||||
readline.close();
|
readline.close();
|
||||||
|
|
||||||
@@ -303,10 +308,12 @@ async function main() {
|
|||||||
gitCommitArgs.push("-m");
|
gitCommitArgs.push("-m");
|
||||||
gitCommitArgs.push(message);
|
gitCommitArgs.push(message);
|
||||||
|
|
||||||
console.log("Git command: ", "git", gitCommitArgs);
|
console.log("[COMMAND] Git command: ", "git", gitCommitArgs);
|
||||||
await execCommandShell("git", gitCommitArgs);
|
await execCommandShell("git", gitCommitArgs);
|
||||||
console.log("Git push");
|
console.log("[COMMAND] Git push");
|
||||||
await execCommandShell("git", ["push"]);
|
await new ProcessBar("Git pushing").call(async (): Promise<void> => {
|
||||||
|
await execCommandShell("git", ["push"]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
@@ -314,5 +321,5 @@ main().catch((err) => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}).then(() => process.exit(0));
|
}).then(() => process.exit(0));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260125T125926+08:00.MEYCIQDyxV26TTjKJCjDH1Pb
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260125T131632+08:00.MEUCIQDEukVWncbkfee1cb9A
|
||||||
// s36IR6JZ4biD/G27wdrxtnQQYQIhAMVSIGkLWOd8dASIayCKeZ0UlfYJN3rercqJKqzRf0Cm
|
// nU0VP5F161xUX/x/fe8IZgb8nwIgHDtOaAzZ2UcjbJ13tD5BgsE+dfk5ifXaKjuYxdQxZGY=
|
||||||
|
|||||||
Reference in New Issue
Block a user