nodebb-plugin-katex2 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-katex2",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "KaTeX math rendering plugin for NodeBB",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -27,6 +27,7 @@
27
27
  "eslint": "^9.35.0"
28
28
  },
29
29
  "scripts": {
30
+ "postinstall": "node scripts/copy-katex.js",
30
31
  "lint": "eslint lib/ static/js/",
31
32
  "fix": "eslint --fix lib/ static/js/"
32
33
  },
package/plugin.json CHANGED
@@ -13,6 +13,6 @@
13
13
  "scripts": ["static/js/render.js"],
14
14
  "stylesheets": ["static/css/katex.css"],
15
15
  "staticDirs": {
16
- "katex": "./node_modules/katex/dist"
16
+ "katex": "./static/katex"
17
17
  }
18
18
  }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ function copyDir(src, dest) {
7
+ if (!fs.existsSync(dest)) {
8
+ fs.mkdirSync(dest, { recursive: true });
9
+ }
10
+
11
+ const entries = fs.readdirSync(src, { withFileTypes: true });
12
+
13
+ for (const entry of entries) {
14
+ const srcPath = path.join(src, entry.name);
15
+ const destPath = path.join(dest, entry.name);
16
+
17
+ if (entry.isDirectory()) {
18
+ copyDir(srcPath, destPath);
19
+ } else {
20
+ fs.copyFileSync(srcPath, destPath);
21
+ }
22
+ }
23
+ }
24
+
25
+ function findKatexDist() {
26
+ const pluginRoot = path.resolve(__dirname, "..");
27
+
28
+ // Вариант 1: Локальный node_modules плагина
29
+ const localPath = path.join(pluginRoot, "node_modules", "katex", "dist");
30
+ if (fs.existsSync(localPath)) {
31
+ console.log("[KaTeX] Found in local node_modules");
32
+ return localPath;
33
+ }
34
+
35
+ // Вариант 2: Hoisted в корень NodeBB (../../node_modules/katex)
36
+ const hoistedPath = path.join(
37
+ pluginRoot,
38
+ "..",
39
+ "..",
40
+ "node_modules",
41
+ "katex",
42
+ "dist",
43
+ );
44
+ if (fs.existsSync(hoistedPath)) {
45
+ console.log("[KaTeX] Found in hoisted node_modules");
46
+ return hoistedPath;
47
+ }
48
+
49
+ return null;
50
+ }
51
+
52
+ try {
53
+ console.log("[KaTeX Plugin] Running postinstall...");
54
+
55
+ const pluginRoot = path.resolve(__dirname, "..");
56
+ const katexSource = findKatexDist();
57
+ const katexDest = path.join(pluginRoot, "static", "katex");
58
+
59
+ if (!katexSource) {
60
+ console.error("[KaTeX] ERROR: katex not found!");
61
+ process.exit(1);
62
+ }
63
+
64
+ if (fs.existsSync(katexDest)) {
65
+ fs.rmSync(katexDest, { recursive: true, force: true });
66
+ }
67
+
68
+ console.log("[KaTeX] Copying from:", katexSource);
69
+ console.log("[KaTeX] Copying to:", katexDest);
70
+
71
+ copyDir(katexSource, katexDest);
72
+
73
+ console.log("[KaTeX] Postinstall completed!");
74
+ } catch (err) {
75
+ console.error("[KaTeX] Postinstall failed:", err);
76
+ process.exit(1);
77
+ }