mdts 0.3.1 → 0.3.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/dist/server/server.js +30 -4
- package/package.json +1 -1
package/dist/server/server.js
CHANGED
|
@@ -52,20 +52,46 @@ export const serve = (directory, port) => {
|
|
|
52
52
|
console.log(`🚀 Server listening at http://localhost:${port}`);
|
|
53
53
|
});
|
|
54
54
|
const wss = new WebSocketServer({ server });
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const isMarkdownOrSimpleAsset = (filePath) => {
|
|
56
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
57
|
+
return (ext &&
|
|
58
|
+
(ext === 'md' ||
|
|
59
|
+
ext === 'markdown' ||
|
|
60
|
+
ext === 'png' ||
|
|
61
|
+
ext === 'jpg' ||
|
|
62
|
+
ext === 'jpeg' ||
|
|
63
|
+
ext === 'gif' ||
|
|
64
|
+
ext === 'svg'));
|
|
65
|
+
};
|
|
66
|
+
let watcher;
|
|
67
|
+
try {
|
|
68
|
+
watcher = chokidar.watch(directory, {
|
|
69
|
+
ignored: (filePath) => {
|
|
70
|
+
if (filePath.includes('node_modules')) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return !isMarkdownOrSimpleAsset(filePath);
|
|
74
|
+
},
|
|
75
|
+
ignoreInitial: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error('🚫 Error watching directory:', error);
|
|
80
|
+
console.error('Livereload will be disabled');
|
|
81
|
+
}
|
|
82
|
+
watcher === null || watcher === void 0 ? void 0 : watcher.on('change', (filePath) => {
|
|
57
83
|
console.log(`🔃 File changed: ${filePath}, reloading...`);
|
|
58
84
|
wss.clients.forEach((client) => {
|
|
59
85
|
client.send(JSON.stringify({ type: 'reload-content' }));
|
|
60
86
|
});
|
|
61
87
|
});
|
|
62
|
-
watcher.on('add', (filePath) => {
|
|
88
|
+
watcher === null || watcher === void 0 ? void 0 : watcher.on('add', (filePath) => {
|
|
63
89
|
console.log(`🌲 File added: ${filePath}, reloading tree...`);
|
|
64
90
|
wss.clients.forEach((client) => {
|
|
65
91
|
client.send(JSON.stringify({ type: 'reload-tree' }));
|
|
66
92
|
});
|
|
67
93
|
});
|
|
68
|
-
watcher.on('unlink', (filePath) => {
|
|
94
|
+
watcher === null || watcher === void 0 ? void 0 : watcher.on('unlink', (filePath) => {
|
|
69
95
|
console.log('🌲 File removed: ${filePath}, reloading tree...');
|
|
70
96
|
wss.clients.forEach((client) => {
|
|
71
97
|
client.send(JSON.stringify({ type: 'reload-tree' }));
|