@wenyan-md/core 2.0.3 → 2.0.4

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/dist/http.js ADDED
@@ -0,0 +1 @@
1
+
package/dist/publish.js CHANGED
@@ -2,11 +2,62 @@ import { JSDOM } from "jsdom";
2
2
  import { fileFromPath } from "formdata-node/file-from-path";
3
3
  import path from "node:path";
4
4
  import { stat } from "node:fs/promises";
5
- import { R as RuntimeEnv } from "./runtimeEnv-pU2mTDLR.js";
6
5
  import { createWechatClient } from "./wechat.js";
7
6
  import { FormDataEncoder } from "form-data-encoder";
8
7
  import { FormData } from "formdata-node";
9
8
  import { Readable } from "node:stream";
9
+ function normalizePath(p) {
10
+ return p.replace(/\\/g, "/").replace(/\/+$/, "");
11
+ }
12
+ function isAbsolutePath(path2) {
13
+ if (!path2) return false;
14
+ const winAbsPattern = /^[a-zA-Z]:\//;
15
+ const linuxAbsPattern = /^\//;
16
+ return winAbsPattern.test(path2) || linuxAbsPattern.test(path2);
17
+ }
18
+ const RuntimeEnv = {
19
+ isContainer: !!process.env.CONTAINERIZED,
20
+ hostFilePath: normalizePath(process.env.HOST_FILE_PATH || ""),
21
+ containerFilePath: normalizePath(process.env.CONTAINER_FILE_PATH || "/mnt/host-downloads"),
22
+ resolveLocalPath(inputPath, relativeBase) {
23
+ if (!this.isContainer) {
24
+ if (relativeBase) {
25
+ return path.resolve(relativeBase, inputPath);
26
+ } else {
27
+ if (!path.isAbsolute(inputPath)) {
28
+ throw new Error(
29
+ `Invalid input: '${inputPath}'. When relativeBase is not provided, inputPath must be an absolute path.`
30
+ );
31
+ }
32
+ return path.normalize(inputPath);
33
+ }
34
+ }
35
+ let normalizedInput = normalizePath(inputPath);
36
+ relativeBase = normalizePath(relativeBase || "");
37
+ if (relativeBase) {
38
+ if (!isAbsolutePath(normalizedInput)) {
39
+ normalizedInput = relativeBase + (normalizedInput.startsWith("/") ? "" : "/") + normalizedInput;
40
+ }
41
+ } else {
42
+ if (!isAbsolutePath(normalizedInput)) {
43
+ throw new Error(
44
+ `Invalid input: '${inputPath}'. When relativeBase is not provided, inputPath must be an absolute path.`
45
+ );
46
+ }
47
+ }
48
+ if (normalizedInput.startsWith(this.hostFilePath)) {
49
+ let relativePart = normalizedInput.slice(this.hostFilePath.length);
50
+ if (relativePart && !relativePart.startsWith("/")) {
51
+ return normalizedInput;
52
+ }
53
+ if (!relativePart.startsWith("/")) {
54
+ relativePart = "/" + relativePart;
55
+ }
56
+ return this.containerFilePath + relativePart;
57
+ }
58
+ return normalizedInput;
59
+ }
60
+ };
10
61
  const nodeHttpAdapter = {
11
62
  fetch,
12
63
  createMultipart(field, file, filename) {
@@ -8,4 +8,3 @@ export interface StyledContent {
8
8
  export declare function renderStyledContent(content: string, options?: ApplyStylesOptions): Promise<StyledContent>;
9
9
  export declare function getGzhContent(content: string, themeId: string, hlThemeId: string, isMacStyle?: boolean, isAddFootnote?: boolean): Promise<StyledContent>;
10
10
  export * from "./configStore.js";
11
- export * from "./runtimeEnv.js";
@@ -5,5 +5,3 @@ export declare function createWechatClient(adapter: HttpAdapter): {
5
5
  publishArticle(title: string, content: string, thumbMediaId: string, accessToken: string): Promise<any>;
6
6
  };
7
7
  export type WechatClient = ReturnType<typeof createWechatClient>;
8
- export * from "./http.js";
9
- export * from "./adapters/browser.js";
package/dist/wechat.js CHANGED
@@ -1,13 +1,3 @@
1
- const browserHttpAdapter = {
2
- fetch: window.fetch.bind(window),
3
- createMultipart(field, file, filename) {
4
- const form = new FormData();
5
- form.append(field, file, filename);
6
- return {
7
- body: form
8
- };
9
- }
10
- };
11
1
  const tokenUrl = "https://api.weixin.qq.com/cgi-bin/token";
12
2
  const publishUrl = "https://api.weixin.qq.com/cgi-bin/draft/add";
13
3
  const uploadUrl = "https://api.weixin.qq.com/cgi-bin/material/add_material";
@@ -48,6 +38,5 @@ function createWechatClient(adapter) {
48
38
  };
49
39
  }
50
40
  export {
51
- browserHttpAdapter,
52
41
  createWechatClient
53
42
  };
package/dist/wrapper.js CHANGED
@@ -3,7 +3,6 @@ import { createWenyanCore } from "./core.js";
3
3
  import path from "node:path";
4
4
  import os from "node:os";
5
5
  import fs from "node:fs";
6
- import { R } from "./runtimeEnv-pU2mTDLR.js";
7
6
  const defaultConfig = {};
8
7
  const configDir = process.env.APPDATA ? path.join(process.env.APPDATA, "wenyan-md") : path.join(os.homedir(), ".config", "wenyan-md");
9
8
  const configPath = path.join(configDir, "config.json");
@@ -112,7 +111,6 @@ async function getGzhContent(content, themeId, hlThemeId, isMacStyle = true, isA
112
111
  });
113
112
  }
114
113
  export {
115
- R as RuntimeEnv,
116
114
  configDir,
117
115
  configPath,
118
116
  configStore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenyan-md/core",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Core library for Wenyan markdown rendering & publishing",
5
5
  "author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
6
6
  "license": "Apache-2.0",
@@ -28,12 +28,11 @@
28
28
  "exports": {
29
29
  ".": {
30
30
  "import": "./dist/core.js",
31
- "types": "./dist/types/core/index.d.ts",
32
- "browser": "./dist/browser/wenyan-core.js"
31
+ "types": "./dist/types/core/index.d.ts"
33
32
  },
34
33
  "./publish": {
35
34
  "import": "./dist/publish.js",
36
- "types": "./dist/types/wechat/publish.d.ts"
35
+ "types": "./dist/types/node/publish.d.ts"
37
36
  },
38
37
  "./wrapper": {
39
38
  "import": "./dist/wrapper.js",
@@ -41,7 +40,11 @@
41
40
  },
42
41
  "./wechat": {
43
42
  "import": "./dist/wechat.js",
44
- "types": "./dist/types/wechat/core.d.ts"
43
+ "types": "./dist/types/wechat.d.ts"
44
+ },
45
+ "./http": {
46
+ "import": "./dist/http.js",
47
+ "types": "./dist/types/http.d.ts"
45
48
  }
46
49
  },
47
50
  "devDependencies": {
@@ -1,56 +0,0 @@
1
- import path from "node:path";
2
- function normalizePath(p) {
3
- return p.replace(/\\/g, "/").replace(/\/+$/, "");
4
- }
5
- function isAbsolutePath(path2) {
6
- if (!path2) return false;
7
- const winAbsPattern = /^[a-zA-Z]:\//;
8
- const linuxAbsPattern = /^\//;
9
- return winAbsPattern.test(path2) || linuxAbsPattern.test(path2);
10
- }
11
- const RuntimeEnv = {
12
- isContainer: !!process.env.CONTAINERIZED,
13
- hostFilePath: normalizePath(process.env.HOST_FILE_PATH || ""),
14
- containerFilePath: normalizePath(process.env.CONTAINER_FILE_PATH || "/mnt/host-downloads"),
15
- resolveLocalPath(inputPath, relativeBase) {
16
- if (!this.isContainer) {
17
- if (relativeBase) {
18
- return path.resolve(relativeBase, inputPath);
19
- } else {
20
- if (!path.isAbsolute(inputPath)) {
21
- throw new Error(
22
- `Invalid input: '${inputPath}'. When relativeBase is not provided, inputPath must be an absolute path.`
23
- );
24
- }
25
- return path.normalize(inputPath);
26
- }
27
- }
28
- let normalizedInput = normalizePath(inputPath);
29
- relativeBase = normalizePath(relativeBase || "");
30
- if (relativeBase) {
31
- if (!isAbsolutePath(normalizedInput)) {
32
- normalizedInput = relativeBase + (normalizedInput.startsWith("/") ? "" : "/") + normalizedInput;
33
- }
34
- } else {
35
- if (!isAbsolutePath(normalizedInput)) {
36
- throw new Error(
37
- `Invalid input: '${inputPath}'. When relativeBase is not provided, inputPath must be an absolute path.`
38
- );
39
- }
40
- }
41
- if (normalizedInput.startsWith(this.hostFilePath)) {
42
- let relativePart = normalizedInput.slice(this.hostFilePath.length);
43
- if (relativePart && !relativePart.startsWith("/")) {
44
- return normalizedInput;
45
- }
46
- if (!relativePart.startsWith("/")) {
47
- relativePart = "/" + relativePart;
48
- }
49
- return this.containerFilePath + relativePart;
50
- }
51
- return normalizedInput;
52
- }
53
- };
54
- export {
55
- RuntimeEnv as R
56
- };
File without changes
File without changes