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