docs-i18n 0.6.1 → 0.6.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/dist/cli.js
CHANGED
|
@@ -4,7 +4,23 @@ import {
|
|
|
4
4
|
} from "./chunk-SKKZIV3L.js";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
|
+
import { existsSync, readFileSync } from "fs";
|
|
8
|
+
import { resolve } from "path";
|
|
7
9
|
import { createRequire } from "module";
|
|
10
|
+
var envPath = resolve(process.cwd(), ".env");
|
|
11
|
+
if (existsSync(envPath)) {
|
|
12
|
+
for (const line of readFileSync(envPath, "utf-8").split("\n")) {
|
|
13
|
+
const trimmed = line.trim();
|
|
14
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
15
|
+
const eq = trimmed.indexOf("=");
|
|
16
|
+
if (eq < 0) continue;
|
|
17
|
+
const key = trimmed.slice(0, eq).trim();
|
|
18
|
+
let val = trimmed.slice(eq + 1).trim();
|
|
19
|
+
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'"))
|
|
20
|
+
val = val.slice(1, -1);
|
|
21
|
+
if (!process.env[key]) process.env[key] = val;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
8
24
|
var args = process.argv.slice(2);
|
|
9
25
|
if (args[0] === "--version" || args[0] === "-v") {
|
|
10
26
|
const require2 = createRequire(import.meta.url);
|
|
@@ -56,7 +72,7 @@ Options:
|
|
|
56
72
|
console.error("Error: --lang is required");
|
|
57
73
|
process.exit(1);
|
|
58
74
|
}
|
|
59
|
-
const { translate } = await import("./translate-
|
|
75
|
+
const { translate } = await import("./translate-ZIVKNAC4.js");
|
|
60
76
|
await translate(config, {
|
|
61
77
|
lang,
|
|
62
78
|
project: getOpt("project") || void 0,
|
|
@@ -65,6 +81,7 @@ Options:
|
|
|
65
81
|
max: getOpt("max") ? Number(getOpt("max")) : void 0,
|
|
66
82
|
concurrency: getOpt("concurrency") ? Number(getOpt("concurrency")) : void 0,
|
|
67
83
|
dryRun: hasFlag("dry-run"),
|
|
84
|
+
apiKey: getOpt("api-key") || void 0,
|
|
68
85
|
model: getOpt("model") || void 0,
|
|
69
86
|
maxTokens: getOpt("max-tokens") ? Number(getOpt("max-tokens")) : void 0,
|
|
70
87
|
contextLength: getOpt("context-length") ? Number(getOpt("context-length")) : void 0
|
|
@@ -95,7 +112,7 @@ Options:
|
|
|
95
112
|
}
|
|
96
113
|
case "admin": {
|
|
97
114
|
const port = Number(getOpt("port", "3456"));
|
|
98
|
-
const { startAdmin } = await import("./server-
|
|
115
|
+
const { startAdmin } = await import("./server-73AVSOL5.js");
|
|
99
116
|
await startAdmin(config, port);
|
|
100
117
|
break;
|
|
101
118
|
}
|
|
@@ -164,6 +164,10 @@ import { streamSSE } from "hono/streaming";
|
|
|
164
164
|
import { spawn } from "child_process";
|
|
165
165
|
var PROJECT_ROOT = process.cwd();
|
|
166
166
|
var CLI_BIN = process.argv[1] ?? "docs-i18n";
|
|
167
|
+
var _config2;
|
|
168
|
+
function setConfig(config) {
|
|
169
|
+
_config2 = config;
|
|
170
|
+
}
|
|
167
171
|
var JobManager = class {
|
|
168
172
|
jobs = /* @__PURE__ */ new Map();
|
|
169
173
|
processes = /* @__PURE__ */ new Map();
|
|
@@ -204,6 +208,8 @@ var JobManager = class {
|
|
|
204
208
|
if (opts.project) args.push("--project", opts.project);
|
|
205
209
|
if (opts.model) args.push("--model", opts.model);
|
|
206
210
|
if (opts.files?.length) args.push("--files", opts.files.join(","));
|
|
211
|
+
const apiKey = _config2?.llm?.apiKey || process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY || "";
|
|
212
|
+
if (apiKey) args.push("--api-key", apiKey);
|
|
207
213
|
const proc = spawn(CLI_BIN, args, {
|
|
208
214
|
cwd: PROJECT_ROOT,
|
|
209
215
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -493,6 +499,7 @@ function loadVersion() {
|
|
|
493
499
|
var PKG_VERSION = loadVersion();
|
|
494
500
|
async function startAdmin(config, port = 3456) {
|
|
495
501
|
initStatus(config);
|
|
502
|
+
setConfig(config);
|
|
496
503
|
const app4 = new Hono4();
|
|
497
504
|
app4.get("/api/version", (c) => c.json({ version: PKG_VERSION }));
|
|
498
505
|
app4.route("/api/status", status_default);
|
|
@@ -591,7 +591,7 @@ async function translate(config, opts) {
|
|
|
591
591
|
const maxTokens = opts.maxTokens ?? llm.maxTokens ?? 16384;
|
|
592
592
|
const contextLength = opts.contextLength ?? llm.contextLength ?? 32768;
|
|
593
593
|
const model = opts.model ?? llm.model ?? "";
|
|
594
|
-
const apiKey = llm.apiKey ?? "";
|
|
594
|
+
const apiKey = opts.apiKey ?? llm.apiKey ?? "";
|
|
595
595
|
const apiType = llm.provider ?? "openrouter";
|
|
596
596
|
const docsContext = config.context ?? "";
|
|
597
597
|
for (const source of sources) {
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import { initStatus } from './services/status';
|
|
|
9
9
|
import jobRoutes from './routes/jobs';
|
|
10
10
|
import modelRoutes from './routes/models';
|
|
11
11
|
import statusRoutes from './routes/status';
|
|
12
|
+
import { setConfig } from './services/job-manager';
|
|
12
13
|
|
|
13
14
|
function loadVersion(): string {
|
|
14
15
|
try {
|
|
@@ -28,6 +29,7 @@ const PKG_VERSION = loadVersion();
|
|
|
28
29
|
|
|
29
30
|
export async function startAdmin(config: DocsI18nConfig, port = 3456) {
|
|
30
31
|
initStatus(config);
|
|
32
|
+
setConfig(config);
|
|
31
33
|
|
|
32
34
|
const app = new Hono();
|
|
33
35
|
app.get('/api/version', (c) => c.json({ version: PKG_VERSION }));
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { type ChildProcess, spawn } from 'node:child_process';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
+
import type { DocsI18nConfig } from '../../../config';
|
|
3
4
|
|
|
4
5
|
const PROJECT_ROOT = process.cwd();
|
|
5
6
|
// CLI binary path — reuse the same entry that started this process
|
|
6
7
|
const CLI_BIN = process.argv[1] ?? 'docs-i18n';
|
|
7
8
|
|
|
9
|
+
let _config: DocsI18nConfig | undefined;
|
|
10
|
+
export function setConfig(config: DocsI18nConfig) { _config = config; }
|
|
11
|
+
|
|
8
12
|
export interface Job {
|
|
9
13
|
id: string;
|
|
10
14
|
lang: string;
|
|
@@ -78,6 +82,10 @@ export class JobManager {
|
|
|
78
82
|
if (opts.model) args.push('--model', opts.model);
|
|
79
83
|
if (opts.files?.length) args.push('--files', opts.files.join(','));
|
|
80
84
|
|
|
85
|
+
// Pass API key explicitly — child process may not inherit .env
|
|
86
|
+
const apiKey = _config?.llm?.apiKey || process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY || '';
|
|
87
|
+
if (apiKey) args.push('--api-key', apiKey);
|
|
88
|
+
|
|
81
89
|
const proc = spawn(CLI_BIN, args, {
|
|
82
90
|
cwd: PROJECT_ROOT,
|
|
83
91
|
stdio: ['ignore', 'pipe', 'pipe'],
|