mdts 0.1.1 → 0.1.3
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 +1 -1
- package/dist/cli.js +7 -14
- package/dist/index.js +2 -4
- package/dist/server.js +15 -18
- package/package.json +2 -2
package/bin/mdts
CHANGED
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,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
8
|
+
export const serve = (directory, port) => {
|
|
9
|
+
const app = express();
|
|
10
|
+
app.use(express.static('public'));
|
|
11
|
+
app.use(express.static('dist/frontend'));
|
|
14
12
|
app.get('/filetree', (req, res) => {
|
|
15
13
|
res.json(getFileTree(directory, '')); // Pass empty string as initial relative path
|
|
16
14
|
});
|
|
17
|
-
app.use('/content',
|
|
15
|
+
app.use('/content', express.static(directory));
|
|
18
16
|
// Catch-all route to serve index.html for any other requests
|
|
19
17
|
app.get('*', (req, res) => {
|
|
20
|
-
res.sendFile(
|
|
18
|
+
res.sendFile(path.join(__dirname, '../public/index.html'));
|
|
21
19
|
});
|
|
22
20
|
app.listen(port, () => {
|
|
23
21
|
console.log(`Server listening at http://localhost:${port}`);
|
|
24
22
|
});
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
const getFileTree = (baseDirectory, currentRelativePath) => fs_1.default.readdirSync(path_1.default.join(baseDirectory, currentRelativePath), { withFileTypes: true })
|
|
24
|
+
const getFileTree = (baseDirectory, currentRelativePath) => fs.readdirSync(path.join(baseDirectory, currentRelativePath), { withFileTypes: true })
|
|
28
25
|
.map((entry) => {
|
|
29
|
-
const entryPath =
|
|
26
|
+
const entryPath = path.join(currentRelativePath, entry.name);
|
|
30
27
|
return entry.isDirectory()
|
|
31
28
|
? { [entry.name]: getFileTree(baseDirectory, entryPath) }
|
|
32
29
|
: 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.3",
|
|
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
|
},
|