mdzilla 0.0.3 → 0.0.5
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 +3 -1
- package/dist/_chunks/exporter.mjs +43 -5
- package/dist/_chunks/server.mjs +1882 -0
- package/dist/cli/main.mjs +25 -4
- package/dist/index.d.mts +3 -2
- package/package.json +2 -1
package/dist/cli/main.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { parseMeta, renderToAnsi, renderToText } from "md4x";
|
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
7
|
import { isAgent } from "std-env";
|
|
8
8
|
import { highlightText } from "@speed-highlight/core/terminal";
|
|
9
|
-
import { execSync } from "node:child_process";
|
|
9
|
+
import { exec, execSync } from "node:child_process";
|
|
10
10
|
//#region src/cli/_ansi.ts
|
|
11
11
|
const noColor = !!(process.env.NO_COLOR || process.env.TERM === "dumb" || !process.stdout.isTTY || isAgent);
|
|
12
12
|
const ESC = "\x1B[";
|
|
@@ -730,6 +730,14 @@ async function interactiveMode(docs) {
|
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
732
|
//#endregion
|
|
733
|
+
//#region src/cli/_utils.ts
|
|
734
|
+
function openInBrowser(url) {
|
|
735
|
+
const parsed = new URL(url);
|
|
736
|
+
if (parsed.hostname === "[::]" || parsed.hostname === "[::1]" || parsed.hostname === "127.0.0.1") parsed.hostname = "localhost";
|
|
737
|
+
url = parsed.href;
|
|
738
|
+
exec(process.platform === "win32" ? `start ${url}` : process.platform === "darwin" ? `open ${url}` : `xdg-open ${url}`, () => {});
|
|
739
|
+
}
|
|
740
|
+
//#endregion
|
|
733
741
|
//#region src/cli/main.ts
|
|
734
742
|
async function main() {
|
|
735
743
|
process.stdout.on("error", (err) => {
|
|
@@ -752,7 +760,8 @@ async function main() {
|
|
|
752
760
|
type: "boolean",
|
|
753
761
|
default: isAgent || !process.stdout.isTTY
|
|
754
762
|
},
|
|
755
|
-
headless: { type: "boolean" }
|
|
763
|
+
headless: { type: "boolean" },
|
|
764
|
+
tui: { type: "boolean" }
|
|
756
765
|
},
|
|
757
766
|
allowPositionals: true
|
|
758
767
|
});
|
|
@@ -762,7 +771,8 @@ async function main() {
|
|
|
762
771
|
if (values.help || !docsDir) return printUsage(!!docsDir);
|
|
763
772
|
const isURL = docsDir.startsWith("http://") || docsDir.startsWith("https://");
|
|
764
773
|
if (docsDir.endsWith(".md")) return singleFileMode(docsDir, plain, isURL);
|
|
765
|
-
const
|
|
774
|
+
const source = isURL ? new DocsSourceHTTP(docsDir) : docsDir.startsWith("gh:") ? new DocsSourceGit(docsDir) : docsDir.startsWith("npm:") ? new DocsSourceNpm(docsDir) : new DocsSourceFS(docsDir);
|
|
775
|
+
const docs = new DocsManager(source);
|
|
766
776
|
await docs.load();
|
|
767
777
|
if (exportDir) {
|
|
768
778
|
await exportDocsToFS(docs, exportDir, { plainText: plain });
|
|
@@ -776,7 +786,18 @@ async function main() {
|
|
|
776
786
|
}
|
|
777
787
|
if (pagePath && !plain) return pageMode(docs, pagePath, plain);
|
|
778
788
|
if (plain) return plainMode(docs, pagePath);
|
|
779
|
-
|
|
789
|
+
if (values.tui) interactiveMode(docs);
|
|
790
|
+
else {
|
|
791
|
+
const { serve } = await import("srvx");
|
|
792
|
+
const { createDocsServer } = await import("../_chunks/server.mjs");
|
|
793
|
+
const server = serve({
|
|
794
|
+
fetch: (await createDocsServer({ source })).fetch,
|
|
795
|
+
gracefulShutdown: false
|
|
796
|
+
});
|
|
797
|
+
await server.ready();
|
|
798
|
+
await server.fetch(new Request(new URL("/api/meta", server.url)));
|
|
799
|
+
openInBrowser(server.url);
|
|
800
|
+
}
|
|
780
801
|
}
|
|
781
802
|
main().catch((err) => {
|
|
782
803
|
showCursor();
|
package/dist/index.d.mts
CHANGED
|
@@ -156,8 +156,9 @@ interface ExportOptions {
|
|
|
156
156
|
/**
|
|
157
157
|
* Export documentation entries to a local filesystem directory as flat `.md` files.
|
|
158
158
|
*
|
|
159
|
-
* Each entry is written to `<dir>/<path>.md
|
|
160
|
-
*
|
|
159
|
+
* Each entry is written to `<dir>/<path>.md` (or `<dir>/<path>/index.md` for directory
|
|
160
|
+
* index pages). Navigation order is preserved via `order` frontmatter in pages and
|
|
161
|
+
* `.navigation.yml` files in directories.
|
|
161
162
|
*
|
|
162
163
|
* A `README.md` table of contents is generated at the root of the output directory.
|
|
163
164
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdzilla",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "pi0/mdzilla",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"giget": "^3.1.2",
|
|
35
35
|
"md4x": ">=0.0.22",
|
|
36
36
|
"mdream": "^0.16.0",
|
|
37
|
+
"srvx": "^0.11.9",
|
|
37
38
|
"std-env": "4.0.0-rc.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|