跳到主要内容

宝玉文章翻译与精校

收藏0

把文章翻译成自然中文或其他语言,支持快翻、标准、精校三种流程和术语表;长文可分块处理,保留 Markdown 结构。

让 AI 安装

github最新版本 0.1.0更新于 2026-10-24下载 1 次

scripts/main.ts

1.4 KB
1#!/usr/bin/env bun
2import path from "node:path"
3import process from "node:process"
4import { runChunkCli } from "./chunk.js"
5
6function formatScriptCommand(fallback: string): string {
7 const raw = process.argv[1]
8 const displayPath = raw
9 ? (() => {
10 const relative = path.relative(process.cwd(), raw)
11 return relative && !relative.startsWith("..") ? relative : raw
12 })()
13 : fallback
14
15 const quotedPath = displayPath.includes(" ")
16 ? `"${displayPath.replace(/"/g, '\\"')}"`
17 : displayPath
18
19 return `npx -y bun ${quotedPath}`
20}
21
22function printUsage(exitCode: number): never {
23 const cmd = formatScriptCommand("scripts/main.ts")
24 console.log(`Baoyu Translate CLI
25
26Usage:
27 ${cmd} <file> [--max-words 5000] [--output-dir <dir>]
28 ${cmd} chunk <file> [--max-words 5000] [--output-dir <dir>]
29
30Commands:
31 chunk Split markdown into chunks
32
33Options:
34 --max-words <n> Maximum words per chunk (default: 5000)
35 --output-dir <dir> Write chunks into <dir>/chunks/
36 -h, --help Show help
37`)
38 process.exit(exitCode)
39}
40
41const args = process.argv.slice(2)
42
43if (args.length === 0) {
44 printUsage(1)
45}
46
47if (args[0] === "-h" || args[0] === "--help") {
48 printUsage(0)
49}
50
51if (args[0] === "chunk") {
52 process.exit(runChunkCli(args.slice(1), `${formatScriptCommand("scripts/main.ts")} chunk`))
53}
54
55process.exit(runChunkCli(args, formatScriptCommand("scripts/main.ts")))

文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。