@vocasync/astro 0.1.0
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/README.md +580 -0
- package/dist/api/client.d.ts +77 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +223 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +257 -0
- package/dist/cli.js.map +1 -0
- package/dist/components/AudioPlayer.astro +1097 -0
- package/dist/components/index.d.ts +19 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/schema.d.ts +275 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +124 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/core/audio-map.d.ts +52 -0
- package/dist/core/audio-map.d.ts.map +1 -0
- package/dist/core/audio-map.js +97 -0
- package/dist/core/audio-map.js.map +1 -0
- package/dist/core/content-loader.d.ts +17 -0
- package/dist/core/content-loader.d.ts.map +1 -0
- package/dist/core/content-loader.js +141 -0
- package/dist/core/content-loader.js.map +1 -0
- package/dist/core/hash-manager.d.ts +16 -0
- package/dist/core/hash-manager.d.ts.map +1 -0
- package/dist/core/hash-manager.js +21 -0
- package/dist/core/hash-manager.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/speech-builder.d.ts +19 -0
- package/dist/core/speech-builder.d.ts.map +1 -0
- package/dist/core/speech-builder.js +252 -0
- package/dist/core/speech-builder.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +27 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +110 -0
- package/dist/integration.js.map +1 -0
- package/dist/lib/latex-to-speech/index.d.ts +26 -0
- package/dist/lib/latex-to-speech/index.d.ts.map +1 -0
- package/dist/lib/latex-to-speech/index.js +101 -0
- package/dist/lib/latex-to-speech/index.js.map +1 -0
- package/dist/rehype/audio-words.d.ts +50 -0
- package/dist/rehype/audio-words.d.ts.map +1 -0
- package/dist/rehype/audio-words.js +269 -0
- package/dist/rehype/audio-words.js.map +1 -0
- package/dist/rehype/index.d.ts +6 -0
- package/dist/rehype/index.d.ts.map +1 -0
- package/dist/rehype/index.js +4 -0
- package/dist/rehype/index.js.map +1 -0
- package/dist/rehype/rehype-math-speech.d.ts +18 -0
- package/dist/rehype/rehype-math-speech.d.ts.map +1 -0
- package/dist/rehype/rehype-math-speech.js +117 -0
- package/dist/rehype/rehype-math-speech.js.map +1 -0
- package/dist/rehype/remark-math-speech.d.ts +13 -0
- package/dist/rehype/remark-math-speech.d.ts.map +1 -0
- package/dist/rehype/remark-math-speech.js +26 -0
- package/dist/rehype/remark-math-speech.js.map +1 -0
- package/dist/styles/variables.css +181 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +2 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/orchestrator.d.ts +36 -0
- package/dist/sync/orchestrator.d.ts.map +1 -0
- package/dist/sync/orchestrator.js +166 -0
- package/dist/sync/orchestrator.js.map +1 -0
- package/dist/types/index.d.ts +196 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +89 -0
- package/src/api/client.ts +316 -0
- package/src/api/index.ts +1 -0
- package/src/cli.ts +301 -0
- package/src/components/AudioPlayer.astro +1097 -0
- package/src/components/index.ts +24 -0
- package/src/config/index.ts +30 -0
- package/src/config/schema.ts +177 -0
- package/src/core/audio-map.ts +107 -0
- package/src/core/content-loader.ts +171 -0
- package/src/core/hash-manager.ts +22 -0
- package/src/core/index.ts +12 -0
- package/src/core/speech-builder.ts +307 -0
- package/src/data/audio-map.example.json +19 -0
- package/src/env.d.ts +13 -0
- package/src/index.ts +67 -0
- package/src/integration.ts +123 -0
- package/src/lib/latex-to-speech/index.ts +126 -0
- package/src/rehype/audio-words.ts +345 -0
- package/src/rehype/index.ts +6 -0
- package/src/rehype/rehype-math-speech.ts +145 -0
- package/src/rehype/remark-math-speech.ts +31 -0
- package/src/styles/variables.css +181 -0
- package/src/sync/index.ts +2 -0
- package/src/sync/orchestrator.ts +239 -0
- package/src/types/index.ts +211 -0
- package/src/types/modules.d.ts +11 -0
package/src/cli.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { validateConfig, type VocaSyncUserConfig } from "./config/index.js";
|
|
7
|
+
import { createClient } from "./api/client.js";
|
|
8
|
+
import { sync, checkConfig } from "./sync/orchestrator.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load .env file manually (no external dependency)
|
|
12
|
+
*/
|
|
13
|
+
async function loadEnvFile(): Promise<void> {
|
|
14
|
+
const envPath = resolve(process.cwd(), ".env");
|
|
15
|
+
if (!existsSync(envPath)) return;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const content = await readFile(envPath, "utf-8");
|
|
19
|
+
for (const line of content.split("\n")) {
|
|
20
|
+
const trimmed = line.trim();
|
|
21
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
22
|
+
|
|
23
|
+
const eqIndex = trimmed.indexOf("=");
|
|
24
|
+
if (eqIndex === -1) continue;
|
|
25
|
+
|
|
26
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
27
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
28
|
+
|
|
29
|
+
// Remove quotes if present
|
|
30
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
31
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
32
|
+
value = value.slice(1, -1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Don't override existing env vars
|
|
36
|
+
if (!(key in process.env)) {
|
|
37
|
+
process.env[key] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// Ignore errors reading .env
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* ANSI color codes for terminal output
|
|
47
|
+
*/
|
|
48
|
+
const colors = {
|
|
49
|
+
reset: "\x1b[0m",
|
|
50
|
+
red: "\x1b[31m",
|
|
51
|
+
green: "\x1b[32m",
|
|
52
|
+
yellow: "\x1b[33m",
|
|
53
|
+
blue: "\x1b[34m",
|
|
54
|
+
cyan: "\x1b[36m",
|
|
55
|
+
dim: "\x1b[2m",
|
|
56
|
+
bold: "\x1b[1m",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function log(message: string, type: "info" | "success" | "warn" | "error" = "info"): void {
|
|
60
|
+
const colorMap = {
|
|
61
|
+
info: colors.cyan,
|
|
62
|
+
success: colors.green,
|
|
63
|
+
warn: colors.yellow,
|
|
64
|
+
error: colors.red,
|
|
65
|
+
};
|
|
66
|
+
console.log(`${colorMap[type]}${message}${colors.reset}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function printBanner(): void {
|
|
70
|
+
console.log(`
|
|
71
|
+
${colors.cyan}${colors.bold}╭────────────────────────────────────────╮
|
|
72
|
+
│ @vocasync/astro │
|
|
73
|
+
│ Text-to-Speech for Astro Sites │
|
|
74
|
+
╰────────────────────────────────────────╯${colors.reset}
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function printHelp(): void {
|
|
79
|
+
console.log(`
|
|
80
|
+
${colors.bold}Usage:${colors.reset}
|
|
81
|
+
vocasync <command> [options]
|
|
82
|
+
|
|
83
|
+
${colors.bold}Commands:${colors.reset}
|
|
84
|
+
sync Synthesize and align content
|
|
85
|
+
check Validate configuration
|
|
86
|
+
status <id> Check job status
|
|
87
|
+
help Show this help
|
|
88
|
+
|
|
89
|
+
${colors.bold}Options:${colors.reset}
|
|
90
|
+
--only <slug> Only process specific slug
|
|
91
|
+
--force Force reprocessing
|
|
92
|
+
--dry-run Preview without API calls
|
|
93
|
+
--config <path> Config file path
|
|
94
|
+
|
|
95
|
+
${colors.bold}Environment:${colors.reset}
|
|
96
|
+
VOCASYNC_API_KEY Your VocaSync API key
|
|
97
|
+
|
|
98
|
+
${colors.bold}Examples:${colors.reset}
|
|
99
|
+
${colors.dim}# Sync all content${colors.reset}
|
|
100
|
+
npx vocasync sync
|
|
101
|
+
|
|
102
|
+
${colors.dim}# Sync single post${colors.reset}
|
|
103
|
+
npx vocasync sync --only my-post
|
|
104
|
+
|
|
105
|
+
${colors.dim}# Check configuration${colors.reset}
|
|
106
|
+
npx vocasync check
|
|
107
|
+
`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Parse command line arguments.
|
|
112
|
+
*/
|
|
113
|
+
function parseArgs(args: string[]): {
|
|
114
|
+
command: string;
|
|
115
|
+
options: Record<string, string | boolean>;
|
|
116
|
+
positional: string[];
|
|
117
|
+
} {
|
|
118
|
+
const options: Record<string, string | boolean> = {};
|
|
119
|
+
const positional: string[] = [];
|
|
120
|
+
let command = "";
|
|
121
|
+
|
|
122
|
+
for (let i = 0; i < args.length; i++) {
|
|
123
|
+
const arg = args[i];
|
|
124
|
+
|
|
125
|
+
if (arg.startsWith("--")) {
|
|
126
|
+
const key = arg.slice(2);
|
|
127
|
+
const nextArg = args[i + 1];
|
|
128
|
+
|
|
129
|
+
// Check if next arg is a value or another flag
|
|
130
|
+
if (nextArg && !nextArg.startsWith("--")) {
|
|
131
|
+
options[key] = nextArg;
|
|
132
|
+
i++;
|
|
133
|
+
} else {
|
|
134
|
+
options[key] = true;
|
|
135
|
+
}
|
|
136
|
+
} else if (!command) {
|
|
137
|
+
command = arg;
|
|
138
|
+
} else {
|
|
139
|
+
positional.push(arg);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { command, options, positional };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Load configuration from vocasync.config.ts/js/mjs.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* // vocasync.config.mjs
|
|
152
|
+
* export default {
|
|
153
|
+
* collection: { name: "articles", path: "./src/content/articles" },
|
|
154
|
+
* voice: { id: "aura-asteria-en", provider: "deepgram" },
|
|
155
|
+
* };
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
async function loadConfig(configPath?: string): Promise<VocaSyncUserConfig> {
|
|
159
|
+
const cwd = process.cwd();
|
|
160
|
+
|
|
161
|
+
// Try explicit config path first
|
|
162
|
+
if (configPath) {
|
|
163
|
+
const fullPath = resolve(cwd, configPath);
|
|
164
|
+
return loadConfigFile(fullPath);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Try vocasync.config.ts / .mjs / .js
|
|
168
|
+
for (const ext of [".ts", ".mjs", ".js"]) {
|
|
169
|
+
const configFile = resolve(cwd, `vocasync.config${ext}`);
|
|
170
|
+
if (existsSync(configFile)) {
|
|
171
|
+
return await loadConfigFile(configFile);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
throw new Error(
|
|
176
|
+
"No VocaSync configuration found.\n" +
|
|
177
|
+
"Create a vocasync.config.mjs file with your configuration."
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Load and execute a config file.
|
|
183
|
+
* Uses file:// URLs for proper ESM import resolution.
|
|
184
|
+
*/
|
|
185
|
+
async function loadConfigFile(filePath: string): Promise<VocaSyncUserConfig> {
|
|
186
|
+
try {
|
|
187
|
+
// Use file:// URL for proper ESM resolution
|
|
188
|
+
const fileUrl = `file://${filePath}`;
|
|
189
|
+
const module = await import(fileUrl);
|
|
190
|
+
return (module.default || module) as VocaSyncUserConfig;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new Error(`Failed to load config from ${filePath}: ${error}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Main CLI entry point.
|
|
198
|
+
*/
|
|
199
|
+
async function main(): Promise<void> {
|
|
200
|
+
// Load .env file before anything else
|
|
201
|
+
await loadEnvFile();
|
|
202
|
+
|
|
203
|
+
const args = process.argv.slice(2);
|
|
204
|
+
const { command, options, positional } = parseArgs(args);
|
|
205
|
+
|
|
206
|
+
// Handle help
|
|
207
|
+
if (!command || command === "help" || options.help) {
|
|
208
|
+
printBanner();
|
|
209
|
+
printHelp();
|
|
210
|
+
process.exit(0);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
printBanner();
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
// Load configuration
|
|
217
|
+
const userConfig = await loadConfig(options.config as string | undefined);
|
|
218
|
+
const config = validateConfig(userConfig);
|
|
219
|
+
const client = createClient(config);
|
|
220
|
+
|
|
221
|
+
switch (command) {
|
|
222
|
+
case "sync": {
|
|
223
|
+
log("Starting sync...", "info");
|
|
224
|
+
|
|
225
|
+
const summary = await sync(config, client, {
|
|
226
|
+
only: options.only as string | undefined,
|
|
227
|
+
force: Boolean(options.force),
|
|
228
|
+
dryRun: Boolean(options["dry-run"]),
|
|
229
|
+
onProgress: log,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
console.log("");
|
|
233
|
+
log(
|
|
234
|
+
`Sync complete: ${summary.synced} synced, ${summary.unchanged} unchanged, ${summary.errors} errors`,
|
|
235
|
+
summary.errors > 0 ? "warn" : "success"
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
process.exit(summary.errors > 0 ? 1 : 0);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
case "check": {
|
|
243
|
+
log("Checking configuration...", "info");
|
|
244
|
+
|
|
245
|
+
const result = await checkConfig(config, client);
|
|
246
|
+
|
|
247
|
+
if (result.valid) {
|
|
248
|
+
log(result.message, "success");
|
|
249
|
+
process.exit(0);
|
|
250
|
+
} else {
|
|
251
|
+
log(result.message, "error");
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case "status": {
|
|
258
|
+
const projectId = positional[0];
|
|
259
|
+
if (!projectId) {
|
|
260
|
+
log("Usage: vocasync status <projectUuid>", "error");
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
log(`Checking status for ${projectId}...`, "info");
|
|
265
|
+
const status = await client.getProjectStatus(projectId);
|
|
266
|
+
|
|
267
|
+
console.log("");
|
|
268
|
+
console.log(`${colors.bold}Project:${colors.reset} ${status.uuid}`);
|
|
269
|
+
console.log(`${colors.bold}Name:${colors.reset} ${status.name}`);
|
|
270
|
+
console.log(
|
|
271
|
+
`${colors.bold}Synthesis:${colors.reset} ${status.synthesisJob?.status || "N/A"}`
|
|
272
|
+
);
|
|
273
|
+
console.log(
|
|
274
|
+
`${colors.bold}Alignment:${colors.reset} ${status.alignmentJob?.status || "N/A"}`
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
if (status.synthesisJob?.audioUrl) {
|
|
278
|
+
console.log(`${colors.bold}Audio:${colors.reset} ${status.synthesisJob.audioUrl}`);
|
|
279
|
+
}
|
|
280
|
+
if (status.alignmentJob?.alignmentUrl) {
|
|
281
|
+
console.log(
|
|
282
|
+
`${colors.bold}Alignment:${colors.reset} ${status.alignmentJob.alignmentUrl}`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
process.exit(0);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
default:
|
|
291
|
+
log(`Unknown command: ${command}`, "error");
|
|
292
|
+
printHelp();
|
|
293
|
+
process.exit(1);
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
log(error instanceof Error ? error.message : String(error), "error");
|
|
297
|
+
process.exit(1);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
main();
|