@opendocsdev/cli 0.2.1 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendocsdev/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -50,6 +50,7 @@ function getSnippetFolders(): string[] {
50
50
  }
51
51
 
52
52
  const snippetFolders = getSnippetFolders();
53
+ const projectDir = import.meta.env.OPENDOCS_PROJECT_DIR || "";
53
54
 
54
55
  // Get all MDX files from user's content directory
55
56
  // This glob pattern is resolved at build time via the @content Vite alias
@@ -71,7 +72,7 @@ function isSnippetPath(path: string): boolean {
71
72
  * Uses default snippet folders from environment
72
73
  */
73
74
  function extractSlugFromPath(globPath: string): string | null {
74
- return extractSlugFromPathUtil(globPath, snippetFolders);
75
+ return extractSlugFromPathUtil(globPath, snippetFolders, projectDir);
75
76
  }
76
77
 
77
78
  /**
@@ -19,7 +19,8 @@ export function isSnippetPath(path: string, folders: string[]): boolean {
19
19
  */
20
20
  export function extractSlugFromPath(
21
21
  globPath: string,
22
- folders: string[]
22
+ folders: string[],
23
+ projectDir?: string
23
24
  ): string | null {
24
25
  // Remove @content/ prefix if present
25
26
  if (globPath.startsWith("@content/")) {
@@ -36,11 +37,25 @@ export function extractSlugFromPath(
36
37
  return null;
37
38
  }
38
39
 
39
- // Handle relative paths from Vite glob
40
+ // Use project directory name to find the content root in the path
41
+ // This handles both local dev (short relative paths) and npm global install (long relative paths)
42
+ if (projectDir) {
43
+ const projectDirName = projectDir.replace(/\/$/, "").split("/").pop();
44
+ if (projectDirName) {
45
+ const marker = `/${projectDirName}/`;
46
+ const idx = globPath.lastIndexOf(marker);
47
+ if (idx !== -1) {
48
+ const contentPath = globPath.substring(idx + marker.length);
49
+ if (isSnippetPath(contentPath, folders)) {
50
+ return null;
51
+ }
52
+ return contentPath.replace(/\.mdx?$/, "");
53
+ }
54
+ }
55
+ }
56
+
57
+ // Fallback: Handle relative paths from Vite glob
40
58
  // e.g., "../../../../test-docs/guides/using-snippets.mdx" -> "guides/using-snippets"
41
- // e.g., "../../../../test-docs/components.mdx" -> "components"
42
- // Find the project directory boundary (last ../ followed by project-dir/)
43
- // The pattern matches all the "../" parts, then project-dir/, then captures the slug
44
59
  const relativeMatch = globPath.match(/(?:\.\.\/)+[^/]+\/(.+)\.mdx?$/);
45
60
  if (relativeMatch) {
46
61
  return relativeMatch[1];
@@ -60,10 +75,10 @@ export function extractSlugFromPath(
60
75
  * Filter paths and return valid slugs (excludes snippet folders)
61
76
  * Used for testing purposes
62
77
  */
63
- export function filterPathsToSlugs(paths: string[], folders: string[]): string[] {
78
+ export function filterPathsToSlugs(paths: string[], folders: string[], projectDir?: string): string[] {
64
79
  const slugs: string[] = [];
65
80
  for (const path of paths) {
66
- const slug = extractSlugFromPath(path, folders);
81
+ const slug = extractSlugFromPath(path, folders, projectDir);
67
82
  if (slug !== null && !slugs.includes(slug)) {
68
83
  slugs.push(slug);
69
84
  }