docs-i18n 0.2.4 → 0.3.1

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.
@@ -1,14 +1,13 @@
1
1
  import {
2
2
  assemble
3
- } from "./chunk-QSVWLTGQ.js";
4
- import "./chunk-SUIDX6IZ.js";
3
+ } from "./chunk-A3YQNPKZ.js";
4
+ import "./chunk-YN4VJHCQ.js";
5
5
  import {
6
6
  TranslationCache
7
7
  } from "./chunk-XEOYZUHS.js";
8
8
  import {
9
9
  flattenSources
10
- } from "./chunk-3YNFMSJH.js";
11
- import "./chunk-AKLW2MUS.js";
10
+ } from "./chunk-SKKZIV3L.js";
12
11
 
13
12
  // src/commands/assemble.ts
14
13
  import {
@@ -3,7 +3,7 @@ import {
3
3
  init_parser,
4
4
  normalize,
5
5
  parseMdx
6
- } from "./chunk-SUIDX6IZ.js";
6
+ } from "./chunk-YN4VJHCQ.js";
7
7
 
8
8
  // src/core/assembler.ts
9
9
  init_normalize();
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/config.ts
23
+ async function loadConfig(path) {
24
+ const configPath = path ?? "docs-i18n.config.ts";
25
+ try {
26
+ const mod = await import(
27
+ /* @vite-ignore */
28
+ `${process.cwd()}/${configPath}`
29
+ );
30
+ return mod.default ?? mod;
31
+ } catch {
32
+ throw new Error(`Cannot load config from ${configPath}. Create a docs-i18n.config.ts file.`);
33
+ }
34
+ }
35
+ function flattenSources(config) {
36
+ const projects = Object.entries(config.projects);
37
+ const singleProject = projects.length === 1;
38
+ return projects.flatMap(
39
+ ([projectId, project]) => Object.entries(project.sources).map(([version, sourcePath]) => ({
40
+ project: projectId,
41
+ version,
42
+ sourcePath,
43
+ versionKey: singleProject ? version : `${projectId}/${version}`
44
+ }))
45
+ );
46
+ }
47
+
48
+ export {
49
+ __esm,
50
+ __export,
51
+ __toCommonJS,
52
+ loadConfig,
53
+ flattenSources
54
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __esm
3
- } from "./chunk-AKLW2MUS.js";
3
+ } from "./chunk-SKKZIV3L.js";
4
4
 
5
5
  // src/core/normalize.ts
6
6
  function normalize(content) {
package/dist/cli.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  loadConfig
4
- } from "./chunk-3YNFMSJH.js";
5
- import "./chunk-AKLW2MUS.js";
4
+ } from "./chunk-SKKZIV3L.js";
6
5
 
7
6
  // src/cli.ts
8
7
  var args = process.argv.slice(2);
@@ -50,7 +49,7 @@ Options:
50
49
  console.error("Error: --lang is required");
51
50
  process.exit(1);
52
51
  }
53
- const { translate } = await import("./translate-F3AQFN6X.js");
52
+ const { translate } = await import("./translate-FI4IXXOP.js");
54
53
  await translate(config, {
55
54
  lang,
56
55
  project: getOpt("project") || void 0,
@@ -66,7 +65,7 @@ Options:
66
65
  break;
67
66
  }
68
67
  case "assemble": {
69
- const { assembleAll } = await import("./assemble-IOHQYYHI.js");
68
+ const { assembleAll } = await import("./assemble-7H4QCW35.js");
70
69
  await assembleAll(config, {
71
70
  project: getOpt("project") || void 0,
72
71
  version: getOpt("version") || void 0,
@@ -75,7 +74,7 @@ Options:
75
74
  break;
76
75
  }
77
76
  case "rescan": {
78
- const { rescan } = await import("./rescan-VB2PILB2.js");
77
+ const { rescan } = await import("./rescan-O5D3CYC2.js");
79
78
  await rescan(config, {
80
79
  project: getOpt("project") || void 0,
81
80
  version: getOpt("version") || void 0
@@ -83,13 +82,13 @@ Options:
83
82
  break;
84
83
  }
85
84
  case "status": {
86
- const { status } = await import("./status-EWQEACVF.js");
85
+ const { status } = await import("./status-F4MYIAAY.js");
87
86
  await status(config, { lang: getOpt("lang") || void 0 });
88
87
  break;
89
88
  }
90
89
  case "admin": {
91
90
  const port = Number(getOpt("port", "3456"));
92
- const { startAdmin } = await import("./server-HUXOPTUA.js");
91
+ const { startAdmin } = await import("./server-2FW3TPYF.js");
93
92
  await startAdmin(config, port);
94
93
  break;
95
94
  }
@@ -1,14 +1,13 @@
1
1
  import {
2
2
  init_parser,
3
3
  parseMdx
4
- } from "./chunk-SUIDX6IZ.js";
4
+ } from "./chunk-YN4VJHCQ.js";
5
5
  import {
6
6
  TranslationCache
7
7
  } from "./chunk-XEOYZUHS.js";
8
8
  import {
9
9
  flattenSources
10
- } from "./chunk-3YNFMSJH.js";
11
- import "./chunk-AKLW2MUS.js";
10
+ } from "./chunk-SKKZIV3L.js";
12
11
 
13
12
  // src/commands/rescan.ts
14
13
  import { existsSync, readdirSync, readFileSync } from "fs";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  init_parser,
3
3
  parseMdx
4
- } from "./chunk-SUIDX6IZ.js";
4
+ } from "./chunk-YN4VJHCQ.js";
5
5
  import {
6
6
  TranslationCache
7
7
  } from "./chunk-XEOYZUHS.js";
8
8
  import {
9
9
  flattenSources
10
- } from "./chunk-3YNFMSJH.js";
11
- import "./chunk-AKLW2MUS.js";
10
+ } from "./chunk-SKKZIV3L.js";
12
11
 
13
12
  // src/admin/server/index.ts
13
+ import { spawn as nodeSpawn } from "child_process";
14
14
  import { createServer } from "http";
15
15
  import { resolve as resolve2 } from "path";
16
16
  import { Hono as Hono4 } from "hono";
@@ -489,22 +489,25 @@ async function startAdmin(config, port = 3456) {
489
489
  if (!fullPath.startsWith(process.cwd())) return c.json({ error: "Invalid path" }, 400);
490
490
  const candidates = process.env.EDITOR_CMD ? [process.env.EDITOR_CMD] : ["code", "cursor", "zed"];
491
491
  for (const cmd of candidates) {
492
- const which = Bun.spawn(["which", cmd], { stdio: ["ignore", "pipe", "ignore"] });
493
- await which.exited;
494
- if (which.exitCode === 0) {
495
- Bun.spawn([cmd, fullPath], { stdio: ["ignore", "ignore", "ignore"] });
492
+ const found = await new Promise((r) => {
493
+ const p = nodeSpawn("which", [cmd], { stdio: "ignore" });
494
+ p.on("exit", (code) => r(code === 0));
495
+ p.on("error", () => r(false));
496
+ });
497
+ if (found) {
498
+ nodeSpawn(cmd, [fullPath], { stdio: "ignore", detached: true }).unref();
496
499
  return c.json({ opened: fullPath, editor: cmd });
497
500
  }
498
501
  }
499
502
  const fallback = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
500
- Bun.spawn([fallback, fullPath], { stdio: ["ignore", "ignore", "ignore"] });
503
+ nodeSpawn(fallback, [fullPath], { stdio: "ignore", detached: true }).unref();
501
504
  return c.json({ opened: fullPath, editor: fallback });
502
505
  });
503
506
  const thisFile = new URL(import.meta.url).pathname;
504
507
  const pkgRoot = resolve2(thisFile, "..", "..");
505
508
  const adminRoot = resolve2(pkgRoot, "src", "admin");
506
509
  try {
507
- const { createServer: createViteServer } = await import("./node-NUDVMOF2.js");
510
+ const { createServer: createViteServer } = await import("vite");
508
511
  const vite = await createViteServer({
509
512
  root: adminRoot,
510
513
  server: { middlewareMode: true },
@@ -539,10 +542,30 @@ async function startAdmin(config, port = 3456) {
539
542
  server.listen(port, () => {
540
543
  console.log(`\u{1F310} docs-i18n admin \u2192 http://localhost:${port}`);
541
544
  });
542
- } catch {
543
- console.error("Failed to start admin UI (vite not available). API-only mode.");
544
- const server = Bun.serve({ port, fetch: app4.fetch });
545
- console.log(`\u{1F310} docs-i18n admin (API only) \u2192 http://localhost:${port}`);
545
+ } catch (err) {
546
+ console.error("Failed to start admin UI with Vite:", err.message);
547
+ console.log("Starting API-only mode...");
548
+ const server = createServer(async (req, res) => {
549
+ const url = req.url ?? "/";
550
+ const headers = new Headers();
551
+ for (const [k, v] of Object.entries(req.headers)) {
552
+ if (v) headers.set(k, Array.isArray(v) ? v.join(", ") : v);
553
+ }
554
+ const body = req.method !== "GET" && req.method !== "HEAD" ? await new Promise((r) => {
555
+ let data = "";
556
+ req.on("data", (c) => {
557
+ data += c.toString();
558
+ });
559
+ req.on("end", () => r(data));
560
+ }) : void 0;
561
+ const webReq = new Request(`http://localhost:${port}${url}`, { method: req.method, headers, body });
562
+ const webRes = await app4.fetch(webReq);
563
+ res.writeHead(webRes.status, Object.fromEntries(webRes.headers.entries()));
564
+ res.end(Buffer.from(await webRes.arrayBuffer()));
565
+ });
566
+ server.listen(port, () => {
567
+ console.log(`\u{1F310} docs-i18n admin (API only) \u2192 http://localhost:${port}`);
568
+ });
546
569
  }
547
570
  }
548
571
  export {
@@ -3,8 +3,7 @@ import {
3
3
  } from "./chunk-XEOYZUHS.js";
4
4
  import {
5
5
  flattenSources
6
- } from "./chunk-3YNFMSJH.js";
7
- import "./chunk-AKLW2MUS.js";
6
+ } from "./chunk-SKKZIV3L.js";
8
7
 
9
8
  // src/commands/status.ts
10
9
  import { resolve } from "path";
@@ -1,19 +1,17 @@
1
- import "./chunk-QSVWLTGQ.js";
1
+ import "./chunk-A3YQNPKZ.js";
2
2
  import {
3
3
  FRONTMATTER_TRANSLATABLE_FIELDS,
4
4
  init_parser
5
- } from "./chunk-SUIDX6IZ.js";
5
+ } from "./chunk-YN4VJHCQ.js";
6
6
  import {
7
7
  TranslationCache
8
8
  } from "./chunk-XEOYZUHS.js";
9
- import {
10
- flattenSources
11
- } from "./chunk-3YNFMSJH.js";
12
9
  import {
13
10
  __esm,
14
11
  __export,
15
- __toCommonJS
16
- } from "./chunk-AKLW2MUS.js";
12
+ __toCommonJS,
13
+ flattenSources
14
+ } from "./chunk-SKKZIV3L.js";
17
15
 
18
16
  // src/core/frontmatter.ts
19
17
  var frontmatter_exports = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docs-i18n",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "Universal documentation translation engine — parse, translate, cache, assemble, manage.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,16 +27,17 @@
27
27
  "prepublishOnly": "tsup && chmod +x dist/cli.js"
28
28
  },
29
29
  "dependencies": {
30
- "@mdx-js/mdx": "^3.1.1",
31
- "@tanstack/react-query": "^5.94.5",
32
30
  "better-sqlite3": "^12.8.0",
33
31
  "glob": "^11.0.2",
34
32
  "hono": "^4.12.0",
35
33
  "openai": "^5.1.1",
36
- "react": "^19.2.4",
37
- "react-dom": "^19.2.4",
38
34
  "remark": "^15.0.1",
39
- "yaml": "^2.8.2"
35
+ "yaml": "^2.8.2",
36
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
37
+ "@vitejs/plugin-react": "^4.0.0 || ^5.0.0 || ^6.0.0",
38
+ "react": "^18.0.0 || ^19.0.0",
39
+ "react-dom": "^18.0.0 || ^19.0.0",
40
+ "@tanstack/react-query": "^5.0.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@biomejs/biome": "^2.0.0",
@@ -1,3 +1,4 @@
1
+ import { spawn as nodeSpawn } from 'node:child_process';
1
2
  import { createServer } from 'node:http';
2
3
  import { resolve } from 'node:path';
3
4
  import { Hono } from 'hono';
@@ -26,15 +27,18 @@ export async function startAdmin(config: DocsI18nConfig, port = 3456) {
26
27
 
27
28
  const candidates = process.env.EDITOR_CMD ? [process.env.EDITOR_CMD] : ['code', 'cursor', 'zed'];
28
29
  for (const cmd of candidates) {
29
- const which = Bun.spawn(['which', cmd], { stdio: ['ignore', 'pipe', 'ignore'] });
30
- await which.exited;
31
- if (which.exitCode === 0) {
32
- Bun.spawn([cmd, fullPath], { stdio: ['ignore', 'ignore', 'ignore'] });
30
+ const found = await new Promise<boolean>((r) => {
31
+ const p = nodeSpawn('which', [cmd], { stdio: 'ignore' });
32
+ p.on('exit', (code) => r(code === 0));
33
+ p.on('error', () => r(false));
34
+ });
35
+ if (found) {
36
+ nodeSpawn(cmd, [fullPath], { stdio: 'ignore', detached: true }).unref();
33
37
  return c.json({ opened: fullPath, editor: cmd });
34
38
  }
35
39
  }
36
40
  const fallback = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
37
- Bun.spawn([fallback, fullPath], { stdio: ['ignore', 'ignore', 'ignore'] });
41
+ nodeSpawn(fallback, [fullPath], { stdio: 'ignore', detached: true }).unref();
38
42
  return c.json({ opened: fullPath, editor: fallback });
39
43
  });
40
44
 
@@ -84,10 +88,30 @@ export async function startAdmin(config: DocsI18nConfig, port = 3456) {
84
88
  server.listen(port, () => {
85
89
  console.log(`🌐 docs-i18n admin → http://localhost:${port}`);
86
90
  });
87
- } catch {
88
- console.error('Failed to start admin UI (vite not available). API-only mode.');
89
- // Fallback: just run Hono without Vite
90
- const server = Bun.serve({ port, fetch: app.fetch });
91
- console.log(`🌐 docs-i18n admin (API only) http://localhost:${port}`);
91
+ } catch (err) {
92
+ console.error('Failed to start admin UI with Vite:', (err as Error).message);
93
+ console.log('Starting API-only mode...');
94
+ // Fallback: Hono on Node http server without Vite
95
+ const server = createServer(async (req, res) => {
96
+ const url = req.url ?? '/';
97
+ const headers = new Headers();
98
+ for (const [k, v] of Object.entries(req.headers)) {
99
+ if (v) headers.set(k, Array.isArray(v) ? v.join(', ') : v);
100
+ }
101
+ const body = req.method !== 'GET' && req.method !== 'HEAD'
102
+ ? await new Promise<string>((r) => {
103
+ let data = '';
104
+ req.on('data', (c: Buffer) => { data += c.toString(); });
105
+ req.on('end', () => r(data));
106
+ })
107
+ : undefined;
108
+ const webReq = new Request(`http://localhost:${port}${url}`, { method: req.method, headers, body });
109
+ const webRes = await app.fetch(webReq);
110
+ res.writeHead(webRes.status, Object.fromEntries(webRes.headers.entries()));
111
+ res.end(Buffer.from(await webRes.arrayBuffer()));
112
+ });
113
+ server.listen(port, () => {
114
+ console.log(`🌐 docs-i18n admin (API only) → http://localhost:${port}`);
115
+ });
92
116
  }
93
117
  }
@@ -1,12 +0,0 @@
1
- import {
2
- createBuilder,
3
- resolveBuildPlugins
4
- } from "./chunk-FYDB7MZX.js";
5
- import "./chunk-PTIH4GGE.js";
6
- import "./chunk-VKKNQBDN.js";
7
- import "./chunk-O35QHRY6.js";
8
- import "./chunk-AKLW2MUS.js";
9
- export {
10
- createBuilder,
11
- resolveBuildPlugins
12
- };