facebook / facebook/docusaurus

[Proposal] Docusarus NodeJS api

Đang mở
#4,841 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
proposal
Ngôn ngữ chính
TypeScript
Star
66.2k
Fork
10k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
52

Mô tả

## 🚀 Feature

Expose (some) docusaurus functionality through a NodeJS api.

### Have you read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/master/CONTRIBUTING.md#reporting-new-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

```TSX
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.

https://github.com/facebook/docusaurus/blob/3548686f596bba8dcd79f57f6a697d8f06a2fcd3/packages/docusaurus/src/commands/start.ts#L215

A rough schema of what I have in mind
```TSX

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

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

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.