Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/grumpy-files-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@open-rpc/markdown-generator": minor
"@open-rpc/docusaurus-plugin": minor
---

The initial release for open-rpc mardown gneerator and docusaurus-plugin
26 changes: 13 additions & 13 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default [
...globals.node,
...globals.es6,
...globals.browser,
Bun: 'readonly',
}
},
plugins: {
Expand Down
15 changes: 1 addition & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{
"name": "markdown-gen-beta",
"module": "index.ts",
"name": "@open-rpc/markdown-gen-root",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/browser/index.js",
"import": "./dist/index.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"private": true,
"workspaces": [
"packages/*"
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open-rpc-docusaurus-plugin-beta",
"version": "0.0.5",
"name": "@open-rpc/docusaurus-plugin",
"version": "0.0.4",
"private": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -22,7 +22,7 @@
"@docusaurus/utils": "3.9.2",
"@docusaurus/utils-common": "3.9.2",
"@docusaurus/utils-validation": "3.9.2",
"open-rpc-markdown-generator-beta": "workspace:*",
"@open-rpc/markdown-generator": "workspace:*",
"@open-rpc/meta-schema": "^1.14.9",
"@open-rpc/schema-utils-js": "^2.1.2"
},
Expand Down
10 changes: 5 additions & 5 deletions packages/docusaurus-plugin/src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { parseOpenRPCDocument } from "@open-rpc/schema-utils-js";
import type { Edits } from "open-rpc-markdown-generator-beta";
import type { Edits } from "@open-rpc/markdown-generator";
import {
identityEdits,
identitySchemaEdits,
renderMethodsToMarkdown,
renderIndex,
} from "open-rpc-markdown-generator-beta";
} from "@open-rpc/markdown-generator";
import type {
DereffedMethodObject,
DereffedMethodObjectParams,
DereffedOpenrpcDocument,
} from "open-rpc-markdown-generator-beta";
} from "@open-rpc/markdown-generator";
import { promises as fs } from "fs";
import * as path from "path";
import { OpenRPCMdContent } from "open-rpc-markdown-generator-beta";
import { OpenRPCMdContent } from "@open-rpc/markdown-generator";
import { MethodObjectParamStructure } from "@open-rpc/meta-schema";

type JSONSchema = any;

const reactComponent: string = `import {TwoColumnLayout, InteractiveRequest, ResponseExample} from 'open-rpc-docusaurus-plugin-beta/components';\nimport { useState } from 'react';`;
const reactComponent: string = `import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/docusaurus-plugin/components';\nimport { useState } from 'react';`;
const methodEdits: Edits = { ...identityEdits };

methodEdits.editMethod = (content, method) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/example-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"typecheck": "tsc"
},
"dependencies": {
"open-rpc-docusaurus-plugin-beta": "workspace:*",
"@open-rpc/docusaurus-plugin": "workspace:*",
"@docusaurus/core": "3.9.2",
"@docusaurus/preset-classic": "3.9.2",
"@mdx-js/react": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "open-rpc-markdown-generator-beta",
"name": "@open-rpc/markdown-generator",
"module": "index.ts",
"type": "module",
"exports": {
Expand Down
188 changes: 188 additions & 0 deletions packages/markdown-generator/src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
import { tmpdir } from "os";
import path from "path";
import fs from "fs/promises";

const CLI_PATH = path.join(import.meta.dir, "cli.ts");
const FIXTURE_PATH = path.join(
import.meta.dir,
"fixtures/comprehensive-test-openrpc.json",
);

describe("CLI", () => {
let tempDir: string;

beforeAll(async () => {
tempDir = await fs.mkdtemp(path.join(tmpdir(), "openrpc-md-test-"));
});

afterAll(async () => {
await fs.rm(tempDir, { recursive: true, force: true });
});

it("should show help with -h flag", async () => {
const proc = Bun.spawn(["bun", CLI_PATH, "-h"], {
stdout: "pipe",
stderr: "pipe",
});

const stdout = await new Response(proc.stdout).text();
await proc.exited;

expect(proc.exitCode).toBe(0);
expect(stdout).toContain("Usage: openrpc-md");
expect(stdout).toContain("--methodDir");
expect(stdout).toContain("--custom");
});

it("should show help with --help flag", async () => {
const proc = Bun.spawn(["bun", CLI_PATH, "--help"], {
stdout: "pipe",
stderr: "pipe",
});

const stdout = await new Response(proc.stdout).text();
await proc.exited;

expect(proc.exitCode).toBe(0);
expect(stdout).toContain("Usage: openrpc-md");
});

it("should error when no document path is provided", async () => {
const proc = Bun.spawn(["bun", CLI_PATH], {
stdout: "pipe",
stderr: "pipe",
});

const stderr = await new Response(proc.stderr).text();
await proc.exited;

expect(proc.exitCode).toBe(1);
expect(stderr).toContain("Error: OpenRPC document path is required");
});

it("should generate .mdx files by default", async () => {
const outputDir = path.join(tempDir, "mdx-output");
await fs.mkdir(outputDir, { recursive: true });

const proc = Bun.spawn(["bun", CLI_PATH, FIXTURE_PATH, "-m", outputDir], {
stdout: "pipe",
stderr: "pipe",
});

const stdout = await new Response(proc.stdout).text();
await proc.exited;

expect(proc.exitCode).toBe(0);
expect(stdout).toContain("Generated markdown files");

// Check that files were created
const files = await fs.readdir(outputDir);
expect(files).toContain("index.md");
expect(files).toContain("test_allOf_composition_param.mdx");
expect(files).toContain("test_if_then_else_keyword.mdx");
});

it("should generate .md files with -t md flag", async () => {
const outputDir = path.join(tempDir, "md-output");
await fs.mkdir(outputDir, { recursive: true });

const proc = Bun.spawn(
["bun", CLI_PATH, FIXTURE_PATH, "-m", outputDir, "-t", "md"],
{
stdout: "pipe",
stderr: "pipe",
},
);

await proc.exited;

expect(proc.exitCode).toBe(0);

// Check that .md files were created
const files = await fs.readdir(outputDir);
expect(files).toContain("index.md");
expect(files).toContain("test_allOf_composition_param.md");
expect(files).toContain("test_if_then_else_keyword.md");
// Should NOT have .mdx files
expect(files.some((f) => f.endsWith(".mdx"))).toBe(false);
});

it("should use --methodDir for output directory", async () => {
const outputDir = path.join(tempDir, "method-dir-output");
await fs.mkdir(outputDir, { recursive: true });

const proc = Bun.spawn(
["bun", CLI_PATH, FIXTURE_PATH, "--methodDir", outputDir],
{
stdout: "pipe",
stderr: "pipe",
},
);

const stdout = await new Response(proc.stdout).text();
await proc.exited;

expect(proc.exitCode).toBe(0);
expect(stdout).toContain(outputDir);

// Verify files exist in the output directory
const files = await fs.readdir(outputDir);
expect(files.length).toBeGreaterThan(0);
});

it("should generate correct number of method files", async () => {
const outputDir = path.join(tempDir, "count-output");
await fs.mkdir(outputDir, { recursive: true });

const proc = Bun.spawn(["bun", CLI_PATH, FIXTURE_PATH, "-m", outputDir], {
stdout: "pipe",
stderr: "pipe",
});

await proc.exited;

expect(proc.exitCode).toBe(0);

const files = await fs.readdir(outputDir);
// 26 method files + 1 index.md = 27 total
expect(files.length).toBe(27);
});

it("should generate valid markdown content", async () => {
const outputDir = path.join(tempDir, "content-output");
await fs.mkdir(outputDir, { recursive: true });

const proc = Bun.spawn(["bun", CLI_PATH, FIXTURE_PATH, "-m", outputDir], {
stdout: "pipe",
stderr: "pipe",
});

await proc.exited;

expect(proc.exitCode).toBe(0);

// Read one of the generated files and verify content
const methodFile = await fs.readFile(
path.join(outputDir, "test_allOf_composition_param.mdx"),
"utf8",
);

expect(methodFile).toContain("---");
expect(methodFile).toContain('title: "test_allOf_composition_param"');
expect(methodFile).toContain("Parameters");
});

it("should error on non-existent document path", async () => {
const proc = Bun.spawn(["bun", CLI_PATH, "/non/existent/path.json"], {
stdout: "pipe",
stderr: "pipe",
});

const stderr = await new Response(proc.stderr).text();
await proc.exited;

expect(proc.exitCode).toBe(1);
expect(stderr).toContain("Error:");
});
});
1 change: 0 additions & 1 deletion packages/markdown-generator/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bun
/* eslint-disable no-console */
/* global Bun */
import { parseArgs } from "node:util";
import path from "node:path";
import { renderDocumentToMarkdownFiles } from "./lib";
Expand Down
Loading
Loading