docs-i18n 0.6.0 → 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-DHRWBIXV.js");
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-AD5PLHI5.js");
115
+ const { startAdmin } = await import("./server-73AVSOL5.js");
99
116
  await startAdmin(config, port);
100
117
  break;
101
118
  }
@@ -12,8 +12,9 @@ import {
12
12
  // src/admin/server/index.ts
13
13
  import { spawn as nodeSpawn } from "child_process";
14
14
  import { createServer } from "http";
15
- import { createRequire } from "module";
16
- import { resolve as resolve2 } from "path";
15
+ import { readFileSync as readFileSync2 } from "fs";
16
+ import { resolve as resolve2, dirname } from "path";
17
+ import { fileURLToPath } from "url";
17
18
  import { Hono as Hono4 } from "hono";
18
19
 
19
20
  // src/admin/server/services/status.ts
@@ -163,6 +164,10 @@ import { streamSSE } from "hono/streaming";
163
164
  import { spawn } from "child_process";
164
165
  var PROJECT_ROOT = process.cwd();
165
166
  var CLI_BIN = process.argv[1] ?? "docs-i18n";
167
+ var _config2;
168
+ function setConfig(config) {
169
+ _config2 = config;
170
+ }
166
171
  var JobManager = class {
167
172
  jobs = /* @__PURE__ */ new Map();
168
173
  processes = /* @__PURE__ */ new Map();
@@ -203,6 +208,8 @@ var JobManager = class {
203
208
  if (opts.project) args.push("--project", opts.project);
204
209
  if (opts.model) args.push("--model", opts.model);
205
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);
206
213
  const proc = spawn(CLI_BIN, args, {
207
214
  cwd: PROJECT_ROOT,
208
215
  stdio: ["ignore", "pipe", "pipe"],
@@ -474,12 +481,27 @@ app3.post("/:version/rescan", (c) => {
474
481
  var status_default = app3;
475
482
 
476
483
  // src/admin/server/index.ts
477
- var require2 = createRequire(import.meta.url);
478
- var pkg = require2("../../../package.json");
484
+ function loadVersion() {
485
+ try {
486
+ let dir = dirname(fileURLToPath(import.meta.url));
487
+ for (let i = 0; i < 5; i++) {
488
+ try {
489
+ const pkg = JSON.parse(readFileSync2(resolve2(dir, "package.json"), "utf-8"));
490
+ if (pkg.name === "docs-i18n") return pkg.version;
491
+ } catch {
492
+ }
493
+ dir = dirname(dir);
494
+ }
495
+ } catch {
496
+ }
497
+ return "unknown";
498
+ }
499
+ var PKG_VERSION = loadVersion();
479
500
  async function startAdmin(config, port = 3456) {
480
501
  initStatus(config);
502
+ setConfig(config);
481
503
  const app4 = new Hono4();
482
- app4.get("/api/version", (c) => c.json({ version: pkg.version }));
504
+ app4.get("/api/version", (c) => c.json({ version: PKG_VERSION }));
483
505
  app4.route("/api/status", status_default);
484
506
  app4.route("/api/jobs", jobs_default);
485
507
  app4.route("/api/models", models_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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docs-i18n",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Universal documentation translation engine — parse, translate, cache, assemble, manage.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,22 +1,38 @@
1
1
  import { spawn as nodeSpawn } from 'node:child_process';
2
2
  import { createServer } from 'node:http';
3
- import { createRequire } from 'node:module';
4
- import { resolve } from 'node:path';
3
+ import { readFileSync } from 'node:fs';
4
+ import { resolve, dirname } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
5
6
  import { Hono } from 'hono';
6
7
  import type { DocsI18nConfig } from '../../config';
7
8
  import { initStatus } from './services/status';
8
9
  import jobRoutes from './routes/jobs';
9
10
  import modelRoutes from './routes/models';
10
11
  import statusRoutes from './routes/status';
12
+ import { setConfig } from './services/job-manager';
11
13
 
12
- const require = createRequire(import.meta.url);
13
- const pkg = require('../../../package.json');
14
+ function loadVersion(): string {
15
+ try {
16
+ // Walk up from dist/ to find package.json
17
+ let dir = dirname(fileURLToPath(import.meta.url));
18
+ for (let i = 0; i < 5; i++) {
19
+ try {
20
+ const pkg = JSON.parse(readFileSync(resolve(dir, 'package.json'), 'utf-8'));
21
+ if (pkg.name === 'docs-i18n') return pkg.version;
22
+ } catch {}
23
+ dir = dirname(dir);
24
+ }
25
+ } catch {}
26
+ return 'unknown';
27
+ }
28
+ const PKG_VERSION = loadVersion();
14
29
 
15
30
  export async function startAdmin(config: DocsI18nConfig, port = 3456) {
16
31
  initStatus(config);
32
+ setConfig(config);
17
33
 
18
34
  const app = new Hono();
19
- app.get('/api/version', (c) => c.json({ version: pkg.version }));
35
+ app.get('/api/version', (c) => c.json({ version: PKG_VERSION }));
20
36
  app.route('/api/status', statusRoutes);
21
37
  app.route('/api/jobs', jobRoutes);
22
38
  app.route('/api/models', modelRoutes);
@@ -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'],