nodebb-plugin-katex2 1.0.1 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-katex2",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "KaTeX math rendering plugin for NodeBB",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -1,27 +1,90 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
1
4
  const fs = require("fs");
2
5
  const path = require("path");
3
6
 
4
- const sourceDir = path.join(__dirname, "../node_modules/katex/dist");
5
- const targetDir = path.join(__dirname, "../static/katex");
7
+ function copyDir(src, dest) {
8
+ if (!fs.existsSync(dest)) {
9
+ fs.mkdirSync(dest, { recursive: true });
10
+ }
11
+
12
+ const entries = fs.readdirSync(src, { withFileTypes: true });
6
13
 
7
- // Создаем целевую директорию если её нет
8
- if (!fs.existsSync(targetDir)) {
9
- fs.mkdirSync(targetDir, { recursive: true });
14
+ for (const entry of entries) {
15
+ const srcPath = path.join(src, entry.name);
16
+ const destPath = path.join(dest, entry.name);
17
+
18
+ if (entry.isDirectory()) {
19
+ copyDir(srcPath, destPath);
20
+ } else {
21
+ fs.copyFileSync(srcPath, destPath);
22
+ }
23
+ }
10
24
  }
11
25
 
12
- // Копируем файлы
13
- function copyRecursive(src, dest) {
14
- if (fs.statSync(src).isDirectory()) {
15
- if (!fs.existsSync(dest)) {
16
- fs.mkdirSync(dest, { recursive: true });
26
+ function findKatexDist() {
27
+ const pluginRoot = path.resolve(__dirname, "..");
28
+
29
+ // Все возможные пути поиска
30
+ const searchPaths = [
31
+ // 1. Локальный node_modules плагина
32
+ path.join(pluginRoot, "node_modules", "katex", "dist"),
33
+ // 2. Hoisted в NodeBB (2 уровня вверх)
34
+ path.join(pluginRoot, "..", "..", "node_modules", "katex", "dist"),
35
+ // 3. Hoisted выше (3 уровня)
36
+ path.join(pluginRoot, "..", "..", "..", "node_modules", "katex", "dist"),
37
+ // 4. В соседней папке (параллельно плагину)
38
+ path.join(pluginRoot, "..", "katex", "dist"),
39
+ ];
40
+
41
+ console.log("[KaTeX] Searching for katex dist...");
42
+ for (const searchPath of searchPaths) {
43
+ console.log(" Checking:", searchPath);
44
+ if (fs.existsSync(searchPath)) {
45
+ console.log("[KaTeX] ✓ Found at:", searchPath);
46
+ return searchPath;
17
47
  }
18
- fs.readdirSync(src).forEach((file) => {
19
- copyRecursive(path.join(src, file), path.join(dest, file));
20
- });
21
- } else {
22
- fs.copyFileSync(src, dest);
23
48
  }
49
+
50
+ return null;
24
51
  }
25
52
 
26
- copyRecursive(sourceDir, targetDir);
27
- console.log("KaTeX files copied successfully");
53
+ try {
54
+ console.log("[KaTeX Plugin] Running postinstall...");
55
+
56
+ const pluginRoot = path.resolve(__dirname, "..");
57
+ const katexDest = path.join(pluginRoot, "static", "katex");
58
+
59
+ // Ищем KaTeX
60
+ const katexSource = findKatexDist();
61
+
62
+ if (!katexSource) {
63
+ console.warn("[KaTeX] WARNING: katex not found!");
64
+ console.warn("[KaTeX] This is normal during initial npm install.");
65
+ console.warn(
66
+ "[KaTeX] Run 'npm rebuild nodebb-plugin-katex2' after installation completes.",
67
+ );
68
+ // Не блокируем установку
69
+ process.exit(0);
70
+ }
71
+
72
+ // Удаляем старую директорию
73
+ if (fs.existsSync(katexDest)) {
74
+ console.log("[KaTeX] Removing old directory...");
75
+ fs.rmSync(katexDest, { recursive: true, force: true });
76
+ }
77
+
78
+ // Копируем файлы
79
+ console.log("[KaTeX] Copying files...");
80
+ console.log("[KaTeX] From:", katexSource);
81
+ console.log("[KaTeX] To:", katexDest);
82
+
83
+ copyDir(katexSource, katexDest);
84
+
85
+ console.log("[KaTeX] ✓ Postinstall completed!");
86
+ } catch (err) {
87
+ console.error("[KaTeX] ✗ Postinstall failed:", err.message);
88
+ // Не блокируем установку
89
+ process.exit(0);
90
+ }