Skip to content

Commit 100b141

Browse files
ankur0904vrcprl
andauthored
feat(cli): add --sound flag for task completion (#1157)
* feat(cli): add --sound flag for task completion * fix: address review comments * style: format code with prettier * chore: formatting * chore: changeset --------- Co-authored-by: Veronica Pril <veranika.prilutskaya@gmail.com>
1 parent 41ea851 commit 100b141

6 files changed

Lines changed: 63 additions & 1 deletion

File tree

.changeset/seven-papayas-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
add --sound flag for task completion

packages/cli/assets/failure.mp3

103 KB
Binary file not shown.

packages/cli/assets/success.mp3

34.7 KB
Binary file not shown.

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@
9898
},
9999
"files": [
100100
"bin",
101-
"build"
101+
"build",
102+
"assets"
102103
],
103104
"scripts": {
104105
"lingo.dev": "node --inspect=9229 ./bin/cli.mjs",

packages/cli/src/cli/cmd/run/_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export const flagsSchema = z.object({
4747
targetLocale: z.array(z.string()).optional(),
4848
watch: z.boolean().default(false),
4949
debounce: z.number().positive().default(5000), // 5 seconds default
50+
sound: z.boolean().optional(),
5051
});
5152
export type CmdRunFlags = z.infer<typeof flagsSchema>;

packages/cli/src/cli/cmd/run/index.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { Command } from "interactive-commander";
2+
import { exec } from "child_process";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
import os from "os";
26
import setup from "./setup";
37
import plan from "./plan";
48
import execute from "./execute";
@@ -15,6 +19,44 @@ import {
1519
import trackEvent from "../../utils/observability";
1620
import { determineAuthId } from "./_utils";
1721

22+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
23+
24+
function playSound(type: "success" | "failure") {
25+
const platform = os.platform();
26+
27+
return new Promise<void>((resolve) => {
28+
const assetDir = path.join(__dirname, "../assets");
29+
const soundFiles = [path.join(assetDir, `${type}.mp3`)];
30+
31+
let command = "";
32+
33+
if (platform === "linux") {
34+
command = soundFiles
35+
.map(
36+
(file) =>
37+
`mpg123 -q "${file}" 2>/dev/null || aplay "${file}" 2>/dev/null`,
38+
)
39+
.join(" || ");
40+
} else if (platform === "darwin") {
41+
command = soundFiles.map((file) => `afplay "${file}"`).join(" || ");
42+
} else if (platform === "win32") {
43+
command = `powershell -c "try { (New-Object Media.SoundPlayer '${soundFiles[1]}').PlaySync() } catch { Start-Process -FilePath '${soundFiles[0]}' -WindowStyle Hidden -Wait }"`;
44+
} else {
45+
command = soundFiles
46+
.map(
47+
(file) =>
48+
`aplay "${file}" 2>/dev/null || afplay "${file}" 2>/dev/null`,
49+
)
50+
.join(" || ");
51+
}
52+
53+
exec(command, () => {
54+
resolve();
55+
});
56+
setTimeout(resolve, 3000);
57+
});
58+
}
59+
1860
export default new Command()
1961
.command("run")
2062
.description("Run Lingo.dev localization engine")
@@ -69,6 +111,10 @@ export default new Command()
69111
"Debounce delay in milliseconds for watch mode (default: 5000ms)",
70112
(val: string) => parseInt(val),
71113
)
114+
.option(
115+
"--sound",
116+
"Play sound on completion, partially completion and failed of the task",
117+
)
72118
.action(async (args) => {
73119
let authId: string | null = null;
74120
try {
@@ -107,6 +153,11 @@ export default new Command()
107153
await renderSummary(ctx.results);
108154
await renderSpacer();
109155

156+
// Play sound after main tasks complete if sound flag is enabled
157+
if (ctx.flags.sound) {
158+
await playSound("success");
159+
}
160+
110161
// If watch mode is enabled, start watching for changes
111162
if (ctx.flags.watch) {
112163
await watch(ctx);
@@ -118,6 +169,10 @@ export default new Command()
118169
});
119170
} catch (error: any) {
120171
await trackEvent(authId || "unknown", "cmd.run.error", {});
172+
// Play sad sound if sound flag is enabled
173+
if (args.sound) {
174+
await playSound("failure");
175+
}
121176
throw error;
122177
}
123178
});

0 commit comments

Comments
 (0)