@wenyan-md/cli 2.0.1 → 2.0.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.
package/README.md CHANGED
@@ -154,6 +154,12 @@ flowchart LR
154
154
 
155
155
  **[Server 模式部署](docs/server.md)**
156
156
 
157
+ 客户端调用 Server 发布:
158
+
159
+ ```bash
160
+ wenyan publish -f article.md --server https://api.example.com --api-key your-api-key
161
+ ```
162
+
157
163
  ## 赞助
158
164
 
159
165
  如果你觉得文颜对你有帮助,可以给我家猫咪买点罐头 ❤️
package/dist/cli.js CHANGED
@@ -125,5 +125,8 @@ async function runCommandWrapper(action) {
125
125
  process.exit(1);
126
126
  }
127
127
  }
128
- const program = createProgram();
129
- program.parse(process.argv);
128
+ export const program = createProgram();
129
+ // 仅在作为主模块运行时执行 parse,防止测试文件 import 时意外触发
130
+ if (import.meta.main) {
131
+ program.parse(process.argv);
132
+ }
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import crypto from "node:crypto";
5
5
  import { configDir } from "@wenyan-md/core/wrapper";
6
6
  import multer from "multer";
7
- import { publishToWechatDraft } from "@wenyan-md/core/publish";
7
+ import { publishToWechatDraft } from "@wenyan-md/core/wrapper";
8
8
  class AppError extends Error {
9
9
  message;
10
10
  constructor(message) {
@@ -214,7 +214,7 @@ async function cleanupOldUploads() {
214
214
  await fs.unlink(filePath);
215
215
  }
216
216
  }
217
- catch (e) {
217
+ catch (_e) {
218
218
  // 忽略单个文件处理错误
219
219
  }
220
220
  }
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
3
  export declare function createProgram(version?: string): Command;
4
+ export declare const program: Command;
@@ -1,4 +1,5 @@
1
1
  export declare function readStdin(): Promise<string>;
2
+ export declare function readStream(stream: NodeJS.ReadableStream): Promise<string>;
2
3
  export declare function getInputContent(inputContent?: string, file?: string): Promise<{
3
4
  content: string;
4
5
  absoluteDirPath: string | undefined;
package/dist/utils.js CHANGED
@@ -1,13 +1,31 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs/promises";
3
3
  import { getNormalizeFilePath } from "@wenyan-md/core/wrapper";
4
- export async function readStdin() {
4
+ export function readStdin() {
5
+ return readStream(process.stdin);
6
+ }
7
+ export async function readStream(stream) {
5
8
  return new Promise((resolve, reject) => {
6
9
  let data = "";
7
- process.stdin.setEncoding("utf8");
8
- process.stdin.on("data", (chunk) => (data += chunk));
9
- process.stdin.on("end", () => resolve(data));
10
- process.stdin.on("error", reject);
10
+ stream.setEncoding?.("utf8");
11
+ const onData = (chunk) => (data += chunk);
12
+ const onEnd = () => {
13
+ cleanup();
14
+ resolve(data);
15
+ };
16
+ const onError = (err) => {
17
+ cleanup();
18
+ reject(err);
19
+ };
20
+ const cleanup = () => {
21
+ stream.removeListener("data", onData);
22
+ stream.removeListener("end", onEnd);
23
+ stream.removeListener("error", onError);
24
+ };
25
+ stream.on("data", onData);
26
+ stream.on("end", onEnd);
27
+ stream.on("error", onError);
28
+ stream.resume?.();
11
29
  });
12
30
  }
13
31
  export async function getInputContent(inputContent, file) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenyan-md/cli",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "A CLI tool for Wenyan markdown rendering & publishing",
5
5
  "author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "url": "https://github.com/caol64/wenyan-cli/issues"
32
32
  },
33
33
  "dependencies": {
34
- "@wenyan-md/core": "^2.0.8",
34
+ "@wenyan-md/core": "^3.0.3",
35
35
  "commander": "^14.0.0",
36
36
  "express": "^5.2.1",
37
37
  "form-data-encoder": "^4.1.0",
@@ -40,24 +40,29 @@
40
40
  "multer": "^2.1.0"
41
41
  },
42
42
  "devDependencies": {
43
+ "@eslint/js": "^10.0.1",
43
44
  "@types/express": "^5.0.6",
44
45
  "@types/multer": "^2.0.0",
45
46
  "@types/node": "^24.3.0",
46
- "dotenv-cli": "^10.0.0",
47
+ "eslint": "^10.1.0",
48
+ "globals": "^17.4.0",
47
49
  "tsx": "^4.21.0",
48
50
  "typescript": "^5.9.2",
49
- "vite": "^7.3.1",
50
- "vitest": "^4.0.18"
51
+ "typescript-eslint": "^8.58.0"
52
+ },
53
+ "publishConfig": {
54
+ "registry": "https://registry.npmjs.org/"
51
55
  },
52
56
  "scripts": {
53
57
  "build": "tsc",
54
58
  "upgrade:core": "pnpm update @wenyan-md/core",
55
- "server": "pnpm build && pnpm dotenv -e .env.test -- node ./dist/cli.js serve",
59
+ "test": "node --import tsx --test",
60
+ "test:watch": "node --import tsx --test --watch",
61
+ "typecheck": "tsc --noEmit",
62
+ "lint": "eslint . --fix",
56
63
  "test:bin": "pnpm build && node ./dist/cli.js render -f tests/publish.md -c tests/manhua.css --no-mac-style",
57
- "test:cli": "vitest run tests/cli.test.ts",
58
- "test:render": "vitest run tests/render.test.ts",
59
- "test:publish": "vitest run tests/publish.test.ts",
60
- "test:realPublish": "pnpm build && pnpm dotenv -e .env.test -- node ./dist/cli.js publish -f tests/publish.md -c tests/manhua.css --no-mac-style",
61
- "test:serverPublish": "pnpm build && node ./dist/cli.js publish -f tests/publish.md -c tests/manhua.css --no-mac-style --server http://localhost:3000"
64
+ "test:realPublish": "pnpm build && node --env-file=.env.test ./dist/cli.js publish -f tests/publish.md -t phycat",
65
+ "test:serverPublish": "pnpm build && node ./dist/cli.js publish -f tests/publish.md -c tests/manhua.css --no-mac-style --server http://localhost:3000",
66
+ "test:serve": "pnpm build && node --env-file=.env.test ./dist/cli.js serve"
62
67
  }
63
68
  }