docs-i18n 0.7.3 → 0.7.5

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.
@@ -8,14 +8,18 @@
8
8
  },
9
9
  "scripts": {
10
10
  "dev": "vite dev",
11
- "build": "vite build"
11
+ "build": "vite build",
12
+ "start": "node dist/server/server.js"
12
13
  },
13
14
  "dependencies": {
15
+ "@tanstack/react-query": "^5.0.0",
16
+ "@tanstack/react-router": "^1.120.3",
17
+ "@tanstack/react-start": "^1.120.3",
18
+ "@vitejs/plugin-react": "^6.0.1",
14
19
  "hono": "^4.12.0",
15
20
  "react": "^19.1.0",
16
21
  "react-dom": "^19.1.0",
17
- "vite": "^8.0.1",
18
- "@vitejs/plugin-react": "^6.0.1"
22
+ "vite": "^8.0.1"
19
23
  },
20
24
  "devDependencies": {
21
25
  "@types/node": "^22.0.0",
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Minimal Node.js HTTP adapter for TanStack Start's fetch-based server.
3
+ * Usage: node serve.mjs
4
+ */
5
+ import { createServer } from 'node:http';
6
+ import { resolve, dirname } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { readFileSync, existsSync } from 'node:fs';
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+
12
+ // Import the built server entry
13
+ const { default: app } = await import('./dist/server/server.js');
14
+
15
+ // Static asset serving from dist/client/
16
+ const clientDir = resolve(__dirname, 'dist', 'client');
17
+
18
+ const mimeTypes = {
19
+ '.html': 'text/html',
20
+ '.js': 'application/javascript',
21
+ '.css': 'text/css',
22
+ '.json': 'application/json',
23
+ '.png': 'image/png',
24
+ '.svg': 'image/svg+xml',
25
+ '.ico': 'image/x-icon',
26
+ '.woff2': 'font/woff2',
27
+ };
28
+
29
+ function getMime(path) {
30
+ const ext = path.match(/\.[^.]+$/)?.[0] || '';
31
+ return mimeTypes[ext] || 'application/octet-stream';
32
+ }
33
+
34
+ const port = Number(process.env.PORT || 3456);
35
+
36
+ const server = createServer(async (req, res) => {
37
+ const url = new URL(req.url, `http://localhost:${port}`);
38
+
39
+ // Try static files first
40
+ const staticPath = resolve(clientDir, url.pathname.slice(1));
41
+ if (staticPath.startsWith(clientDir) && existsSync(staticPath) && !url.pathname.endsWith('/')) {
42
+ try {
43
+ const data = readFileSync(staticPath);
44
+ res.writeHead(200, {
45
+ 'Content-Type': getMime(staticPath),
46
+ 'Cache-Control': url.pathname.includes('/assets/') ? 'public, max-age=31536000, immutable' : 'no-cache',
47
+ });
48
+ res.end(data);
49
+ return;
50
+ } catch {}
51
+ }
52
+
53
+ // Proxy to TanStack Start fetch handler
54
+ const headers = new Headers();
55
+ for (const [key, value] of Object.entries(req.headers)) {
56
+ if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value);
57
+ }
58
+
59
+ const body = ['GET', 'HEAD'].includes(req.method)
60
+ ? undefined
61
+ : await new Promise((resolve) => {
62
+ const chunks = [];
63
+ req.on('data', (c) => chunks.push(c));
64
+ req.on('end', () => resolve(Buffer.concat(chunks)));
65
+ });
66
+
67
+ const request = new Request(url.href, {
68
+ method: req.method,
69
+ headers,
70
+ body,
71
+ });
72
+
73
+ try {
74
+ const response = await app.fetch(request);
75
+ res.writeHead(response.status, Object.fromEntries(response.headers.entries()));
76
+ const buffer = await response.arrayBuffer();
77
+ res.end(Buffer.from(buffer));
78
+ } catch (err) {
79
+ console.error('Server error:', err);
80
+ res.writeHead(500);
81
+ res.end('Internal Server Error');
82
+ }
83
+ });
84
+
85
+ server.listen(port, () => {
86
+ console.log(`Admin dashboard: http://localhost:${port}/`);
87
+ });
@@ -10,4 +10,17 @@ export default defineConfig({
10
10
  }),
11
11
  react(),
12
12
  ],
13
+ // Bundle all deps into server build so it can run without node_modules
14
+ environments: {
15
+ ssr: {
16
+ build: {
17
+ rollupOptions: {
18
+ external: ['node:*'],
19
+ },
20
+ },
21
+ resolve: {
22
+ noExternal: true,
23
+ },
24
+ },
25
+ },
13
26
  });
package/dist/cli.js CHANGED
@@ -200,18 +200,30 @@ Options:
200
200
  const adminNm = res(coreRoot, "node_modules", "@docs-i18n", "admin");
201
201
  const adminRoot = ex(adminNm) ? rp(adminNm) : res(coreRoot, "admin");
202
202
  wf(res(tmp(), "docs-i18n-project-root"), process.cwd());
203
- const { execSync: execS } = await import("child_process");
204
- if (!ex(res(adminRoot, "node_modules"))) {
205
- console.log("Installing admin dependencies...");
206
- execS("npm install --no-audit --no-fund", { cwd: adminRoot, stdio: "inherit" });
203
+ const adminEnv = { ...process.env, DOCS_I18N_PROJECT_ROOT: process.cwd(), PORT: String(port) };
204
+ const serveEntry = res(adminRoot, "serve.mjs");
205
+ const builtServer = res(adminRoot, "dist", "server", "server.js");
206
+ if (ex(builtServer) && ex(serveEntry)) {
207
+ const child = sp("node", [serveEntry], {
208
+ cwd: adminRoot,
209
+ stdio: "inherit",
210
+ env: adminEnv
211
+ });
212
+ child.on("exit", (code) => process.exit(code ?? 0));
213
+ } else {
214
+ const { execSync: execS } = await import("child_process");
215
+ if (!ex(res(adminRoot, "node_modules"))) {
216
+ console.log("Installing admin dependencies...");
217
+ execS("npm install --no-audit --no-fund", { cwd: adminRoot, stdio: "inherit" });
218
+ }
219
+ const adminVite = res(adminRoot, "node_modules", ".bin", "vite");
220
+ const child = sp(adminVite, ["--port", String(port)], {
221
+ cwd: adminRoot,
222
+ stdio: "inherit",
223
+ env: adminEnv
224
+ });
225
+ child.on("exit", (code) => process.exit(code ?? 0));
207
226
  }
208
- const adminVite = res(adminRoot, "node_modules", ".bin", "vite");
209
- const child = sp(adminVite, ["--port", String(port)], {
210
- cwd: adminRoot,
211
- stdio: "inherit",
212
- env: { ...process.env, DOCS_I18N_PROJECT_ROOT: process.cwd() }
213
- });
214
- child.on("exit", (code) => process.exit(code ?? 0));
215
227
  await new Promise(() => {
216
228
  });
217
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docs-i18n",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Universal documentation translation engine — parse, translate, cache, assemble, manage.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,7 +25,7 @@
25
25
  "typecheck": "tsc --noEmit",
26
26
  "prepack": "rm -rf admin template && cp -r ../admin admin && cp -r ../template template && rm -rf admin/node_modules template/node_modules && node -e \"const fs=require('fs');const p=JSON.parse(fs.readFileSync('template/package.json','utf8'));delete p.dependencies['docs-i18n'];fs.writeFileSync('template/package.json',JSON.stringify(p,null,2)+'\\n');const a=JSON.parse(fs.readFileSync('admin/package.json','utf8'));delete a.dependencies['docs-i18n'];fs.writeFileSync('admin/package.json',JSON.stringify(a,null,2)+'\\n')\"",
27
27
  "postpack": "rm -rf admin template",
28
- "prepublishOnly": "rm -rf dist && tsup && chmod +x dist/cli.js"
28
+ "prepublishOnly": "rm -rf dist && tsup && chmod +x dist/cli.js && cd ../admin && npx vite build"
29
29
  },
30
30
  "dependencies": {
31
31
  "better-sqlite3": "^12.8.0",
@@ -5,7 +5,7 @@
5
5
  "scripts": {
6
6
  "dev": "vite dev",
7
7
  "build": "vite build",
8
- "start": "vite start"
8
+ "start": "node dist/server/server.js"
9
9
  },
10
10
  "dependencies": {
11
11
  "@radix-ui/react-dropdown-menu": "^2.1.16",