Skip to content

[Proposal] Docusarus NodeJS api #4841

@fforres

Description

@fforres

🚀 Feature

Expose (some) docusaurus functionality through a NodeJS api.

Have you read the Contributing Guidelines on issues?

Yes

Motivation

At my work I have implemented an automated documentation flow using docusaurus, react-docgen, react-docgen-typescript and file-watchers.

We are aiming maintain a good DX in writing documents, so we implemented a flow that uses chokidar to watch multiple project's files (Files in our component library repository, our mobile repo, our main application repo, etc) and generate a bunch of .md files that then docusuarus renders.

However, there is ATM not an "official" way to programmatically start/stop a docusaurus process.

Pitch

ATM our solution is to reach inside docusaurus core

import { start as startDocusaurus } from "@docusaurus/core/lib";


/// much code

startDocusaurus(DOCS_ROOT, {
    port: undefined,
    host: undefined,
    locale: undefined,
    hotOnly: undefined,
    open: true,
    poll: undefined,
});

Unsure on the API exactly, but Ideally we would expose a method that would essentially return a a wrapper around WebpackDevServer 's .listen and .close methods, so expose specific controls over it and not return the whole devServer.

const devServer = new WebpackDevServer(compiler, devServerConfig);

A rough schema of what I have in mind

type SomeDocusaurusInformation = {
	pid: number;
	port: number;
	filesWatched: string[];
	/// idk, something else. 
}

export default async function start(
  siteDir: string,
  cliOptions: Partial<StartCLIOptions>,
): Promise<{
	start: Promise<SomeDocusaurusInformation>
	close: Promise<void>
}> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    apprenticeIssues that are good candidates to be handled by a Docusaurus apprentice / traineeproposalThis issue is a proposal, usually non-trivial change

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions