Skip to content

Commit d8bec24

Browse files
authored
feat: add useReadme flag for parsing only README (#33)
1 parent 528c9c6 commit d8bec24

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ electron-docs-parser --dir ./
1212
# You now have ./electron-api.json with the entire Electron API
1313
```
1414

15+
Options:
16+
* `--useReadme` - Assume all documentation is in the module's base `README.md` file
17+
* `--dir` - The base directory where documentation is located.
18+
* API documentation must be located in `/docs/api` within the specified base directory.
19+
* API structures documentation must be located in `/docs/api/structures` within the specified base directory.
20+
* `--packageMode` - Can be `single` or `multi`; default `single`. Specifying `multi` allows exporting multiple packages from an API instead of multiple modules from a single package.
21+
1522
## How it Works
1623

1724
We generate a markdown AST for every documentation file and search for

src/bin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const args = minimist(process.argv, {
1515
},
1616
});
1717

18-
const { dir, outDir, packageMode, help } = args;
18+
const { dir, outDir, useReadme, packageMode, help } = args;
1919
if (!['single', 'multi'].includes(packageMode)) {
2020
console.error(chalk.red('packageMode must be one of "single" and "multi"'));
2121
process.exit(1);
@@ -64,6 +64,7 @@ const start = Date.now();
6464

6565
fs.mkdirp(resolvedOutDir).then(() =>
6666
parseDocs({
67+
useReadme: useReadme ? true : false,
6768
baseDirectory: resolvedDir,
6869
moduleVersion: pj.version,
6970
packageMode,

src/index.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@ import { DocsParser } from './DocsParser';
44

55
type ParseOptions = {
66
baseDirectory: string;
7+
useReadme: boolean;
78
moduleVersion: string;
89
packageMode?: 'single' | 'multi';
910
};
1011

1112
export async function parseDocs(options: ParseOptions) {
1213
const packageMode = options.packageMode || 'single';
13-
const electronDocsPath = path.resolve(options.baseDirectory, 'docs', 'api');
14+
15+
const apiDocsPath = options.baseDirectory || path.resolve('./', 'docs', 'api');
16+
const structuresPath = path.resolve(apiDocsPath, 'structures');
17+
18+
let structures: string[] = [];
19+
let apis: string[] = [];
20+
21+
if (options.useReadme) {
22+
const readmePath = path.resolve(options.baseDirectory, 'README.md');
23+
if (!fs.existsSync(readmePath)) {
24+
throw new Error('README.md file not found');
25+
}
26+
apis = [readmePath];
27+
} else {
28+
structures = await getAllMarkdownFiles(structuresPath);
29+
apis = await getAllMarkdownFiles(apiDocsPath);
30+
}
1431

1532
const parser = new DocsParser(
1633
options.baseDirectory,
1734
options.moduleVersion,
18-
await getAllMarkdownFiles(electronDocsPath),
19-
await getAllMarkdownFiles(path.resolve(electronDocsPath, 'structures')),
35+
apis,
36+
structures,
2037
packageMode,
2138
);
2239

0 commit comments

Comments
 (0)