@opendocsdev/cli 0.2.0 → 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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# opendocs
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@opendocsdev/cli)
|
|
4
4
|
[](https://github.com/chigala/opendocs/blob/main/LICENSE)
|
|
5
5
|
|
|
6
6
|
Beautiful docs with zero config. An open-source alternative to [Mintlify](https://mintlify.com).
|
|
@@ -10,13 +10,13 @@ Write documentation in MDX, get built-in search, syntax highlighting, theming, a
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npm install -g
|
|
13
|
+
npm install -g @opendocsdev/cli
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
Or use directly with npx:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npx
|
|
19
|
+
npx @opendocsdev/cli init my-docs
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Commands
|
|
@@ -191,15 +191,15 @@ Tabbed code blocks for showing the same example in multiple languages:
|
|
|
191
191
|
````mdx
|
|
192
192
|
<CodeGroup>
|
|
193
193
|
```bash npm
|
|
194
|
-
npm install
|
|
194
|
+
npm install @opendocsdev/cli
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
```bash pnpm
|
|
198
|
-
pnpm add
|
|
198
|
+
pnpm add @opendocsdev/cli
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
```bash yarn
|
|
202
|
-
yarn add
|
|
202
|
+
yarn add @opendocsdev/cli
|
|
203
203
|
```
|
|
204
204
|
</CodeGroup>
|
|
205
205
|
````
|
|
@@ -223,7 +223,7 @@ yarn add opendocs
|
|
|
223
223
|
<Steps>
|
|
224
224
|
### Install the CLI
|
|
225
225
|
|
|
226
|
-
Run `npm install -g
|
|
226
|
+
Run `npm install -g @opendocsdev/cli`.
|
|
227
227
|
|
|
228
228
|
### Create a project
|
|
229
229
|
|
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
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
|
}
|