@drakulavich/kesha-voice-kit 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli.ts +20 -1
- package/src/star.ts +57 -0
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { defineCommand, runMain } from "citty";
|
|
|
4
4
|
import { detect } from "tinyld";
|
|
5
5
|
import { transcribe } from "./lib";
|
|
6
6
|
import { downloadEngine } from "./engine-install";
|
|
7
|
-
import { detectAudioLanguageEngine, detectTextLanguageEngine } from "./engine";
|
|
7
|
+
import { detectAudioLanguageEngine, detectTextLanguageEngine, getEngineBinPath } from "./engine";
|
|
8
|
+
import { readStarSeen, shouldShowStarPrompt, writeStarSeen } from "./star";
|
|
8
9
|
import type { LangDetectResult } from "./engine";
|
|
9
10
|
import { log } from "./log";
|
|
10
11
|
import { say, SayError } from "./say";
|
|
@@ -50,6 +51,24 @@ function resolveBackendFlag(coreml: boolean, onnx: boolean): string | undefined
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
async function askForStar() {
|
|
54
|
+
// Gate on major-or-minor bump only — patch releases and re-installs of the
|
|
55
|
+
// same version shouldn't nag. First-ever install (no marker) still prompts.
|
|
56
|
+
const currentVersion = typeof pkg.version === "string" ? pkg.version : null;
|
|
57
|
+
if (!currentVersion) return;
|
|
58
|
+
const binPath = getEngineBinPath();
|
|
59
|
+
const seen = readStarSeen(binPath);
|
|
60
|
+
if (!shouldShowStarPrompt(currentVersion, seen)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Record the version up front so a single run never prompts twice, even
|
|
64
|
+
// if the gh subprocess below throws.
|
|
65
|
+
try {
|
|
66
|
+
writeStarSeen(binPath, currentVersion);
|
|
67
|
+
} catch {
|
|
68
|
+
// Non-fatal — falling through to the prompt is still OK, just means we
|
|
69
|
+
// may nag again on the next install if the write failed for IO reasons.
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
const gh = Bun.which("gh");
|
|
54
73
|
if (!gh) {
|
|
55
74
|
log.info("\nIf you enjoy Kesha Voice Kit, consider starring the repo:");
|
package/src/star.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Version-bump gate for the "star the repo" prompt in `kesha install`.
|
|
5
|
+
*
|
|
6
|
+
* Prompts are valuable on first install and on meaningful upgrades (new
|
|
7
|
+
* features) but annoying on patch-only bumps. This module persists the
|
|
8
|
+
* last-seen version to a marker file next to the engine binary and only
|
|
9
|
+
* returns true on a major-or-minor bump.
|
|
10
|
+
*/
|
|
11
|
+
export function starSeenPath(binPath: string): string {
|
|
12
|
+
return `${binPath}.star-seen`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function readStarSeen(binPath: string): string | null {
|
|
16
|
+
try {
|
|
17
|
+
const v = readFileSync(starSeenPath(binPath), "utf-8").trim();
|
|
18
|
+
return v.length > 0 ? v : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function writeStarSeen(binPath: string, version: string): void {
|
|
25
|
+
writeFileSync(starSeenPath(binPath), `${version}\n`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function parseMajorMinor(v: string): [number, number] | null {
|
|
29
|
+
const parts = v.split(".");
|
|
30
|
+
if (parts.length < 2) return null;
|
|
31
|
+
const major = Number(parts[0]);
|
|
32
|
+
const minor = Number(parts[1]);
|
|
33
|
+
if (!Number.isFinite(major) || !Number.isFinite(minor)) return null;
|
|
34
|
+
return [major, minor];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns true iff `current` represents a major-or-minor bump over `seen`.
|
|
39
|
+
* - `seen === null` → true (first install, always prompt once).
|
|
40
|
+
* - Same or downgraded version → false.
|
|
41
|
+
* - Patch-only bump → false (annoying on every install).
|
|
42
|
+
* - Unparseable either side → false (don't nag when we can't reason).
|
|
43
|
+
*/
|
|
44
|
+
export function shouldShowStarPrompt(current: string, seen: string | null): boolean {
|
|
45
|
+
if (seen === null) return true;
|
|
46
|
+
const c = parseMajorMinor(current);
|
|
47
|
+
const s = parseMajorMinor(seen);
|
|
48
|
+
if (!c || !s) return false;
|
|
49
|
+
if (c[0] > s[0]) return true;
|
|
50
|
+
if (c[0] === s[0] && c[1] > s[1]) return true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** True when a star-seen marker already exists for this install. */
|
|
55
|
+
export function hasStarMarker(binPath: string): boolean {
|
|
56
|
+
return existsSync(starSeenPath(binPath));
|
|
57
|
+
}
|