mdts 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 unhappychoice
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ <h1 align="center">
2
+ <img src="docs/logo.svg" alt="mdts" width="400">
3
+ </h1>
4
+
5
+ `mdts` (MarkDown Tree Server) is a simple command-line tool that serves Markdown files from a specified local directory and provides a web-based interface to browse and view them. It automatically opens the served content in your default web browser.
6
+
7
+ ## Features
8
+
9
+ - **File Tree Navigation**: Provides a hierarchical view of your Markdown files for easy browsing.
10
+ - **Markdown Rendering**: Renders Markdown files in a clean, readable format.
11
+ - [WIP] **Live Reload**:
12
+
13
+ ![screenshot](docs/screenshot.png)
14
+
15
+
16
+ ## Usage
17
+ ```bash
18
+ npx mdts
19
+ ```
20
+
21
+ By default, `mdts` will serve files from the current directory (`.`) on port `8521`. It will automatically open a new tab in your web browser pointing to `http://localhost:8521`.
22
+
23
+ ### Options
24
+
25
+ You can specify a different directory and port:
26
+
27
+ ```bash
28
+ npx mdts [directory] --port 8000
29
+ ```
30
+
31
+ - `-p, --port <port>`: Specify the port to serve on (default: `8521`)
32
+ - `[directory]`: Specify the directory to serve (default: current directory `.`)
33
+
34
+ **Example:**
35
+
36
+ To serve Markdown files from the `docs` directory on port `3000`:
37
+
38
+ ```bash
39
+ npx mdts docs -p 3000
40
+ ```
41
+
42
+ ## Development
43
+
44
+ To build the project:
45
+
46
+ ```bash
47
+ npm run build & npm run build:frontend
48
+ ```
49
+
50
+ To start the server:
51
+ ```bash
52
+ npm start
53
+ ```
54
+
55
+ ## License
56
+
57
+ This project is licensed under the MIT License. See the `LICENSE` file for details.
package/dist/cli.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cli = void 0;
7
+ const server_1 = require("./server");
8
+ const open_1 = __importDefault(require("open"));
9
+ const commander_1 = require("commander");
10
+ const DEFAULT_PORT = 8521;
11
+ const DEFAULT_DIRECTORY = '.';
12
+ const cli = () => {
13
+ const program = new commander_1.Command();
14
+ program
15
+ .option('-p, --port <port>', 'Port to serve on', String(DEFAULT_PORT))
16
+ .argument('[directory]', 'Directory to serve', DEFAULT_DIRECTORY)
17
+ .action((directory, options) => {
18
+ const port = parseInt(options.port, 10);
19
+ (0, server_1.serve)(directory, port);
20
+ (0, open_1.default)(`http://localhost:${port}`);
21
+ });
22
+ program.parse(process.argv);
23
+ };
24
+ exports.cli = cli;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("./cli");
4
+ (0, cli_1.cli)();
package/dist/server.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.serve = void 0;
7
+ const express_1 = __importDefault(require("express"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const serve = (directory, port) => {
11
+ const app = (0, express_1.default)();
12
+ app.use(express_1.default.static('public'));
13
+ app.use(express_1.default.static('dist/frontend'));
14
+ app.get('/filetree', (req, res) => {
15
+ res.json(getFileTree(directory, '')); // Pass empty string as initial relative path
16
+ });
17
+ app.use('/content', express_1.default.static(directory));
18
+ // Catch-all route to serve index.html for any other requests
19
+ app.get('*', (req, res) => {
20
+ res.sendFile(path_1.default.join(__dirname, '../public/index.html'));
21
+ });
22
+ app.listen(port, () => {
23
+ console.log(`Server listening at http://localhost:${port}`);
24
+ });
25
+ };
26
+ exports.serve = serve;
27
+ const getFileTree = (baseDirectory, currentRelativePath) => fs_1.default.readdirSync(path_1.default.join(baseDirectory, currentRelativePath), { withFileTypes: true })
28
+ .map((entry) => {
29
+ const entryPath = path_1.default.join(currentRelativePath, entry.name);
30
+ return entry.isDirectory()
31
+ ? { [entry.name]: getFileTree(baseDirectory, entryPath) }
32
+ : entryPath; // Return full relative path for files
33
+ });
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "mdts",
3
+ "version": "0.1.0",
4
+ "description": "A markdown preview server.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "mdts": "./bin/mdts"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "build": "tsc",
16
+ "prepublishOnly": "npm run build",
17
+ "start": "npm run build:frontend && npm run build && node dist/index.js",
18
+ "build:frontend": "webpack --config webpack.config.js"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/unhappychoice/mdts.git"
23
+ },
24
+ "keywords": [
25
+ "markdown",
26
+ "preview",
27
+ "server",
28
+ "cli",
29
+ "live-reload"
30
+ ],
31
+ "author": "unhappychoice",
32
+ "license": "MIT",
33
+ "type": "commonjs",
34
+ "bugs": {
35
+ "url": "https://github.com/unhappychoice/mdts/issues"
36
+ },
37
+ "homepage": "https://github.com/unhappychoice/mdts#readme",
38
+ "devDependencies": {
39
+ "@babel/core": "^7.28.0",
40
+ "@babel/preset-env": "^7.28.0",
41
+ "@babel/preset-react": "^7.27.1",
42
+ "@babel/preset-typescript": "^7.27.1",
43
+ "@emotion/react": "^11.11.4",
44
+ "@emotion/styled": "^11.11.5",
45
+ "@mui/material": "^7.2.0",
46
+ "@types/commander": "^2.12.0",
47
+ "@types/express": "^4.17.21",
48
+ "@types/markdown-it": "^14.1.2",
49
+ "@types/react": "^19.1.8",
50
+ "@types/react-dom": "^19.1.6",
51
+ "babel-loader": "^10.0.0",
52
+ "css-loader": "^7.1.2",
53
+ "html-webpack-plugin": "^5.6.3",
54
+ "style-loader": "^4.0.0",
55
+ "ts-node": "^10.9.2",
56
+ "typescript": "^5.8.3",
57
+ "webpack": "^5.100.1",
58
+ "webpack-cli": "^6.0.1"
59
+ },
60
+ "dependencies": {
61
+ "@mui/icons-material": "^7.2.0",
62
+ "@mui/x-tree-view": "^8.8.0",
63
+ "commander": "^14.0.0",
64
+ "express": "^4.19.2",
65
+ "open": "^10.1.2",
66
+ "react": "^19.1.0",
67
+ "react-dom": "^19.1.0",
68
+ "react-markdown": "^10.1.0",
69
+ "remark-gfm": "^4.0.1"
70
+ }
71
+ }