@mdocs/cli 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/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # @mdocs/cli
2
+
3
+ Command-line interface for mDocs — spins up a local documentation server that serves markdown files from cloned GitHub repositories.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install -g @mdocs/cli
9
+ ```
10
+
11
+ Or run without installing:
12
+
13
+ ```sh
14
+ npx @mdocs/cli <command>
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - Node.js >= 18
20
+ - Git (must be available in `PATH`)
21
+
22
+ ## Commands
23
+
24
+ ### `mdocs setup`
25
+
26
+ Initializes the `.mdocs/` project structure in the target directory.
27
+
28
+ ```sh
29
+ mdocs setup [options]
30
+ ```
31
+
32
+ | Option | Description | Default |
33
+ |---|---|---|
34
+ | `-d, --data-dir <dir>` | Directory to initialize | current working directory |
35
+
36
+ Creates:
37
+ ```
38
+ .mdocs/
39
+ └── repos/
40
+ ```
41
+
42
+ ### `mdocs serve`
43
+
44
+ Starts the mDocs local HTTP server. If `.mdocs/` does not exist, you will be prompted to initialize it first.
45
+
46
+ ```sh
47
+ mdocs serve [options]
48
+ ```
49
+
50
+ | Option | Description | Default |
51
+ |---|---|---|
52
+ | `-p, --port <port>` | Port to listen on | `4873` |
53
+ | `-H, --host <host>` | Host to bind to | `127.0.0.1` |
54
+ | `-d, --data-dir <dir>` | Directory containing `.mdocs/` | current working directory |
55
+ | `-o, --origin <origin>` | Extra CORS origin to allow | — |
56
+
57
+ **Examples:**
58
+
59
+ ```sh
60
+ # Start with defaults
61
+ mdocs serve
62
+
63
+ # Custom port
64
+ mdocs serve --port 5000
65
+
66
+ # Allow a custom frontend origin
67
+ mdocs serve --origin http://localhost:5173
68
+
69
+ # Point at a specific data directory
70
+ mdocs serve --data-dir /path/to/project
71
+ ```
72
+
73
+ Once running, the server is available at `http://127.0.0.1:4873` by default.
74
+
75
+ ## Typical workflow
76
+
77
+ ```sh
78
+ # 1. Initialize in your project
79
+ cd my-project
80
+ mdocs setup
81
+
82
+ # 2. Start the server
83
+ mdocs serve
84
+
85
+ # 3. Use the REST API to clone a repo and browse its docs
86
+ curl -X POST http://127.0.0.1:4873/api/repos/clone \
87
+ -H "Content-Type: application/json" \
88
+ -d '{"url": "https://github.com/owner/repo"}'
89
+ ```
90
+
91
+ ## REST API
92
+
93
+ The CLI delegates all HTTP logic to `@mdocs/server`. See the [`@mdocs/server` README](../server/README.md) for the full API reference.
94
+
95
+ ## Related packages
96
+
97
+ - [`@mdocs/server`](https://www.npmjs.com/package/@mdocs/server) — the underlying HTTP server (used internally by this CLI)
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+
6
+ // src/commands/serve.ts
7
+ import chalk2 from "chalk";
8
+ import inquirer from "inquirer";
9
+ import { startServer, DEFAULT_ORIGINS } from "@mdocs/server";
10
+
11
+ // src/lib/mdocs.ts
12
+ import { existsSync, mkdirSync } from "fs";
13
+ import { join } from "path";
14
+ var MDOCS_DIR = ".mdocs";
15
+ var REPOS_DIR = join(MDOCS_DIR, "repos");
16
+ function mdocsExists(cwd) {
17
+ return existsSync(join(cwd, MDOCS_DIR));
18
+ }
19
+ function reposDirExists(cwd) {
20
+ return existsSync(join(cwd, REPOS_DIR));
21
+ }
22
+ function createMdocsStructure(cwd) {
23
+ mkdirSync(join(cwd, REPOS_DIR), { recursive: true });
24
+ }
25
+ function resolveDataDir(dataDir) {
26
+ if (!dataDir) return process.cwd();
27
+ return dataDir.startsWith(".") ? join(process.cwd(), dataDir) : dataDir;
28
+ }
29
+
30
+ // src/commands/setup.ts
31
+ import chalk from "chalk";
32
+ async function runSetup(cwd) {
33
+ const dir = resolveDataDir(cwd);
34
+ console.log(chalk.dim("\n Setting up mDocs project structure...\n"));
35
+ createMdocsStructure(dir);
36
+ console.log(chalk.green(" \u2713") + chalk.white(` ${MDOCS_DIR}/`));
37
+ console.log(chalk.green(" \u2713") + chalk.white(` ${REPOS_DIR}/`));
38
+ console.log(chalk.bold.green("\n mDocs initialized successfully!\n"));
39
+ }
40
+
41
+ // src/lib/banner.ts
42
+ import gradient from "gradient-string";
43
+ import figlet from "figlet";
44
+ var GRADIENT = ["#06b6d4", "#8b5cf6", "#ec4899"];
45
+ function printBanner() {
46
+ const text = figlet.textSync("mDocs", { font: "ANSI Shadow" });
47
+ console.log(gradient(GRADIENT).multiline(text));
48
+ console.log();
49
+ }
50
+
51
+ // src/commands/serve.ts
52
+ async function serve(options) {
53
+ const cwd = resolveDataDir(options.dataDir);
54
+ const port = parseInt(options.port, 10);
55
+ const host = options.host;
56
+ if (!mdocsExists(cwd) || !reposDirExists(cwd)) {
57
+ console.log(chalk2.yellow("\n \u26A0 No .mdocs directory found in this project.\n"));
58
+ const { confirm } = await inquirer.prompt([
59
+ {
60
+ type: "confirm",
61
+ name: "confirm",
62
+ message: "Would you like to initialize mDocs for this project?",
63
+ default: true
64
+ }
65
+ ]);
66
+ if (!confirm) {
67
+ console.log(
68
+ chalk2.dim("\n Aborted. Run ") + chalk2.cyan("mdocs setup") + chalk2.dim(" to initialize manually.\n")
69
+ );
70
+ process.exit(0);
71
+ }
72
+ await runSetup(cwd);
73
+ }
74
+ console.log(chalk2.dim(`
75
+ Starting server on ${host}:${port}...
76
+ `));
77
+ const origins = options.origin ? [options.origin, ...DEFAULT_ORIGINS] : DEFAULT_ORIGINS;
78
+ const server = await startServer({ port, host, dataDir: cwd, origins });
79
+ printBanner();
80
+ console.log(
81
+ chalk2.bold(" Server running at ") + chalk2.bold.underline.cyan(`http://${host}:${port}`)
82
+ );
83
+ console.log(chalk2.dim(` Health: http://${host}:${port}/health`));
84
+ if (options.origin) {
85
+ console.log(chalk2.dim(` CORS origin: ${options.origin}`));
86
+ }
87
+ console.log(chalk2.dim("\n Press Ctrl+C to stop.\n"));
88
+ process.on("SIGINT", () => {
89
+ console.log(chalk2.dim("\n Stopping mDocs server\u2026\n"));
90
+ server.close(() => process.exit(0));
91
+ });
92
+ }
93
+
94
+ // src/index.ts
95
+ var program = new Command();
96
+ program.name("mdocs").description("mDocs \u2014 local documentation server").version("0.1.0");
97
+ program.command("serve").description("Start the mDocs local server").option("-p, --port <port>", "Port to listen on", "4873").option("-H, --host <host>", "Host to bind to", "127.0.0.1").option("-d, --data-dir <dir>", "Directory that holds (or will hold) .mdocs/").option("-o, --origin <origin>", "Allowed CORS origin").action(serve);
98
+ program.command("setup").description("Initialize .mdocs/ project structure in the current directory").option("-d, --data-dir <dir>", "Target directory (defaults to cwd)").action((opts) => runSetup(opts.dataDir));
99
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@mdocs/cli",
3
+ "version": "0.1.0",
4
+ "description": "mDocs CLI — start the local documentation server",
5
+ "type": "module",
6
+ "bin": {
7
+ "mdocs": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "dependencies": {
13
+ "chalk": "^5.3.0",
14
+ "commander": "^12.1.0",
15
+ "figlet": "^1.7.0",
16
+ "gradient-string": "^2.0.2",
17
+ "inquirer": "^9.2.23",
18
+ "@mdocs/server": "0.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/figlet": "^1.5.8",
22
+ "@types/node": "^20.14.0",
23
+ "tsup": "^8.1.0",
24
+ "tsx": "^4.15.0",
25
+ "typescript": "^5.4.5"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsx src/index.ts",
30
+ "dev:serve": "tsx src/index.ts serve",
31
+ "typecheck": "tsc --noEmit"
32
+ }
33
+ }