doccupine 0.0.128 → 0.0.129

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 CHANGED
@@ -148,7 +148,7 @@ Place these JSON files in your project root (where you run `doccupine`). They ar
148
148
 
149
149
  | File | Purpose |
150
150
  | ----------------- | --------------------------------------------------------------------------------------------------------- |
151
- | `doccupine.json` | CLI config (watchDir, outputDir, port). Auto-generated on first run. |
151
+ | `doccupine.json` | CLI config (watchDir, outputDir, port). Auto-generated on first run. Paths are stored relative to the project root, so the file is safe to commit. |
152
152
  | `config.json` | Site metadata: `name`, `description`, `icon`, `image`, `url` (public site URL for sitemap/robots) |
153
153
  | `theme.json` | Theme overrides for [cherry-styled-components](https://github.com/cherry-design-system/styled-components) |
154
154
  | `navigation.json` | Manual navigation structure (overrides auto-generated) |
package/dist/index.d.ts CHANGED
@@ -1,2 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  export { generateSlug, getFullSlug, escapeTemplateContent, } from "./lib/utils.js";
3
+ /**
4
+ * True when this file is what node was asked to run, rather than a module some
5
+ * other process imported. The test suite imports this file for its exported
6
+ * helpers; without this guard, that import parses argv, falls through to the
7
+ * default `watch` command, and prompts for config / starts file watchers.
8
+ *
9
+ * Compares realpaths because npm installs the bin as a symlink
10
+ * (`node_modules/.bin/doccupine` -> `dist/index.js`), so `process.argv[1]` and
11
+ * `import.meta.url` can name the same file by different paths.
12
+ */
13
+ export declare function isProcessEntrypoint(entry?: string | undefined, self?: string): boolean;
package/dist/index.js CHANGED
@@ -1250,6 +1250,8 @@ program
1250
1250
  port: options.port,
1251
1251
  });
1252
1252
  const generator = new MDXToNextJSGenerator(config.watchDir, config.outputDir);
1253
+ // Config paths are project-relative; child processes get an absolute cwd.
1254
+ const outputDir = path.resolve(process.cwd(), config.outputDir);
1253
1255
  await generator.init();
1254
1256
  let devServer = null;
1255
1257
  console.log(chalk.blue("šŸ“¦ Installing dependencies..."));
@@ -1260,7 +1262,7 @@ program
1260
1262
  const packageManager = resolvePackageManager(options.packageManager ?? config.packageManager);
1261
1263
  console.log(chalk.blue(`šŸ“¦ Using ${packageManager.name}...`));
1262
1264
  const install = spawn(packageManager.bin, ["install"], {
1263
- cwd: config.outputDir,
1265
+ cwd: outputDir,
1264
1266
  stdio: "inherit",
1265
1267
  });
1266
1268
  await new Promise((resolve, reject) => {
@@ -1285,7 +1287,7 @@ program
1285
1287
  ? ["run", "dev", "--", "--port", portStr]
1286
1288
  : ["run", "dev", "--port", portStr];
1287
1289
  devServer = spawn(packageManager.bin, devArgs, {
1288
- cwd: config.outputDir,
1290
+ cwd: outputDir,
1289
1291
  stdio: ["ignore", "pipe", "pipe"],
1290
1292
  });
1291
1293
  devServer.stdout?.on("data", (data) => {
@@ -1370,4 +1372,29 @@ program
1370
1372
  console.log(chalk.blue("Use --show to display configuration or --reset to reset it"));
1371
1373
  }
1372
1374
  });
1373
- program.parse();
1375
+ /**
1376
+ * True when this file is what node was asked to run, rather than a module some
1377
+ * other process imported. The test suite imports this file for its exported
1378
+ * helpers; without this guard, that import parses argv, falls through to the
1379
+ * default `watch` command, and prompts for config / starts file watchers.
1380
+ *
1381
+ * Compares realpaths because npm installs the bin as a symlink
1382
+ * (`node_modules/.bin/doccupine` -> `dist/index.js`), so `process.argv[1]` and
1383
+ * `import.meta.url` can name the same file by different paths.
1384
+ */
1385
+ export function isProcessEntrypoint(entry = process.argv[1], self = __filename) {
1386
+ if (!entry)
1387
+ return false;
1388
+ // Windows paths are case-insensitive; a false negative here would make the
1389
+ // CLI exit silently without running any command.
1390
+ const normalize = (filePath) => process.platform === "win32" ? filePath.toLowerCase() : filePath;
1391
+ try {
1392
+ return (normalize(fs.realpathSync(entry)) === normalize(fs.realpathSync(self)));
1393
+ }
1394
+ catch {
1395
+ return false;
1396
+ }
1397
+ }
1398
+ if (isProcessEntrypoint()) {
1399
+ program.parse();
1400
+ }
@@ -1,4 +1,22 @@
1
1
  import type { DoccupineConfig } from "./types.js";
2
+ /**
3
+ * Rewrites a path as project-relative so `doccupine.json` stays portable
4
+ * across machines, CI and containers (an absolute `/Users/you/...` breaks for
5
+ * every other contributor and leaks the local directory layout).
6
+ *
7
+ * Paths outside the project root have no portable form, so they are kept
8
+ * absolute - reads go through `path.resolve()`, which accepts both.
9
+ */
10
+ export declare function toProjectRelativePath(targetPath: string, rootDir?: string): string;
11
+ /**
12
+ * Migrates configs written by older versions, which stored absolute paths.
13
+ * Returns the normalized config plus whether anything actually changed, so
14
+ * callers only rewrite the file when needed.
15
+ */
16
+ export declare function normalizeConfigPaths(config: DoccupineConfig, rootDir?: string): {
17
+ config: DoccupineConfig;
18
+ changed: boolean;
19
+ };
2
20
  export declare class ConfigManager {
3
21
  private configPath;
4
22
  constructor(configPath?: string);
@@ -2,6 +2,46 @@ import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import chalk from "chalk";
4
4
  import prompts from "prompts";
5
+ /**
6
+ * Rewrites a path as project-relative so `doccupine.json` stays portable
7
+ * across machines, CI and containers (an absolute `/Users/you/...` breaks for
8
+ * every other contributor and leaks the local directory layout).
9
+ *
10
+ * Paths outside the project root have no portable form, so they are kept
11
+ * absolute - reads go through `path.resolve()`, which accepts both.
12
+ */
13
+ export function toProjectRelativePath(targetPath, rootDir = process.cwd()) {
14
+ // A hand-edited config can hold anything; leave junk untouched rather than
15
+ // throwing inside path.*.
16
+ if (typeof targetPath !== "string" || !targetPath)
17
+ return targetPath;
18
+ if (!path.isAbsolute(targetPath))
19
+ return targetPath;
20
+ const relativePath = path.relative(rootDir, targetPath);
21
+ // Empty means the path *is* the root; ".." or an absolute result (Windows
22
+ // cross-drive) means it escapes the root - neither is portable.
23
+ if (!relativePath)
24
+ return ".";
25
+ if (relativePath === ".." || relativePath.startsWith(`..${path.sep}`)) {
26
+ return targetPath;
27
+ }
28
+ if (path.isAbsolute(relativePath))
29
+ return targetPath;
30
+ // Always store POSIX separators so a config written on Windows still
31
+ // resolves on macOS/Linux.
32
+ return relativePath.split(path.sep).join("/");
33
+ }
34
+ /**
35
+ * Migrates configs written by older versions, which stored absolute paths.
36
+ * Returns the normalized config plus whether anything actually changed, so
37
+ * callers only rewrite the file when needed.
38
+ */
39
+ export function normalizeConfigPaths(config, rootDir = process.cwd()) {
40
+ const watchDir = toProjectRelativePath(config.watchDir, rootDir);
41
+ const outputDir = toProjectRelativePath(config.outputDir, rootDir);
42
+ const changed = watchDir !== config.watchDir || outputDir !== config.outputDir;
43
+ return { config: { ...config, watchDir, outputDir }, changed };
44
+ }
5
45
  export class ConfigManager {
6
46
  configPath;
7
47
  constructor(configPath = "doccupine.json") {
@@ -23,7 +63,7 @@ export class ConfigManager {
23
63
  }
24
64
  async saveConfig(config) {
25
65
  try {
26
- await fs.writeFile(this.configPath, JSON.stringify(config, null, 2), "utf8");
66
+ await fs.writeFile(this.configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
27
67
  console.log(chalk.green("šŸ’¾ Configuration saved to doccupine.json"));
28
68
  }
29
69
  catch (error) {
@@ -50,24 +90,40 @@ export class ConfigManager {
50
90
  console.log(chalk.yellow("\nāš ļø Setup cancelled."));
51
91
  process.exit(0);
52
92
  }
93
+ // Resolve first so "./docs" and "docs/" collapse to the same value, then
94
+ // store project-relative for portability.
53
95
  return {
54
- watchDir: path.resolve(process.cwd(), watchDir),
55
- outputDir: path.resolve(process.cwd(), outputDir),
96
+ watchDir: toProjectRelativePath(path.resolve(process.cwd(), watchDir)),
97
+ outputDir: toProjectRelativePath(path.resolve(process.cwd(), outputDir)),
56
98
  port: existingConfig?.port || "3000",
57
99
  };
58
100
  }
59
101
  async getConfig(options = {}) {
60
102
  let config = null;
103
+ let dirty = false;
61
104
  if (!options.reset) {
62
105
  config = await this.loadConfig();
63
106
  }
64
107
  if (!config || options.reset) {
65
108
  console.log(chalk.blue("šŸ”§ Setting up Doccupine configuration..."));
66
109
  config = await this.promptForConfig(config || {});
67
- await this.saveConfig(config);
110
+ dirty = true;
111
+ }
112
+ else {
113
+ // Configs written before 0.0.129 stored absolute paths; rewrite them in
114
+ // place so the file can be committed and shared.
115
+ const normalized = normalizeConfigPaths(config);
116
+ if (normalized.changed) {
117
+ config = normalized.config;
118
+ dirty = true;
119
+ console.log(chalk.blue("šŸ” Rewriting doccupine.json paths as project-relative"));
120
+ }
68
121
  }
69
122
  if (options.port) {
70
123
  config.port = options.port;
124
+ dirty = true;
125
+ }
126
+ if (dirty) {
71
127
  await this.saveConfig(config);
72
128
  }
73
129
  return config;
@@ -24,8 +24,8 @@ export const packageJsonTemplate = JSON.stringify({
24
24
  minisearch: "^7.2.0",
25
25
  next: "16.2.10",
26
26
  "next-mdx-remote": "^6.0.0",
27
- "posthog-js": "^1.404.1",
28
- "posthog-node": "^5.45.2",
27
+ "posthog-js": "^1.405.3",
28
+ "posthog-node": "^5.46.0",
29
29
  react: "19.2.7",
30
30
  "react-dom": "19.2.7",
31
31
  "rehype-highlight": "^7.0.2",
@@ -51,7 +51,7 @@ export const packageJsonTemplate = JSON.stringify({
51
51
  "eslint-plugin-react": "^7.37.5",
52
52
  "eslint-plugin-react-hooks": "^7.1.1",
53
53
  globals: "^17.7.0",
54
- prettier: "^3.9.5",
54
+ prettier: "^3.9.6",
55
55
  tsx: "^4.23.1",
56
56
  typescript: "npm:@typescript/typescript6@^6.0.2",
57
57
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doccupine",
3
- "version": "0.0.128",
3
+ "version": "0.0.129",
4
4
  "description": "Free and open-source documentation platform. Write MDX, get a production-ready site with AI chat, built-in components, and an MCP server - in one command.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -48,7 +48,7 @@
48
48
  "@types/fs-extra": "^11.0.4",
49
49
  "@types/node": "^26.1.1",
50
50
  "@types/prompts": "^2.4.9",
51
- "prettier": "^3.9.5",
51
+ "prettier": "^3.9.6",
52
52
  "typescript": "^7.0.2",
53
53
  "vitest": "^4.1.10"
54
54
  },