This repository was archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdocs.js
56 lines (45 loc) · 1.39 KB
/
docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /usr/bin/env node
const program = require('../../src/bin/program');
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { writeFileSync, existsSync, mkdirSync } from 'fs';
import Main from '../components/Main';
import Command from '../components/Command';
import path from 'path';
import process from 'process';
const outputPath = 'docs/build';
function formatContent(id, title, content){
return `---
id: ${id}
title: ${title}
---
${content}
`;
}
function writeMd(id, title, content) {
const data = formatContent(id, title, content);
writeFileSync(path.resolve(outputPath, `cli_${id}.md`), data);
}
function makeSidebar(program) {
return {
'cli-api': {
'OVERVIEW': ['cli_main'],
'COMMANDS': program.commands.map(command => `cli_${command.name()}`)
}
};
}
function run() {
if (!existsSync(outputPath)) {
mkdirSync(outputPath);
}
const main = renderToStaticMarkup(React.createElement(Main, { program }));
writeMd('main', 'Entrypoint', main);
program.commands.forEach(command => {
const content = renderToStaticMarkup(React.createElement(Command, { command }));
writeMd(command.name(), command.name(), content);
});
const sidebar = makeSidebar(program);
writeFileSync(path.resolve(outputPath, 'sidebars.json'), JSON.stringify(sidebar, null, 2));
}
run();
console.log(`Docs generated in ${process.cwd()}/${outputPath}`)