@@ -5,37 +5,22 @@ import type { LoadContext, Plugin } from "@docusaurus/types";
55import type { PluginContent } from "./types" ;
66import type { Options , PluginOptions } from "./options" ;
77import { normalizeOptions } from "./options" ;
8- import { generateDocs } from "./lib" ;
8+ import { cleanUpExistingDocs , generateDocs } from "./lib" ;
99import fs from "fs/promises" ;
1010import path from "path" ;
11+ import { parseOpenRPCDocument } from "@open-rpc/schema-utils-js" ;
12+ import { DereffedOpenrpcDocument } from "@open-rpc/markdown-generator" ;
1113
1214const PluginName = "@open-rpc/docusaurus-plugin" ;
1315
14- async function initDocs (
16+ async function rebuildDocs (
1517 specPath : string ,
1618 outputDir : string ,
1719 options : PluginOptions ,
1820) {
19- if ( ! ( await fs . stat ( specPath ) ) . isFile ( ) ) {
20- throw new Error ( `OpenRPC spec file not found: ${ specPath } ` ) ;
21- }
22-
23- try {
24- const entries = await fs . readdir ( outputDir , { withFileTypes : true } ) ;
25- await Promise . all (
26- entries
27- . filter ( ( entry ) => entry . name !== "index.md" )
28- . map ( ( entry ) => {
29- const fullPath = `${ outputDir } /${ entry . name } ` ;
30- return fs . rm ( fullPath , { recursive : true , force : true } ) ;
31- } ) ,
32- ) ;
33- } catch {
34- // Directory doesn't exist yet, that's fine
35- }
36-
3721 try {
3822 await generateDocs ( specPath , outputDir , options ) ;
23+ await cleanUpExistingDocs ( specPath , outputDir ) ;
3924 } catch ( err ) {
4025 logger . error ( `[${ PluginName } ] generateDocs failed: ${ err } ` ) ;
4126 logger . error (
@@ -61,7 +46,7 @@ export default async function openRPCDocusaurusPlugin(
6146 normalizedOptions . docOutputPath ,
6247 ) ;
6348
64- await initDocs ( specPath , outputDir , normalizedOptions ) ;
49+ await rebuildDocs ( specPath , outputDir , normalizedOptions ) ;
6550
6651 return {
6752 name : PluginName ,
@@ -95,7 +80,7 @@ export default async function openRPCDocusaurusPlugin(
9580 */
9681 async contentLoaded ( { content, actions } ) : Promise < void > {
9782 logger . info ( `[${ PluginName } ] contentLoaded called` ) ;
98- await initDocs ( specPath , outputDir , normalizedOptions ) ;
83+ await rebuildDocs ( specPath , outputDir , normalizedOptions ) ;
9984 } ,
10085
10186 /**
0 commit comments