doccupine 0.0.139 ā 0.0.141
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 +14 -7
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +191 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +5 -1895
- package/dist/lib/config-manager.d.ts +1 -0
- package/dist/lib/config-manager.js +63 -3
- package/dist/lib/generated-artifacts.d.ts +26 -0
- package/dist/lib/generated-artifacts.js +147 -0
- package/dist/lib/layout.js +30 -30
- package/dist/lib/metadata.js +58 -30
- package/dist/lib/openapi-types.d.ts +2 -2
- package/dist/lib/openapi.d.ts +6 -3
- package/dist/lib/openapi.js +330 -50
- package/dist/lib/output-safety.d.ts +15 -0
- package/dist/lib/output-safety.js +428 -0
- package/dist/lib/structures.js +11 -0
- package/dist/lib/utils.d.ts +18 -0
- package/dist/lib/utils.js +125 -0
- package/dist/mdx-to-nextjs-generator.d.ts +166 -0
- package/dist/mdx-to-nextjs-generator.js +2229 -0
- package/dist/templates/app/api/gate/route.d.ts +1 -1
- package/dist/templates/app/api/gate/route.js +18 -6
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +181 -111
- package/dist/templates/app/api/playground/route.d.ts +1 -1
- package/dist/templates/app/api/playground/route.js +45 -13
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +102 -25
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +5 -0
- package/dist/templates/app/robots.d.ts +1 -1
- package/dist/templates/app/robots.js +1 -26
- package/dist/templates/app/theme.d.ts +1 -1
- package/dist/templates/app/theme.js +31 -19
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +411 -104
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +56 -13
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +63 -11
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +191 -49
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +8 -2
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +26 -3
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -1
- package/dist/templates/components/layout/ApiPlayground.js +4 -7
- package/dist/templates/components/layout/Badge.d.ts +1 -1
- package/dist/templates/components/layout/Badge.js +1 -1
- package/dist/templates/components/layout/Button.d.ts +1 -1
- package/dist/templates/components/layout/Button.js +4 -4
- package/dist/templates/components/layout/Callout.d.ts +1 -1
- package/dist/templates/components/layout/Callout.js +6 -6
- package/dist/templates/components/layout/Card.d.ts +1 -1
- package/dist/templates/components/layout/Card.js +9 -4
- package/dist/templates/components/layout/CherryThemeProvider.d.ts +1 -1
- package/dist/templates/components/layout/CherryThemeProvider.js +63 -12
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +5 -5
- package/dist/templates/components/layout/CopyButton.d.ts +1 -1
- package/dist/templates/components/layout/CopyButton.js +1 -1
- package/dist/templates/components/layout/DemoTheme.d.ts +1 -1
- package/dist/templates/components/layout/DemoTheme.js +8 -28
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +57 -18
- package/dist/templates/components/layout/GlobalStyles.d.ts +1 -1
- package/dist/templates/components/layout/GlobalStyles.js +15 -9
- package/dist/templates/components/layout/Prompt.d.ts +1 -1
- package/dist/templates/components/layout/Prompt.js +4 -7
- package/dist/templates/components/layout/Steps.d.ts +1 -1
- package/dist/templates/components/layout/Steps.js +7 -1
- package/dist/templates/components/layout/Tabs.d.ts +1 -1
- package/dist/templates/components/layout/Tabs.js +108 -19
- package/dist/templates/env.example.d.ts +1 -1
- package/dist/templates/env.example.js +11 -0
- package/dist/templates/eslint.config.d.ts +1 -1
- package/dist/templates/eslint.config.js +20 -0
- package/dist/templates/gitignore.d.ts +1 -1
- package/dist/templates/gitignore.js +4 -3
- package/dist/templates/lib/access.d.ts +1 -0
- package/dist/templates/lib/access.js +41 -0
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +17 -1
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +5 -3
- package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
- package/dist/templates/mdx/authentication.mdx.js +5 -3
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +20 -6
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +3 -0
- package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
- package/dist/templates/mdx/deployment-and-hosting.mdx.js +2 -2
- package/dist/templates/mdx/globals.mdx.d.ts +1 -1
- package/dist/templates/mdx/globals.mdx.js +14 -11
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +22 -35
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +23 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +7 -0
- package/dist/templates/mdx/platform/authentication.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/authentication.mdx.js +63 -0
- package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
- package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/import-from-github.mdx.js +2 -2
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +12 -1
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +43 -10
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +48 -9
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +4 -0
- package/dist/templates/mdx/space.mdx.d.ts +1 -0
- package/dist/templates/mdx/space.mdx.js +125 -0
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +4 -0
- package/dist/templates/next.config.js +20 -8
- package/dist/templates/package.js +3 -3
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +1 -0
- package/dist/templates/proxy.js +47 -19
- package/dist/templates/scripts/build-docs-index.d.ts +1 -1
- package/dist/templates/scripts/build-docs-index.js +1 -0
- package/dist/templates/services/mcp/docsContentStub.d.ts +1 -0
- package/dist/templates/services/mcp/docsContentStub.js +1 -0
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +140 -83
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +65 -137
- package/dist/templates/utils/playgroundAllowlist.d.ts +1 -1
- package/dist/templates/utils/playgroundAllowlist.js +13 -4
- package/dist/templates/utils/rateLimit.d.ts +1 -1
- package/dist/templates/utils/rateLimit.js +40 -3
- package/dist/templates/utils/requestBody.d.ts +1 -0
- package/dist/templates/utils/requestBody.js +56 -0
- package/dist/templates/utils/ssrfGuard.d.ts +1 -1
- package/dist/templates/utils/ssrfGuard.js +138 -33
- package/package.json +14 -9
- package/dist/lib/mdxToMarkdown.d.ts +0 -1
- package/dist/lib/mdxToMarkdown.js +0 -134
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +0 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +0 -118
package/README.md
CHANGED
|
@@ -35,11 +35,14 @@ Doccupine will prompt you for:
|
|
|
35
35
|
|
|
36
36
|
It then scaffolds the app, installs dependencies, and starts the dev server. Open http://localhost:3000 to view your docs.
|
|
37
37
|
|
|
38
|
+
The source and output directories must not overlap. To prevent accidental data loss, Doccupine only claims an empty output directory, one containing harmless local metadata such as `.DS_Store` or `.env.local`, or an existing Doccupine-generated app. Run `doccupine config --reset` if an older configuration no longer passes validation.
|
|
39
|
+
|
|
38
40
|
## CLI Commands
|
|
39
41
|
|
|
40
42
|
```bash
|
|
41
43
|
doccupine watch [options] # Default. Watch MDX files and start dev server
|
|
42
|
-
doccupine build [options] #
|
|
44
|
+
doccupine build [options] # Generate the site without installing or serving it
|
|
45
|
+
doccupine generate [options] # Alias for build
|
|
43
46
|
doccupine config --show # Show current configuration
|
|
44
47
|
doccupine config --reset # Re-prompt for configuration
|
|
45
48
|
```
|
|
@@ -53,6 +56,7 @@ doccupine config --reset # Re-prompt for configuration
|
|
|
53
56
|
| `--port <port>` | Port for the dev server (default: `3000`). Auto-increments if taken. |
|
|
54
57
|
| `--verbose` | Show all Next.js output including compilation details |
|
|
55
58
|
| `--reset` | Re-prompt for watch/output directories |
|
|
59
|
+
| `--skip-install` | Generate and serve without running the dependency installer (installs are skipped automatically when `package.json` is unchanged) |
|
|
56
60
|
| `--package-manager <name>` | Package manager for the generated app: `pnpm` or `npm` (default: auto-detect). Overrides the `packageManager` field in `doccupine.json`. |
|
|
57
61
|
|
|
58
62
|
`build`:
|
|
@@ -149,7 +153,7 @@ Each entry has:
|
|
|
149
153
|
|
|
150
154
|
## API Reference
|
|
151
155
|
|
|
152
|
-
Point Doccupine at an OpenAPI document (`.json`, `.yaml`, or `.yml`, OpenAPI 3.0/3.1) and it generates an interactive API reference: one page per operation
|
|
156
|
+
Point Doccupine at an OpenAPI document (`.json`, `.yaml`, or `.yml`, OpenAPI 3.0/3.1) and it generates an interactive API reference: a directory at `/api-reference` linking every operation, plus one page per operation with a live playground for sending requests. Set the `openapi` field in `doccupine.json`:
|
|
153
157
|
|
|
154
158
|
```json
|
|
155
159
|
{
|
|
@@ -209,7 +213,7 @@ Doccupine generates `robots.ts` automatically for every site. When you set a `ur
|
|
|
209
213
|
}
|
|
210
214
|
```
|
|
211
215
|
|
|
212
|
-
You can override the URL at deploy time by setting the `NEXT_PUBLIC_SITE_URL` environment variable. When no URL is configured
|
|
216
|
+
You can override the URL at deploy time by setting the `NEXT_PUBLIC_SITE_URL` environment variable. When no URL is configured, `/sitemap.xml` is still served but stays empty, and `robots.txt` omits its sitemap reference until a public URL is available. The variable is baked in at build time, so changing it needs a redeploy.
|
|
213
217
|
|
|
214
218
|
## llms.txt
|
|
215
219
|
|
|
@@ -223,7 +227,7 @@ Doccupine generates [llms.txt](https://llmstxt.org) artifacts so AI agents can d
|
|
|
223
227
|
|
|
224
228
|
The site name and description used in `llms.txt` come from `config.json` (`name`, `description`). Page URLs are absolute when `url` is set in `config.json` (or via `NEXT_PUBLIC_SITE_URL`), and root-relative otherwise.
|
|
225
229
|
|
|
226
|
-
A `.doccupine-
|
|
230
|
+
A `.doccupine-artifacts.json` file in the generated app tracks generated route ownership and per-page mirrors so renamed or deleted sources clean up only their own outputs. Don't commit this file; it is regenerated automatically.
|
|
227
231
|
|
|
228
232
|
## AI Chat Setup
|
|
229
233
|
|
|
@@ -250,10 +254,13 @@ LLM_EMBEDDING_MODEL=text-embedding-3-small # Override the default embedding mod
|
|
|
250
254
|
LLM_TEMPERATURE=0 # Set temperature (0-1, default: 0)
|
|
251
255
|
LLM_EMBEDDING_DIMS=512 # Dimensions for the prebuilt search index (default: 512)
|
|
252
256
|
RAG_RUNTIME_EMBED_MAX_CHUNKS=400 # Max chunks embedded on demand in production (default: 400; 0 requires a prebuilt index)
|
|
257
|
+
# RAG_API_KEY=... # Optional bearer auth for direct /api/rag requests
|
|
253
258
|
```
|
|
254
259
|
|
|
255
260
|
`LLM_EMBEDDING_DIMS` Matryoshka-truncates document vectors so the prebuilt search index stays small; lower values shrink the index at a slight cost to recall. `RAG_RUNTIME_EMBED_MAX_CHUNKS` caps how many chunks the chat will embed on demand in production before requiring a prebuilt index (it's unlimited under `next dev`).
|
|
256
261
|
|
|
262
|
+
Public documentation leaves browser chat available by default. Setting `RAG_API_KEY` requires a bearer token for `/api/rag` and is intended for server-to-server use; the built-in browser cannot safely hold that secret. Use `SITE_PASSWORD` instead when authenticated browser visitors should retain chat access.
|
|
263
|
+
|
|
257
264
|
Default models per provider:
|
|
258
265
|
|
|
259
266
|
| Provider | Chat model | Embedding model |
|
|
@@ -270,7 +277,7 @@ The generated app exposes an MCP endpoint at `/api/mcp` with three tools:
|
|
|
270
277
|
- `get_doc` - retrieve a specific document by path
|
|
271
278
|
- `list_docs` - list all available documents
|
|
272
279
|
|
|
273
|
-
This lets AI agents (Claude, ChatGPT, etc.) query your docs programmatically.
|
|
280
|
+
This lets AI agents (Claude, ChatGPT, etc.) query your docs programmatically. Semantic `search_docs` requires the AI setup above for embeddings; `get_doc` and `list_docs` work from the generated content manifest without an embedding provider.
|
|
274
281
|
|
|
275
282
|
## Password Protection
|
|
276
283
|
|
|
@@ -283,12 +290,12 @@ SITE_PASSWORD=choose-a-strong-shared-password
|
|
|
283
290
|
When set, every visitor sees a login screen until they enter the password. Protection is enforced across three layers:
|
|
284
291
|
|
|
285
292
|
- **Pages** are gated behind the login screen.
|
|
286
|
-
- **Content APIs** (`/api/rag` chat and `/api/
|
|
293
|
+
- **Content APIs** (`/api/rag` chat, `/api/search`, and the `/api/playground` proxy) return `401` without a valid session, so the docs can't be scraped and the proxy can't relay anonymous requests around the login. Each route re-checks the session itself, not just the middleware.
|
|
287
294
|
- **Search engines and crawlers** are blocked: `robots.txt` disallows everything, pages carry a `noindex, nofollow` tag, and responses include an `X-Robots-Tag` header.
|
|
288
295
|
|
|
289
296
|
A successful login sets a signed, `httpOnly` cookie that lasts 30 days. The cookie stores an HMAC of the password, never the password itself. Leave `SITE_PASSWORD` unset (the default) to keep the site fully public. Documentation pages stay statically rendered either way - the gate is enforced in middleware.
|
|
290
297
|
|
|
291
|
-
> **Note:** The [MCP endpoint](#mcp-server) uses
|
|
298
|
+
> **Note:** The [MCP endpoint](#mcp-server) uses `DOCS_API_KEY` bearer authentication when configured. Without an API key, a password-protected site requires the normal gate session for MCP as well.
|
|
292
299
|
|
|
293
300
|
## License
|
|
294
301
|
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCli(argv?: string[]): Promise<void>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
import { ConfigManager, normalizeOpenApiConfig } from "./lib/config-manager.js";
|
|
9
|
+
import { findAvailablePort, resolvePackageManager, writeFileAtomic, } from "./lib/utils.js";
|
|
10
|
+
import { MDXToNextJSGenerator } from "./mdx-to-nextjs-generator.js";
|
|
11
|
+
async function dependencyFingerprint(outputDir, packageManager) {
|
|
12
|
+
const packageJson = await fs.readFile(path.join(outputDir, "package.json"), "utf8");
|
|
13
|
+
return createHash("sha256")
|
|
14
|
+
.update(packageManager)
|
|
15
|
+
.update("\0")
|
|
16
|
+
.update(packageJson)
|
|
17
|
+
.digest("hex");
|
|
18
|
+
}
|
|
19
|
+
async function needsDependencyInstall(outputDir, packageManager) {
|
|
20
|
+
if (!(await fs.pathExists(path.join(outputDir, "node_modules"))))
|
|
21
|
+
return true;
|
|
22
|
+
const stampPath = path.join(outputDir, ".doccupine-install");
|
|
23
|
+
try {
|
|
24
|
+
const expected = await dependencyFingerprint(outputDir, packageManager);
|
|
25
|
+
return (await fs.readFile(stampPath, "utf8")).trim() !== expected;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function recordDependencyInstall(outputDir, packageManager) {
|
|
32
|
+
const fingerprint = await dependencyFingerprint(outputDir, packageManager);
|
|
33
|
+
await writeFileAtomic(path.join(outputDir, ".doccupine-install"), `${fingerprint}\n`);
|
|
34
|
+
}
|
|
35
|
+
export async function runCli(argv) {
|
|
36
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
const packageJson = JSON.parse(await fs.readFile(path.join(__dirname, "..", "package.json"), "utf8"));
|
|
38
|
+
const program = new Command();
|
|
39
|
+
program
|
|
40
|
+
.name("doccupine")
|
|
41
|
+
.description("Watch MDX files and generate Next.js documentation pages automatically")
|
|
42
|
+
.version(packageJson.version);
|
|
43
|
+
program
|
|
44
|
+
.command("watch", { isDefault: true })
|
|
45
|
+
.description("Watch a directory for MDX changes and generate Next.js app")
|
|
46
|
+
.option("--port <port>", "Port for Next.js dev server")
|
|
47
|
+
.option("--verbose", "Show verbose output")
|
|
48
|
+
.option("--reset", "Reset configuration and prompt for new directories")
|
|
49
|
+
.option("--skip-install", "Skip dependency installation")
|
|
50
|
+
.option("--package-manager <name>", "Package manager for the generated app: pnpm or npm (default: auto-detect)")
|
|
51
|
+
.action(async (options) => {
|
|
52
|
+
const configManager = new ConfigManager();
|
|
53
|
+
const config = await configManager.getConfig({
|
|
54
|
+
reset: options.reset,
|
|
55
|
+
port: options.port,
|
|
56
|
+
});
|
|
57
|
+
const generator = new MDXToNextJSGenerator(config.watchDir, config.outputDir, normalizeOpenApiConfig(config.openapi));
|
|
58
|
+
// Config paths are project-relative; child processes get an absolute cwd.
|
|
59
|
+
const outputDir = path.resolve(process.cwd(), config.outputDir);
|
|
60
|
+
await generator.init();
|
|
61
|
+
let devServer = null;
|
|
62
|
+
// Prefer pnpm (the generated app ships a pnpm workspace) and fall back to
|
|
63
|
+
// npm. A --package-manager flag or a "packageManager" field in
|
|
64
|
+
// doccupine.json overrides detection; the flag wins.
|
|
65
|
+
const packageManager = resolvePackageManager(options.packageManager ?? config.packageManager);
|
|
66
|
+
console.log(chalk.blue(`š¦ Using ${packageManager.name}...`));
|
|
67
|
+
if (options.skipInstall) {
|
|
68
|
+
console.log(chalk.yellow("āļø Skipping dependency installation"));
|
|
69
|
+
}
|
|
70
|
+
else if (await needsDependencyInstall(outputDir, packageManager.name)) {
|
|
71
|
+
console.log(chalk.blue("š¦ Installing dependencies..."));
|
|
72
|
+
const install = spawn(packageManager.bin, ["install"], {
|
|
73
|
+
cwd: outputDir,
|
|
74
|
+
stdio: "inherit",
|
|
75
|
+
});
|
|
76
|
+
await new Promise((resolve, reject) => {
|
|
77
|
+
install.on("close", (code) => {
|
|
78
|
+
if (code === 0) {
|
|
79
|
+
resolve(void 0);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
reject(new Error(`${packageManager.name} install failed with code ${code}`));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
install.on("error", reject);
|
|
86
|
+
});
|
|
87
|
+
await recordDependencyInstall(outputDir, packageManager.name);
|
|
88
|
+
console.log(chalk.green("ā
Dependencies installed"));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(chalk.green("ā
Dependencies are already up to date"));
|
|
92
|
+
}
|
|
93
|
+
const requestedPort = Number(config.port);
|
|
94
|
+
const port = await findAvailablePort(requestedPort);
|
|
95
|
+
if (port !== requestedPort) {
|
|
96
|
+
console.log(chalk.yellow(`ā ļø Port ${config.port} is in use, using port ${port} instead`));
|
|
97
|
+
}
|
|
98
|
+
console.log(chalk.blue(`š Starting Next.js dev server on port ${port}...`));
|
|
99
|
+
const portStr = String(port);
|
|
100
|
+
const devArgs = packageManager.name === "npm"
|
|
101
|
+
? ["run", "dev", "--", "--port", portStr]
|
|
102
|
+
: ["run", "dev", "--port", portStr];
|
|
103
|
+
devServer = spawn(packageManager.bin, devArgs, {
|
|
104
|
+
cwd: outputDir,
|
|
105
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
106
|
+
});
|
|
107
|
+
devServer.stdout?.on("data", (data) => {
|
|
108
|
+
const output = data.toString();
|
|
109
|
+
if (output.includes("Ready") || output.includes("started")) {
|
|
110
|
+
console.log(chalk.green(`š Next.js ready at http://localhost:${port}`));
|
|
111
|
+
}
|
|
112
|
+
if (options.verbose) {
|
|
113
|
+
process.stdout.write(chalk.gray("[Next.js] ") + output);
|
|
114
|
+
}
|
|
115
|
+
else if (output.includes("compiled") ||
|
|
116
|
+
output.includes("error") ||
|
|
117
|
+
output.includes("Ready")) {
|
|
118
|
+
process.stdout.write(chalk.gray("[Next.js] ") + output);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
devServer.stderr?.on("data", (data) => {
|
|
122
|
+
const output = data.toString();
|
|
123
|
+
if (options.verbose ||
|
|
124
|
+
output.includes("Error") ||
|
|
125
|
+
output.includes("error")) {
|
|
126
|
+
process.stderr.write(chalk.red("[Next.js] ") + output);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
devServer.on("error", (error) => {
|
|
130
|
+
console.error(chalk.red("ā Error starting dev server:"), error);
|
|
131
|
+
});
|
|
132
|
+
devServer.on("close", (code) => {
|
|
133
|
+
if (code && code !== 0) {
|
|
134
|
+
console.error(chalk.red(`ā Next.js dev server exited with code ${code}`));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
await generator.startWatching();
|
|
138
|
+
process.on("SIGINT", async () => {
|
|
139
|
+
console.log(chalk.yellow("\nš Shutting down..."));
|
|
140
|
+
await generator.stop();
|
|
141
|
+
if (devServer) {
|
|
142
|
+
devServer.kill();
|
|
143
|
+
}
|
|
144
|
+
process.exit(0);
|
|
145
|
+
});
|
|
146
|
+
console.log(chalk.green("š Generator is running! Press Ctrl+C to stop."));
|
|
147
|
+
console.log(chalk.cyan(`š Edit your MDX files in: ${config.watchDir}`));
|
|
148
|
+
});
|
|
149
|
+
program
|
|
150
|
+
.command("build")
|
|
151
|
+
.alias("generate")
|
|
152
|
+
.description("Generate the Next.js app once without running its build")
|
|
153
|
+
.option("--reset", "Reset configuration and prompt for new directories")
|
|
154
|
+
.action(async (options) => {
|
|
155
|
+
const configManager = new ConfigManager();
|
|
156
|
+
const config = await configManager.getConfig({
|
|
157
|
+
reset: options.reset,
|
|
158
|
+
});
|
|
159
|
+
const generator = new MDXToNextJSGenerator(config.watchDir, config.outputDir, normalizeOpenApiConfig(config.openapi));
|
|
160
|
+
await generator.init();
|
|
161
|
+
console.log(chalk.green("š Generation complete!"));
|
|
162
|
+
});
|
|
163
|
+
program
|
|
164
|
+
.command("config")
|
|
165
|
+
.description("Show or reset configuration")
|
|
166
|
+
.option("--show", "Show current configuration")
|
|
167
|
+
.option("--reset", "Reset configuration")
|
|
168
|
+
.action(async (options) => {
|
|
169
|
+
const configManager = new ConfigManager();
|
|
170
|
+
if (options.show) {
|
|
171
|
+
const config = await configManager.loadConfig();
|
|
172
|
+
if (config) {
|
|
173
|
+
console.log(chalk.blue("š Current configuration:"));
|
|
174
|
+
console.log(chalk.white("Watch Directory:"), chalk.cyan(path.relative(process.cwd(), config.watchDir)));
|
|
175
|
+
console.log(chalk.white("Output Directory:"), chalk.cyan(path.relative(process.cwd(), config.outputDir)));
|
|
176
|
+
console.log(chalk.white("Port:"), chalk.cyan(config.port || "3000"));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
console.log(chalk.yellow("ā ļø No configuration file found"));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if (options.reset) {
|
|
183
|
+
await configManager.getConfig({ reset: true });
|
|
184
|
+
console.log(chalk.green("ā
Configuration reset"));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
console.log(chalk.blue("Use --show to display configuration or --reset to reset it"));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
await program.parseAsync(argv ?? process.argv);
|
|
191
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
export { generateSlug, getFullSlug, escapeTemplateContent, toJsStringLiteral, } from "./lib/utils.js";
|
|
3
|
+
export { MDXToNextJSGenerator } from "./mdx-to-nextjs-generator.js";
|
|
3
4
|
/**
|
|
4
5
|
* True when this file is what node was asked to run, rather than a module some
|
|
5
|
-
* other process imported.
|
|
6
|
-
*
|
|
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.
|
|
6
|
+
* other process imported. Compares realpaths because npm installs the bin as a
|
|
7
|
+
* symlink (`node_modules/.bin/doccupine` -> `dist/index.js`).
|
|
12
8
|
*/
|
|
13
9
|
export declare function isProcessEntrypoint(entry?: string | undefined, self?: string): boolean;
|