docs-i18n 0.7.1 → 0.7.3

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.
Files changed (2) hide show
  1. package/dist/cli.js +36 -22
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -6,11 +6,12 @@ import "./chunk-PNKVD2UK.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { createRequire } from "module";
9
+ var require2 = createRequire(import.meta.url);
10
+ var pkg = require2("../package.json");
11
+ var version = pkg.version;
9
12
  var args = process.argv.slice(2);
10
13
  if (args[0] === "--version" || args[0] === "-v") {
11
- const require2 = createRequire(import.meta.url);
12
- const pkg = require2("../package.json");
13
- console.log(pkg.version);
14
+ console.log(version);
14
15
  process.exit(0);
15
16
  }
16
17
  var command = args[0];
@@ -22,6 +23,7 @@ function hasFlag(name) {
22
23
  return args.includes(`--${name}`);
23
24
  }
24
25
  async function handleSiteCommand() {
26
+ console.log(`docs-i18n v${version}`);
25
27
  const validSub = /* @__PURE__ */ new Set(["dev", "build", "upload", "deploy"]);
26
28
  const subCommand = args.slice(1).find((a) => validSub.has(a));
27
29
  const port = Number(getOpt("port", "3000"));
@@ -52,20 +54,20 @@ async function handleSiteCommand() {
52
54
  stdio: "inherit"
53
55
  });
54
56
  }
57
+ const viteBin = resolve(templateRoot, "node_modules", ".bin", "vite");
58
+ const siteEnv = { ...process.env, DOCS_I18N_PROJECT_ROOT: process.cwd() };
55
59
  if (!subCommand || subCommand === "dev") {
56
- const child = spawn("npx", ["vite", "--port", String(port)], {
60
+ const child = spawn(viteBin, ["--port", String(port)], {
57
61
  cwd: templateRoot,
58
62
  stdio: "inherit",
59
- env: { ...process.env, DOCS_I18N_PROJECT_ROOT: process.cwd() },
60
- shell: true
63
+ env: siteEnv
61
64
  });
62
65
  child.on("exit", (code) => process.exit(code ?? 0));
63
66
  } else if (subCommand === "build") {
64
- const child = spawn("npx", ["vite", "build"], {
67
+ const child = spawn(viteBin, ["build"], {
65
68
  cwd: templateRoot,
66
69
  stdio: "inherit",
67
- env: { ...process.env, DOCS_I18N_PROJECT_ROOT: process.cwd() },
68
- shell: true
70
+ env: siteEnv
69
71
  });
70
72
  child.on("exit", (code) => process.exit(code ?? 0));
71
73
  } else if (subCommand === "upload") {
@@ -82,10 +84,10 @@ async function handleSiteCommand() {
82
84
  const sqlFile = resolve(os.tmpdir(), "docs-i18n-upload.sql");
83
85
  writeFileSync(sqlFile, allSql.join("\n"));
84
86
  const dbName = getOpt("db", "docs-i18n-db");
85
- const child = spawn("npx", ["wrangler", "d1", "execute", dbName, "--file", sqlFile], {
87
+ const wranglerBin = resolve(templateRoot, "node_modules", ".bin", "wrangler");
88
+ const child = spawn(wranglerBin, ["d1", "execute", dbName, "--file", sqlFile], {
86
89
  cwd: templateRoot,
87
- stdio: "inherit",
88
- shell: true
90
+ stdio: "inherit"
89
91
  });
90
92
  child.on("exit", (code) => {
91
93
  if (code === 0) {
@@ -94,11 +96,11 @@ async function handleSiteCommand() {
94
96
  process.exit(code ?? 0);
95
97
  });
96
98
  } else if (subCommand === "deploy") {
97
- const child = spawn("npx", ["wrangler", "deploy"], {
99
+ const wranglerBin2 = resolve(templateRoot, "node_modules", ".bin", "wrangler");
100
+ const child = spawn(wranglerBin2, ["deploy"], {
98
101
  cwd: templateRoot,
99
102
  stdio: "inherit",
100
- env: { ...process.env },
101
- shell: true
103
+ env: siteEnv
102
104
  });
103
105
  child.on("exit", (code) => process.exit(code ?? 0));
104
106
  } else {
@@ -187,19 +189,31 @@ Options:
187
189
  break;
188
190
  }
189
191
  case "admin": {
192
+ console.log(`docs-i18n v${version}`);
190
193
  const port = Number(getOpt("port", "3456"));
191
194
  const { resolve: res, dirname: dn } = await import("path");
192
195
  const { fileURLToPath: toPath } = await import("url");
193
- const { existsSync: ex, realpathSync: rp } = await import("fs");
196
+ const { existsSync: ex, realpathSync: rp, writeFileSync: wf } = await import("fs");
197
+ const { spawn: sp } = await import("child_process");
198
+ const { tmpdir: tmp } = await import("os");
194
199
  const coreRoot = res(dn(toPath(import.meta.url)), "..");
195
200
  const adminNm = res(coreRoot, "node_modules", "@docs-i18n", "admin");
196
201
  const adminRoot = ex(adminNm) ? rp(adminNm) : res(coreRoot, "admin");
197
- const { startAdmin } = await import(
198
- /* @vite-ignore */
199
- res(adminRoot, "server", "index.ts")
200
- );
201
- await startAdmin(config, port);
202
- break;
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" });
207
+ }
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
+ await new Promise(() => {
216
+ });
203
217
  }
204
218
  default:
205
219
  console.error(`Unknown command: ${command}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docs-i18n",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Universal documentation translation engine — parse, translate, cache, assemble, manage.",
5
5
  "type": "module",
6
6
  "bin": {