Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Docusarus NodeJS api #4841

Open
fforres opened this issue May 24, 2021 · 1 comment
Open

[Proposal] Docusarus NodeJS api #4841

fforres opened this issue May 24, 2021 · 1 comment
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee proposal This issue is a proposal, usually non-trivial change
Milestone

Comments

@fforres
Copy link

fforres commented May 24, 2021

🚀 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>
}> 
@fforres fforres added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels May 24, 2021
@slorber
Copy link
Collaborator

slorber commented Jun 2, 2021

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

You could implement a plugin, the getPathsToWatch lifecycle allows to register a path like somePath/**/*.md and content will hot reload everytime a file changes

I'd also like to make it easier to integrate with CMSs. The issue is a bit messy but you may find relevant intos here:

We could have a way for plugins to trigger site content reloads on a per-plugin basis, eventually, listen for a CMS to send a notification for changes etc...

I don't think we'll expose an imperative Nodejs API, but rather expose the required APIs for such use-cases through plugin lifecycles. You will have to implement your own plugin

@Josh-Cena Josh-Cena added proposal This issue is a proposal, usually non-trivial change and removed feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Oct 30, 2021
@Josh-Cena Josh-Cena added this to the backlog milestone Mar 25, 2022
@slorber slorber modified the milestones: Roadmap, Upcoming Aug 17, 2023
@slorber slorber added the apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee label Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apprentice Issues that are good candidates to be handled by a Docusaurus apprentice / trainee proposal This issue is a proposal, usually non-trivial change
Projects
None yet
Development

No branches or pull requests

3 participants