Skip to content

Commit c9e28e4

Browse files
authored
Merge pull request #5 from HumeAI/twitchard/better-cross-compat
Ship javascript, not binaries
2 parents afb2b0c + d8f6b8f commit c9e28e4

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@humeai/cli",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"module": "index.ts",
55
"type": "module",
66
"description": "CLI for Hume.ai's OCTAVE expressive TTS API",
@@ -18,22 +18,21 @@
1818
"typecheck": "tsc --noEmit",
1919
"format": "prettier --write \"**/*.{ts,js,json,md}\"",
2020
"format:check": "prettier --check \"**/*.{ts,js,json,md}\"",
21-
"prebuild": "bun build src/index.ts --compile --outfile dist/hume",
21+
"prebuild": "bun build src/index.ts --target node --outfile dist/index.js && chmod +x dist/index.js",
2222
"prepublishOnly": "npm run prebuild"
2323
},
2424
"dependencies": {
2525
"@clack/prompts": "^0.10.0",
26-
"bun": "^1.2.2",
2726
"clipanion": "^4.0.0-rc.4",
2827
"debug": "^4.4.0",
2928
"hume": "^0.10.3",
3029
"open": "^10.1.0",
3130
"typanion": "^3.14.0"
3231
},
3332
"files": [
34-
"dist/hume"
33+
"dist/index.js"
3534
],
3635
"bin": {
37-
"hume": "dist/hume"
36+
"hume": "dist/index.js"
3837
}
3938
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env node
12
import {
23
Cli,
34
Command as ClipanionBaseCommand,

src/play_audio.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { debug } from './common';
2+
import { spawnSync, spawn } from 'child_process';
23

34
type Command = {
45
cmd: string;
@@ -52,28 +53,38 @@ const findDefaultAudioPlayer_ = (): Command | null => {
5253
for (const player of commonPlayers) {
5354
const checkCmd = isWindows ? 'where' : 'which';
5455
try {
55-
Bun.spawnSync([checkCmd, player.cmd]);
56+
spawnSync(checkCmd, [player.cmd]);
5657
return player; // found!
5758
} catch {}
5859
}
5960

6061
return null;
6162
};
6263

63-
export const playAudioFile = async (
64-
path: string,
65-
customCommand: string | null
66-
): Promise<unknown> => {
64+
export const playAudioFile = async (path: string, customCommand: string | null) => {
6765
const command = ensureAudioPlayer(
6866
customCommand ? parseCustomCommand(customCommand) : findDefaultAudioPlayer()
6967
);
7068
const isWindows = process.platform === 'win32';
7169
const sanitizedPath = isWindows ? path.replace(/\\/g, '\\\\') : path;
7270

73-
return Bun.spawn([command.cmd, ...command.argsWithPath(sanitizedPath)], {
74-
stdout: 'ignore',
75-
stderr: 'ignore',
76-
}).exited;
71+
return new Promise<void>((resolve, reject) => {
72+
const process = spawn(command.cmd, [...command.argsWithPath(sanitizedPath)], {
73+
stdio: ['ignore', 'ignore', 'ignore'],
74+
});
75+
76+
process.on('close', (code: number) => {
77+
if (code === 0) {
78+
resolve();
79+
} else {
80+
reject(new Error(`Process exited with code ${code}`));
81+
}
82+
});
83+
84+
process.on('error', (err: any) => {
85+
reject(err);
86+
});
87+
});
7788
};
7889

7990
export const parseCustomCommand = (command: string): Command => {
@@ -114,17 +125,30 @@ export const withStdinAudioPlayer = async (
114125
const command = ensureStdinSupport(
115126
ensureAudioPlayer(customCommand ? parseCustomCommand(customCommand) : findDefaultAudioPlayer())
116127
);
117-
118128
debug([command.cmd, command.argsWithStdin]);
119-
const proc = Bun.spawn([command.cmd, ...command.argsWithStdin], {
120-
stdout: 'ignore',
121-
stderr: 'ignore',
122-
stdin: 'pipe',
129+
130+
const { spawn } = require('child_process');
131+
const proc = spawn(command.cmd, [...command.argsWithStdin], {
132+
stdio: ['pipe', 'ignore', 'ignore'],
123133
});
124134

125-
await f((audioBuffer: Buffer) => {
135+
await f((audioBuffer) => {
126136
proc.stdin.write(audioBuffer);
127137
});
138+
128139
proc.stdin.end();
129-
await proc.exited;
140+
141+
return new Promise((resolve, reject) => {
142+
proc.on('close', (code: number) => {
143+
if (code === 0) {
144+
resolve();
145+
} else {
146+
reject(new Error(`Process exited with code ${code}`));
147+
}
148+
});
149+
150+
proc.on('error', (err: any) => {
151+
reject(err);
152+
});
153+
});
130154
};

0 commit comments

Comments
 (0)