@mdocs/cli 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.
Files changed (2) hide show
  1. package/dist/index.js +10 -21
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -5,12 +5,13 @@ import { Command } from "commander";
5
5
 
6
6
  // src/commands/serve.ts
7
7
  import chalk2 from "chalk";
8
- import inquirer from "inquirer";
8
+ import open from "open";
9
9
  import { startServer, DEFAULT_ORIGINS } from "@mdocs/server";
10
10
 
11
11
  // src/lib/mdocs.ts
12
12
  import { existsSync, mkdirSync } from "fs";
13
- import { join } from "path";
13
+ import { join, isAbsolute } from "path";
14
+ import { homedir } from "os";
14
15
  var MDOCS_DIR = ".mdocs";
15
16
  var REPOS_DIR = join(MDOCS_DIR, "repos");
16
17
  function mdocsExists(cwd) {
@@ -23,8 +24,8 @@ function createMdocsStructure(cwd) {
23
24
  mkdirSync(join(cwd, REPOS_DIR), { recursive: true });
24
25
  }
25
26
  function resolveDataDir(dataDir) {
26
- if (!dataDir) return process.cwd();
27
- return dataDir.startsWith(".") ? join(process.cwd(), dataDir) : dataDir;
27
+ if (!dataDir) return homedir();
28
+ return isAbsolute(dataDir) ? dataDir : join(process.cwd(), dataDir);
28
29
  }
29
30
 
30
31
  // src/commands/setup.ts
@@ -49,33 +50,19 @@ function printBanner() {
49
50
  }
50
51
 
51
52
  // src/commands/serve.ts
53
+ var VIEWER_URL = "https://idocs-md-viewer.vercel.app/";
52
54
  async function serve(options) {
53
55
  const cwd = resolveDataDir(options.dataDir);
54
56
  const port = parseInt(options.port, 10);
55
57
  const host = options.host;
56
58
  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
59
  await runSetup(cwd);
73
60
  }
74
61
  console.log(chalk2.dim(`
75
62
  Starting server on ${host}:${port}...
76
63
  `));
77
64
  const origins = options.origin ? [options.origin, ...DEFAULT_ORIGINS] : DEFAULT_ORIGINS;
78
- const server = await startServer({ port, host, dataDir: cwd, origins });
65
+ const server = await startServer({ port, host, dataDir: cwd, origins, githubToken: options.githubToken });
79
66
  printBanner();
80
67
  console.log(
81
68
  chalk2.bold(" Server running at ") + chalk2.bold.underline.cyan(`http://${host}:${port}`)
@@ -84,7 +71,9 @@ async function serve(options) {
84
71
  if (options.origin) {
85
72
  console.log(chalk2.dim(` CORS origin: ${options.origin}`));
86
73
  }
74
+ console.log(chalk2.dim(` Opening ${VIEWER_URL}`));
87
75
  console.log(chalk2.dim("\n Press Ctrl+C to stop.\n"));
76
+ void open(VIEWER_URL);
88
77
  process.on("SIGINT", () => {
89
78
  console.log(chalk2.dim("\n Stopping mDocs server\u2026\n"));
90
79
  server.close(() => process.exit(0));
@@ -94,6 +83,6 @@ async function serve(options) {
94
83
  // src/index.ts
95
84
  var program = new Command();
96
85
  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);
86
+ 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").option("-t, --github-token <token>", "GitHub PAT for cloning private repositories (or set GITHUB_TOKEN env var)").action(serve);
98
87
  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
88
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdocs/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "mDocs CLI — start the local documentation server",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,8 +14,8 @@
14
14
  "commander": "^12.1.0",
15
15
  "figlet": "^1.7.0",
16
16
  "gradient-string": "^2.0.2",
17
- "inquirer": "^9.2.23",
18
- "@mdocs/server": "0.1.0"
17
+ "open": "^11.0.0",
18
+ "@mdocs/server": "0.1.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/figlet": "^1.5.8",