mdts 0.17.0 → 0.18.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/README.md +4 -0
- package/dist/cli.js +29 -11
- package/dist/frontend/bundle.js +10 -10
- package/dist/frontend/markdown.css +40 -0
- package/dist/server/server.js +29 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,3 +103,7 @@ Experience mdts in action with real examples and interactive features.
|
|
|
103
103
|
|
|
104
104
|
Found a bug? Have an idea? Want to send a PR?
|
|
105
105
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) for details — we'd love to have your help!
|
|
106
|
+
|
|
107
|
+
## Author
|
|
108
|
+
|
|
109
|
+
[@unhappychoice](https://unhappychoice.com)
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -15,7 +24,7 @@ const DEFAULT_DIRECTORY = '.';
|
|
|
15
24
|
class CLI {
|
|
16
25
|
run() {
|
|
17
26
|
return this.requireOpen()
|
|
18
|
-
.then((open) => {
|
|
27
|
+
.then((open) => __awaiter(this, void 0, void 0, function* () {
|
|
19
28
|
const program = new commander_1.Command();
|
|
20
29
|
const packageJsonPath = path_1.default.join(__dirname, '..', 'package.json');
|
|
21
30
|
const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf8'));
|
|
@@ -23,37 +32,46 @@ class CLI {
|
|
|
23
32
|
.version(packageJson.version)
|
|
24
33
|
.description('A zero-config CLI tool to preview local Markdown files in a browser')
|
|
25
34
|
.option('-H, --host <host>', 'host to listen on', 'localhost')
|
|
26
|
-
.option('-p, --port <port>', 'port to serve on', String(DEFAULT_PORT))
|
|
35
|
+
.option('-p, --port <port>', 'port to serve on (use "auto" to find an available port)', String(DEFAULT_PORT))
|
|
27
36
|
.option('-s, --silent', 'suppress server logs', false)
|
|
28
37
|
.option('--no-open', 'do not open the browser automatically')
|
|
29
38
|
.option('-g, --glob <patterns...>', 'glob patterns to filter markdown files (e.g. "docs/*.md")')
|
|
30
39
|
.argument('[directory]', 'directory to serve', DEFAULT_DIRECTORY)
|
|
31
|
-
.action((directory, options) => {
|
|
40
|
+
.action((directory, options) => __awaiter(this, void 0, void 0, function* () {
|
|
32
41
|
logger_1.logger.setSilent(options.silent);
|
|
33
42
|
logger_1.logger.showLogo();
|
|
34
43
|
logger_1.logger.log('Announcement', '🎉 Thanks for using mdts!');
|
|
35
44
|
logger_1.logger.log('Announcement', '✨ Like it? Star it on GitHub: https://github.com/unhappychoice/mdts');
|
|
36
45
|
logger_1.logger.log('CLI', '⚙ Options: ' + JSON.stringify(options));
|
|
37
|
-
const
|
|
46
|
+
const autoPort = options.port === 'auto';
|
|
47
|
+
const port = autoPort ? DEFAULT_PORT : parseInt(options.port, 10);
|
|
38
48
|
const host = options.host;
|
|
39
49
|
const absoluteDirectory = path_1.default.resolve(process.cwd(), directory);
|
|
40
50
|
const context = options.glob
|
|
41
51
|
? (0, glob_1.resolveGlobPatterns)(absoluteDirectory, options.glob)
|
|
42
52
|
: { directory: absoluteDirectory };
|
|
43
|
-
|
|
53
|
+
let actualPort;
|
|
54
|
+
try {
|
|
55
|
+
({ port: actualPort } = yield (0, server_1.serve)(context, port, host, autoPort));
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
logger_1.logger.error(`❌ Failed to start server: ${err instanceof Error ? err.message : err}`);
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
44
62
|
const readmePath = path_1.default.join(context.directory, 'README.md');
|
|
45
63
|
const initialPath = (0, fs_1.existsSync)(readmePath) ? '/README.md' : '';
|
|
46
64
|
const displayHost = (host === '0.0.0.0' || host === '::') ? 'localhost' : host;
|
|
47
65
|
if (options.open) {
|
|
48
|
-
logger_1.logger.log('CLI', `🌐 Opening browser at http://${displayHost}:${
|
|
49
|
-
open(`http://${displayHost}:${
|
|
66
|
+
logger_1.logger.log('CLI', `🌐 Opening browser at http://${displayHost}:${actualPort}${initialPath}`);
|
|
67
|
+
open(`http://${displayHost}:${actualPort}${initialPath}`);
|
|
50
68
|
}
|
|
51
69
|
else {
|
|
52
|
-
logger_1.logger.log('CLI', `🌐 Server running at http://${displayHost}:${
|
|
70
|
+
logger_1.logger.log('CLI', `🌐 Server running at http://${displayHost}:${actualPort}${initialPath}`);
|
|
53
71
|
}
|
|
54
|
-
});
|
|
55
|
-
program.
|
|
56
|
-
});
|
|
72
|
+
}));
|
|
73
|
+
yield program.parseAsync(process.argv);
|
|
74
|
+
}));
|
|
57
75
|
}
|
|
58
76
|
requireOpen() {
|
|
59
77
|
return import('open').then((module) => module.default);
|