@v1hz/md2docx 1.0.1 → 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/package.json +4 -2
- package/src/cli.ts +7 -1
- package/src/index.ts +8 -1
- package/src/paths.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v1hz/md2docx",
|
|
3
|
-
"version": "1.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;
|