@v1hz/md2docx 1.0.0 → 1.0.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/README.md CHANGED
@@ -21,28 +21,42 @@
21
21
  - [Bun](https://bun.sh) ≥ 1.3
22
22
  - [pandoc](https://pandoc.org)(可选,需导出 Word 时安装)
23
23
 
24
- ### 克隆并安装
24
+ ### 通过 npx(推荐,无需安装)
25
+
26
+ ```bash
27
+ npx @v1hz/md2docx README.md
28
+ ```
29
+
30
+ ### 全局安装
31
+
32
+ ```bash
33
+ npm install -g @v1hz/md2docx
34
+ md2docx README.md
35
+ ```
36
+
37
+ ### 从源码运行
25
38
 
26
39
  ```bash
27
40
  git clone https://github.com/WXY-V1hZ/md2docx.git
28
41
  cd md2docx
29
42
  bun install
43
+ bun run src/index.ts docs/example.md
30
44
  ```
31
45
 
32
46
  ## 快速开始
33
47
 
34
48
  ```bash
35
49
  # 处理 Markdown 并生成 Word 文档
36
- bun run src/index.ts docs/example.md
50
+ npx @v1hz/md2docx docs/example.md
37
51
 
38
52
  # 只预处理,不调用 pandoc
39
- bun run src/index.ts docs/example.md --pandoc.enabled false
53
+ npx @v1hz/md2docx docs/example.md --pandoc.enabled false
40
54
 
41
55
  # 指定输出路径
42
- bun run src/index.ts docs/example.md -o output/example.docx
56
+ npx @v1hz/md2docx docs/example.md -o output/example.docx
43
57
 
44
58
  # 使用自定义配置文件
45
- bun run src/index.ts docs/example.md --config ./my-config.json
59
+ npx @v1hz/md2docx docs/example.md --config ./my-config.json
46
60
  ```
47
61
 
48
62
  ## 配置
@@ -52,7 +66,7 @@ bun run src/index.ts docs/example.md --config ./my-config.json
52
66
  所有配置项均可通过命令行覆盖:
53
67
 
54
68
  ```bash
55
- bun run src/index.ts docs/example.md --figureCaption.enabled false
69
+ npx @v1hz/md2docx docs/example.md --figureCaption.enabled false
56
70
  ```
57
71
 
58
72
  ### 配置项概览
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v1hz/md2docx",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "基于 pandoc 的 Markdown 转 Word (docx) 工具,自动处理标题、编号、Mermaid 图表等",
5
5
  "keywords": [
6
6
  "converter",
@@ -51,8 +51,10 @@
51
51
  "xpath": "^0.0.34"
52
52
  },
53
53
  "devDependencies": {
54
+ "@types/bun": "^1.3.14",
54
55
  "oxfmt": "^0.58.0",
55
- "oxlint": "^1.73.0"
56
+ "oxlint": "^1.73.0",
57
+ "typescript": "^7.0.2"
56
58
  },
57
59
  "engines": {
58
60
  "bun": ">=1.3"
package/src/cli.ts CHANGED
@@ -24,6 +24,7 @@ export interface ConfigOption {
24
24
 
25
25
  export interface CliOptions {
26
26
  help: boolean;
27
+ version: boolean;
27
28
  web: boolean;
28
29
  mdPath?: string;
29
30
  outputPath?: string;
@@ -60,7 +61,7 @@ export function getConfigOptions(schema: SchemaNode): ConfigOption[] {
60
61
 
61
62
  export function parseCliArgs(args: string[], configOptions: ConfigOption[]): CliOptions {
62
63
  const optionsByName = new Map(configOptions.map((option) => [option.path, option]));
63
- const result: CliOptions = { help: false, web: false, overrides: new Map() };
64
+ const result: CliOptions = { help: false, version: false, web: false, overrides: new Map() };
64
65
  const positional: string[] = [];
65
66
 
66
67
  for (let i = 0; i < args.length; i++) {
@@ -69,6 +70,10 @@ export function parseCliArgs(args: string[], configOptions: ConfigOption[]): Cli
69
70
  result.help = true;
70
71
  continue;
71
72
  }
73
+ if (arg === "-v" || arg === "--version") {
74
+ result.version = true;
75
+ continue;
76
+ }
72
77
  if (arg === "--web") {
73
78
  result.web = true;
74
79
  continue;
@@ -132,6 +137,7 @@ export function formatHelp(configOptions: ConfigOption[]): string {
132
137
  " -o <path> 输出 docx 路径",
133
138
  " --config <path> 配置文件路径,默认 config/config.json",
134
139
  " --web 打开默认配置的网页编辑器",
140
+ " -v, --version 显示版本号",
135
141
  " -h, --help 显示帮助",
136
142
  "",
137
143
  "配置覆盖:",
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ import { $ } from "bun";
6
6
 
7
7
  import { applyConfigOverrides, formatHelp, getConfigOptions, parseCliArgs } from "./cli";
8
8
  import { loadConfig } from "./config";
9
- import { CONFIG_PATH, CONFIG_SCHEMA_PATH, formattedMdPath, preprocessDir } from "./paths";
9
+ import { CONFIG_PATH, CONFIG_SCHEMA_PATH, PKG_DIR, formattedMdPath, preprocessDir } from "./paths";
10
10
  import { preprocess } from "./preprocess/index";
11
11
  import { startWebEditor } from "./web";
12
12
 
@@ -16,6 +16,13 @@ export async function run(args: string[]): Promise<number> {
16
16
  const configOptions = getConfigOptions(schema);
17
17
  const cli = parseCliArgs(args, configOptions);
18
18
 
19
+ if (cli.version) {
20
+ const { version } = JSON.parse(await Bun.file(resolve(PKG_DIR, "package.json")).text()) as {
21
+ version: string;
22
+ };
23
+ console.log(`@v1hz/md2docx v${version}`);
24
+ return 0;
25
+ }
19
26
  if (cli.help) {
20
27
  console.log(formatHelp(configOptions));
21
28
  return 0;
package/src/paths.ts CHANGED
@@ -1,15 +1,20 @@
1
- // ── 路径常量 ───────────────────────────────────────────
1
+ import { resolve } from "path";
2
2
 
3
- /** 配置文件路径 */
4
- export const CONFIG_PATH = "config/config.json";
3
+ const PKG_DIR = resolve(import.meta.dir, "..");
5
4
 
6
- /** 配置 schema 路径 */
7
- export const CONFIG_SCHEMA_PATH = "config/config.schema.json";
5
+ /** 包根目录 */
6
+ export { PKG_DIR };
8
7
 
9
- /** 临时文件根目录 */
8
+ /** 默认配置文件路径(相对于包安装目录) */
9
+ export const CONFIG_PATH = resolve(PKG_DIR, "config/config.json");
10
+
11
+ /** 默认配置 schema 路径(相对于包安装目录) */
12
+ export const CONFIG_SCHEMA_PATH = resolve(PKG_DIR, "config/config.schema.json");
13
+
14
+ /** 临时文件根目录(相对于当前工作目录) */
10
15
  export const TMP_DIR = "tmp";
11
16
 
12
- /** 预处理模块的输出目录(相对于项目根目录) */
17
+ /** 预处理模块的输出目录(相对于当前工作目录) */
13
18
  export function preprocessDir(baseName: string): string {
14
19
  return `${TMP_DIR}/preprocess/${baseName}`;
15
20
  }