mdts 0.8.2 → 0.9.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.
@@ -1,10 +1,25 @@
1
+ :root {
2
+ --markdown-border-color: rgba(0, 0, 0, .12);
3
+ --markdown-pre-background-color: #f4f5f7;
4
+ --markdown-code-background-color: #f4f5f7;
5
+ --markdown-blockquote-color: rgba(0, 0, 0, .24);
6
+ --markdown-link-color: #1976d2;
7
+ }
8
+
9
+ [data-theme="dark"] {
10
+ --markdown-border-color: rgba(255, 255, 255, .12);
11
+ --markdown-pre-background-color: #161819;
12
+ --markdown-code-background-color: #161819;
13
+ --markdown-blockquote-color: rgba(255, 255, 255, .24);
14
+ }
15
+
1
16
  .markdown-body {
2
17
  h1 {
3
18
  margin: 48px 0 24px;
4
19
  padding-bottom: 16px;
5
20
  font-weight: 500;
6
21
  font-size: 26px;
7
- border-bottom: 1px solid rgba(0, 0, 0, .12);
22
+ border-bottom: 1px solid var(--markdown-border-color);
8
23
  }
9
24
 
10
25
  h2 {
@@ -12,7 +27,7 @@
12
27
  padding-bottom: 10px;
13
28
  font-weight: 500;
14
29
  font-size: 22px;
15
- border-bottom: 1px solid rgba(0, 0, 0, .12);
30
+ border-bottom: 1px solid var(--markdown-border-color);
16
31
  }
17
32
 
18
33
  h3 {
@@ -56,7 +71,7 @@
56
71
  hr {
57
72
  margin: 48px 0;
58
73
  border: 0;
59
- border-bottom: 1px solid rgba(0, 0, 0, .12);
74
+ border-bottom: 1px solid var(--markdown-border-color);
60
75
  }
61
76
 
62
77
  img {
@@ -76,12 +91,12 @@
76
91
  }
77
92
 
78
93
  tr {
79
- border-top: 1px solid rgba(0, 0, 0, .12);
94
+ border-top: 1px solid var(--markdown-border-color);
80
95
  }
81
96
 
82
97
  td, th {
83
98
  padding: 6px 12px;
84
- border: 1px solid rgba(0, 0, 0, .12);
99
+ border: 1px solid var(--markdown-border-color);
85
100
  }
86
101
  }
87
102
 
@@ -89,7 +104,7 @@
89
104
  padding: 16px;
90
105
  overflow: auto;
91
106
  font-size: 0.85rem;
92
- background-color: #f4f5f7;
107
+ background-color: var(--markdown-pre-background-color);
93
108
 
94
109
  code {
95
110
  padding: 0;
@@ -105,7 +120,7 @@
105
120
  padding: .1em .6em;
106
121
  margin: 0;
107
122
  font-size: 80%;
108
- background-color: #f4f5f7;
123
+ background-color: var(--markdown-code-background-color);
109
124
  border-radius: 2px;
110
125
  }
111
126
 
@@ -113,8 +128,8 @@
113
128
  margin: 24px 0;
114
129
  padding: 5px 16px;
115
130
  font-size: 14px;
116
- color: rgba(0, 0, 0, .24);
117
- border-left: 4px solid rgba(0, 0, 0, .12);
131
+ color: var(--markdown-blockquote-color);
132
+ border-left: 4px solid var(--markdown-border-color);
118
133
 
119
134
  blockquote {
120
135
  margin: 12px 0;
@@ -126,7 +141,7 @@
126
141
  }
127
142
 
128
143
  a {
129
- color: #1976d2;
144
+ color: var(--markdown-link-color);
130
145
  transition: color 0.1s ease-in-out;
131
146
 
132
147
  &:hover {
@@ -135,40 +150,3 @@
135
150
  }
136
151
  }
137
152
  }
138
-
139
- .markdown-body.dark {
140
- h1 {
141
- border-color: rgba(255, 255, 255, .12);
142
- }
143
-
144
- h2 {
145
- border-color: rgba(255, 255, 255, .12);
146
- }
147
-
148
- table {
149
- tr {
150
- border-color: rgba(255, 255, 255, .12);
151
- }
152
-
153
- td, th {
154
- border-color: rgba(255, 255, 255, .12);
155
- }
156
- }
157
-
158
- pre {
159
- background-color: #161819;
160
- }
161
-
162
- code {
163
- background-color: #161819;
164
- }
165
-
166
- blockquote {
167
- color: rgba(255, 255, 255, .24);
168
- border-color: rgba(255, 255, 255, .12);
169
- }
170
-
171
- hr {
172
- border-color: rgba(255, 255, 255, .12);
173
- }
174
- }
@@ -17,6 +17,7 @@ const express_1 = require("express");
17
17
  const fs_1 = __importDefault(require("fs"));
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const simple_git_1 = __importDefault(require("simple-git"));
20
+ const constants_1 = require("../../constants");
20
21
  const fileTreeRouter = (directory) => {
21
22
  const router = (0, express_1.Router)();
22
23
  const git = (0, simple_git_1.default)({ baseDir: directory });
@@ -32,12 +33,8 @@ exports.fileTreeRouter = fileTreeRouter;
32
33
  const isDotFileOrDirectory = (entryName) => {
33
34
  return entryName.startsWith('.');
34
35
  };
35
- const isLibraryDirectory = (entryName) => {
36
- const libraryDirs = ['node_modules', 'vendor', 'bundle', 'venv', 'env', 'site-packages'];
37
- return libraryDirs.includes(entryName);
38
- };
39
36
  const shouldIncludeEntry = (entry) => {
40
- return !isDotFileOrDirectory(entry.name) && !isLibraryDirectory(entry.name);
37
+ return !isDotFileOrDirectory(entry.name) && !constants_1.EXCLUDED_DIRECTORIES.includes(entry.name);
41
38
  };
42
39
  const getFileTree = (baseDirectory, currentRelativePath, gitStatus) => __awaiter(void 0, void 0, void 0, function* () {
43
40
  const fullPath = path_1.default.join(baseDirectory, currentRelativePath);
@@ -1,46 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.setupWatcher = void 0;
40
7
  const chokidar_1 = __importDefault(require("chokidar"));
41
- const fs = __importStar(require("fs"));
42
8
  const ws_1 = require("ws");
43
9
  const logger_1 = require("../utils/logger");
10
+ const constants_1 = require("../constants");
44
11
  let contentWatcher = null;
45
12
  let currentWatchedFile = null;
46
13
  const setupWatcher = (directory, server, port) => {
@@ -79,19 +46,18 @@ const handleWebSocketClose = (wss) => {
79
46
  const setupDirectoryWatcher = (directory, wss) => {
80
47
  try {
81
48
  const watcher = chokidar_1.default.watch(directory, {
82
- ignored: (watchedFilePath) => {
83
- if (watchedFilePath.includes('node_modules')) {
49
+ ignored: (watchedFilePath, stats) => {
50
+ if (constants_1.EXCLUDED_DIRECTORIES.some(p => watchedFilePath.includes(`/${p}`))) {
84
51
  return true;
85
52
  }
86
- try {
87
- if (fs.statSync(watchedFilePath).isDirectory()) {
88
- return false;
89
- }
53
+ if (stats) {
54
+ return !stats.isDirectory();
90
55
  }
91
- catch (_a) {
56
+ else {
57
+ // If stats is undefined, it's a directory that hasn't been scanned yet.
58
+ // We want to traverse directories, so don't ignore.
92
59
  return false;
93
60
  }
94
- return !isMarkdownOrSimpleAsset(watchedFilePath);
95
61
  },
96
62
  ignoreInitial: true,
97
63
  });
@@ -107,6 +73,15 @@ const setupDirectoryWatcher = (directory, wss) => {
107
73
  client.send(JSON.stringify({ type: 'reload-tree' }));
108
74
  });
109
75
  });
76
+ watcher.on('error', (error) => {
77
+ watcher.unwatch(directory);
78
+ watcher.close()
79
+ .then((a) => console.log(a));
80
+ logger_1.logger.error('🚫 Error watching directory:', error);
81
+ logger_1.logger.error('Livereload will be disabled');
82
+ if (error && typeof error === 'object' && 'code' in error && error.code === 'EMFILE')
83
+ logger_1.logger.error('This error is likely caused by too many open files. Try increasing the ulimit.');
84
+ });
110
85
  return watcher;
111
86
  }
112
87
  catch (e) {
@@ -130,7 +105,3 @@ const setupContentWatcher = (ws, filePath) => {
130
105
  });
131
106
  }
132
107
  };
133
- const isMarkdownOrSimpleAsset = (filePath) => {
134
- const ext = filePath.toLowerCase().split('.').pop();
135
- return !!ext && (ext === 'md' || ext === 'markdown');
136
- };
@@ -27,7 +27,7 @@ class Logger {
27
27
  error(message, ...args) {
28
28
  import('chalk')
29
29
  .then((module) => module.default)
30
- .then(chalk => { console.error(chalk.bgRed.white(' Error '), message, ...args); });
30
+ .then(chalk => { console.error(chalk.bgRed.black(' Error'.padEnd(14, ' ')), message, ...args); });
31
31
  }
32
32
  getTagColor(tag) {
33
33
  return import('chalk').then((module) => module.default).then(chalk => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdts",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "A markdown preview server.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,8 +15,11 @@
15
15
  "build:frontend": "cd packages/frontend && npm run build",
16
16
  "jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js",
17
17
  "watch": "npm run jest -- --watch",
18
+ "watch:frontend": "cd packages/frontend && npm run jest -- --watch",
18
19
  "test": "npm run jest -- --selectProjects test",
20
+ "test:frontend": "cd packages/frontend && npm run jest -- --selectProjects test",
19
21
  "lint": "npm run jest -- --selectProjects lint",
22
+ "lint:frontend": "cd packages/frontend && npm run jest -- --selectProjects lint",
20
23
  "start": "npm run build && npm run build:frontend && node dist/index.js",
21
24
  "dev": "npm run build && npm run build:frontend && tsc --watch --preserveWatchOutput & cd packages/frontend && npm run build -- --watch & node dist/index.js"
22
25
  },
@@ -36,7 +39,7 @@
36
39
  "bugs": {
37
40
  "url": "https://github.com/unhappychoice/mdts/issues"
38
41
  },
39
- "homepage": "https://github.com/unhappychoice/mdts#readme",
42
+ "homepage": "https://mdts.unhappychoice.com",
40
43
  "devDependencies": {
41
44
  "@types/commander": "^2.12.0",
42
45
  "@types/express": "^4.17.21",