Skip to content

Commit

Permalink
fix: split by submodule ignores output
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Oct 2, 2023
1 parent 6c90770 commit 9b3ad15
Show file tree
Hide file tree
Showing 5 changed files with 1,114 additions and 11 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ Curreently jsii-docgen supports generating documentation in the following langua

## CLI Options

| Option | Required | Description |
|:--------------------| :------- |:---------------------------------------------------------------------------------------------------------------------------------------------|
| `--output`, `-o` | optional | Output filename (defaults to API.md if format is markdown, and API.json if format is JSON). <br /><br />`jsii-docgen -o ./docs/API.md` |
| `--format`, `-f` | optional | Output format. Can be `markdown` or `json`. <br /><br />`jsii-docgen -f json` |
| `--language`, `-l` | optional | Language to generate documentation for. Can be `typescript`, `python`, `java`, `csharp` or `go`. <br /><br />`jsii-docgen -l typescript` |
| `--package`, `-p` | optional | The name@version of an NPM package to document. <br /><br />`jsii-docgen -p my-package` |
| `--submodule`, `-s` | optional | Generate docs for a specific submodule or "root". <br /><br />`jsii-docgen -s my-submodule` |
| `--readme`, `-r` | optional | Generate docs for user specified README.md. <br /><br />`jsii-docgen -r` |
| Option | Required | Description |
| :--------------------- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
| `--output`, `-o` | optional | Output filename (defaults to API.md if format is markdown, and API.json if format is JSON). <br /><br/>`jsii-docgen -o ./docs/API.md` |
| `--format`, `-f` | optional | Output format. Can be `markdown` or `json`. <br /><br />`jsii-docgen -f json` |
| `--language`, `-l` | optional | Language to generate documentation for. Can be `typescript`, `python`, `java`, `csharp` or `go`. <br /><br />`jsii-docgen -l typescript` |
| `--package`, `-p` | optional | The name@version of an NPM package to document. <br /><br />`jsii-docgen -p my-package` |
| `--readme`, `-r` | optional | Generate docs for user specified README.md. <br /><br />`jsii-docgen -r` |
| `--submodule`, `-s` | optional | Generate docs for a specific submodule or "root". <br /><br />`jsii-docgen -s my-submodule` |
| `--split-by-submodule` | optional | Generate a separate file for each submodule. <br /><br />`jsii-docgen --split-by-submodule` |

## Contributions

Expand Down
11 changes: 8 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs/promises';
import * as path from 'node:path';
import * as yargs from 'yargs';
import { Language } from './docgen/transpile/transpile';
import { Documentation } from './index';
Expand All @@ -23,10 +24,14 @@ async function generateForLanguage(docs: Documentation, options: GenerateOptions
: output;
// e.g. API.typescript as name
if (outputFileName.includes('.')) {
const languageSeperator = outputFileName.split('.')[1];
submoduleSuffix = `${languageSeperator}.${fileSuffix}`;
const languageSeparator = outputFileName.split('.')[1];
submoduleSuffix = `${languageSeparator}.${fileSuffix}`;
}

// Ensure the output path exists
const outputPath = path.dirname(outputFileName);
await fs.mkdir(outputPath, { recursive: true });

if (options.splitBySubmodules) {
if (format !== 'md') {
throw new Error('split-by-submodule is only supported for markdown');
Expand All @@ -41,7 +46,7 @@ async function generateForLanguage(docs: Documentation, options: GenerateOptions
header: { title: `\`${submodule.name}\` Submodule`, id: submodule.fqn },
});

await fs.writeFile(`${submodule.name}.${submoduleSuffix}`, content.render());
await fs.writeFile(path.join(outputPath, `${submodule.name}.${submoduleSuffix}`), content.render());
}

await fs.writeFile(`${outputFileName}.${fileSuffix}`, await (await docs.toIndexMarkdown(submoduleSuffix, options)).render());
Expand Down
1 change: 1 addition & 0 deletions test/__fixtures__/libraries/construct-library/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.d.ts
*.jsii
API.md
docs/**
node_modules/
tsconfig.json
tsconfig.tsbuildinfo
Loading

0 comments on commit 9b3ad15

Please sign in to comment.