@wenyan-md/core 2.0.7 → 3.0.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenyan-md/core",
3
- "version": "2.0.7",
3
+ "version": "3.0.0",
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",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "./publish": {
34
34
  "import": "./dist/publish.js",
35
- "types": "./dist/types/node/publish.d.ts"
35
+ "types": "./dist/types/publish.d.ts"
36
36
  },
37
37
  "./wrapper": {
38
38
  "import": "./dist/wrapper.js",
@@ -43,7 +43,6 @@
43
43
  "types": "./dist/types/wechat.d.ts"
44
44
  },
45
45
  "./http": {
46
- "import": "./dist/http.js",
47
46
  "types": "./dist/types/http.d.ts"
48
47
  }
49
48
  },
@@ -80,17 +79,12 @@
80
79
  }
81
80
  },
82
81
  "scripts": {
83
- "dev": "vite build --watch",
84
82
  "check": "tsc --noEmit",
85
83
  "build": "vite build && tsc",
86
- "build:browser": "vite build --config vite.config.browser.ts",
87
- "build:styles": "vite build --config vite.config.styles.ts",
88
- "build:math": "vite build --config vite.config.math.ts",
89
- "build:all": "pnpm build && pnpm build:styles && pnpm build:math && pnpm build:browser",
90
84
  "test": "pnpm build && vitest",
91
- "test:wrapper": "vitest run test/wrapper.test.ts",
92
- "test:publish": "vitest run test/publish.test.ts",
93
- "test:realPublish": "vitest run test/realPublish.test.ts",
94
- "test:runtimeEnv": "vitest run test/runtimeEnv.test.ts"
85
+ "test:wrapper": "vitest run tests/wrapper.test.ts",
86
+ "test:publish": "vitest run tests/publish.test.ts",
87
+ "test:realPublish": "vitest run tests/realPublish.test.ts",
88
+ "test:runtimeEnv": "vitest run tests/runtimeEnv.test.ts"
95
89
  }
96
90
  }
@@ -1,111 +0,0 @@
1
- import path from "node:path";
2
- import os from "node:os";
3
- import fs from "node:fs";
4
- import crypto from "node:crypto";
5
- function safeReadJson(file, fallback) {
6
- try {
7
- return JSON.parse(fs.readFileSync(file, "utf-8"));
8
- } catch {
9
- return fallback;
10
- }
11
- }
12
- function safeWriteJson(file, data) {
13
- const tmp = file + ".tmp";
14
- fs.writeFileSync(tmp, JSON.stringify(data ?? {}, null, 2), "utf-8");
15
- fs.renameSync(tmp, file);
16
- }
17
- function ensureDir(dir) {
18
- if (!fs.existsSync(dir)) {
19
- fs.mkdirSync(dir, { recursive: true });
20
- }
21
- }
22
- function md5FromBuffer(buf) {
23
- return crypto.createHash("md5").update(buf).digest("hex");
24
- }
25
- function md5FromFile(filePath) {
26
- const buf = fs.readFileSync(filePath);
27
- return md5FromBuffer(buf);
28
- }
29
- const defaultConfig = {};
30
- const configDir = process.env.APPDATA ? path.join(process.env.APPDATA, "wenyan-md") : path.join(os.homedir(), ".config", "wenyan-md");
31
- const configPath = path.join(configDir, "config.json");
32
- class ConfigStore {
33
- config = { ...defaultConfig };
34
- constructor() {
35
- this.load();
36
- }
37
- load() {
38
- ensureDir(configDir);
39
- if (fs.existsSync(configPath)) {
40
- this.config = {
41
- ...defaultConfig,
42
- ...safeReadJson(configPath, defaultConfig)
43
- };
44
- }
45
- }
46
- save() {
47
- try {
48
- ensureDir(configDir);
49
- safeWriteJson(configPath, this.config);
50
- } catch (error) {
51
- console.error("❌ 无法保存配置文件:", error);
52
- }
53
- }
54
- getConfig() {
55
- return this.config;
56
- }
57
- getThemes() {
58
- return Object.values(this.config.themes ?? {});
59
- }
60
- getThemeById(themeId) {
61
- const themeOption = this.config.themes?.[themeId];
62
- if (!themeOption) return;
63
- const absoluteFilePath = path.join(configDir, themeOption.path);
64
- try {
65
- return fs.readFileSync(absoluteFilePath, "utf-8");
66
- } catch {
67
- return void 0;
68
- }
69
- }
70
- addThemeToConfig(name, content) {
71
- const savedPath = this.addThemeFile(name, content);
72
- this.config.themes ??= {};
73
- this.config.themes[name] = {
74
- id: name,
75
- name,
76
- path: savedPath
77
- };
78
- this.save();
79
- }
80
- addThemeFile(themeId, themeContent) {
81
- const filePath = `themes/${themeId}.css`;
82
- const absoluteFilePath = path.join(configDir, filePath);
83
- ensureDir(path.dirname(absoluteFilePath));
84
- fs.writeFileSync(absoluteFilePath, themeContent, "utf-8");
85
- return filePath;
86
- }
87
- deleteThemeFromConfig(themeId) {
88
- const theme = this.config.themes?.[themeId];
89
- if (!theme) return;
90
- this.deleteThemeFile(theme.path);
91
- delete this.config.themes[themeId];
92
- this.save();
93
- }
94
- deleteThemeFile(filePath) {
95
- try {
96
- fs.unlinkSync(path.join(configDir, filePath));
97
- } catch {
98
- }
99
- }
100
- }
101
- const configStore = new ConfigStore();
102
- export {
103
- configPath as a,
104
- configStore as b,
105
- configDir as c,
106
- safeWriteJson as d,
107
- ensureDir as e,
108
- md5FromFile as f,
109
- md5FromBuffer as m,
110
- safeReadJson as s
111
- };
package/dist/http.js DELETED
@@ -1 +0,0 @@
1
-
@@ -1,18 +0,0 @@
1
- export declare const tokenPath: string;
2
- export interface TokenCache {
3
- appid: string;
4
- accessToken: string;
5
- expireAt: number;
6
- }
7
- declare class TokenStore {
8
- private cache;
9
- constructor();
10
- private load;
11
- private save;
12
- isValid(appid: string): boolean;
13
- getToken(appid: string): string | null;
14
- setToken(appid: string, accessToken: string, expiresIn: number): void;
15
- clear(): void;
16
- }
17
- export declare const tokenStore: TokenStore;
18
- export {};
@@ -1,15 +0,0 @@
1
- export interface MediaInfo {
2
- media_id: string;
3
- url: string;
4
- updated_at?: number;
5
- }
6
- declare class UploadCacheStore {
7
- private cache;
8
- constructor();
9
- private load;
10
- private save;
11
- get(md5: string): MediaInfo;
12
- set(md5: string, mediaId: string, url: string): void;
13
- }
14
- export declare const uploadCacheStore: UploadCacheStore;
15
- export {};