mdts 0.1.0 → 0.1.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/bin/mdts +3 -0
- package/dist/cli.js +7 -14
- package/dist/index.js +2 -4
- package/dist/server.js +11 -18
- package/package.json +2 -2
package/bin/mdts
ADDED
package/dist/cli.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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");
|
|
1
|
+
import { serve } from './server.js';
|
|
2
|
+
import open from 'open';
|
|
3
|
+
import { Command } from 'commander';
|
|
10
4
|
const DEFAULT_PORT = 8521;
|
|
11
5
|
const DEFAULT_DIRECTORY = '.';
|
|
12
|
-
const cli = () => {
|
|
13
|
-
const program = new
|
|
6
|
+
export const cli = () => {
|
|
7
|
+
const program = new Command();
|
|
14
8
|
program
|
|
15
9
|
.option('-p, --port <port>', 'Port to serve on', String(DEFAULT_PORT))
|
|
16
10
|
.argument('[directory]', 'Directory to serve', DEFAULT_DIRECTORY)
|
|
17
11
|
.action((directory, options) => {
|
|
18
12
|
const port = parseInt(options.port, 10);
|
|
19
|
-
|
|
20
|
-
(
|
|
13
|
+
serve(directory, port);
|
|
14
|
+
open(`http://localhost:${port}`);
|
|
21
15
|
});
|
|
22
16
|
program.parse(process.argv);
|
|
23
17
|
};
|
|
24
|
-
exports.cli = cli;
|
package/dist/index.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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'));
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
export const serve = (directory, port) => {
|
|
5
|
+
const app = express();
|
|
6
|
+
app.use(express.static('public'));
|
|
7
|
+
app.use(express.static('dist/frontend'));
|
|
14
8
|
app.get('/filetree', (req, res) => {
|
|
15
9
|
res.json(getFileTree(directory, '')); // Pass empty string as initial relative path
|
|
16
10
|
});
|
|
17
|
-
app.use('/content',
|
|
11
|
+
app.use('/content', express.static(directory));
|
|
18
12
|
// Catch-all route to serve index.html for any other requests
|
|
19
13
|
app.get('*', (req, res) => {
|
|
20
|
-
res.sendFile(
|
|
14
|
+
res.sendFile(path.join(__dirname, '../public/index.html'));
|
|
21
15
|
});
|
|
22
16
|
app.listen(port, () => {
|
|
23
17
|
console.log(`Server listening at http://localhost:${port}`);
|
|
24
18
|
});
|
|
25
19
|
};
|
|
26
|
-
|
|
27
|
-
const getFileTree = (baseDirectory, currentRelativePath) => fs_1.default.readdirSync(path_1.default.join(baseDirectory, currentRelativePath), { withFileTypes: true })
|
|
20
|
+
const getFileTree = (baseDirectory, currentRelativePath) => fs.readdirSync(path.join(baseDirectory, currentRelativePath), { withFileTypes: true })
|
|
28
21
|
.map((entry) => {
|
|
29
|
-
const entryPath =
|
|
22
|
+
const entryPath = path.join(currentRelativePath, entry.name);
|
|
30
23
|
return entry.isDirectory()
|
|
31
24
|
? { [entry.name]: getFileTree(baseDirectory, entryPath) }
|
|
32
25
|
: entryPath; // Return full relative path for files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A markdown preview server.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"author": "unhappychoice",
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"type": "
|
|
33
|
+
"type": "module",
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/unhappychoice/mdts/issues"
|
|
36
36
|
},
|