Skip to content

Commit 046e27a

Browse files
authored
add redocly docs generation (#4)
1 parent 6b96b8d commit 046e27a

File tree

18 files changed

+371
-296
lines changed

18 files changed

+371
-296
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@ See:
3838

3939
Configure via the following environment variables:
4040

41-
`OPENAPI_INPUT` - File to process (**default**: `./openapi/openapi.yaml`)
41+
`OPENAPI_INPUT` - File to process
4242

43-
`OPENAPI_OUTPUT` - Where to write output file (**default**: `./dist/openapi.yaml`)
43+
- **default** `redocly-*` - `./openapi/openapi.yaml`
4444

45-
`OPENAPI_FORMAT` - Output format (**default**: `yaml`)
45+
`OPENAPI_OUTPUT` - Where to write output file
4646

47-
`OPENAPI_LINT_FORMAT` - Linter report format (**default**: `codeframe`)
47+
- **default** `redocly-bundle` - `./dist/openapi.yaml`
48+
- **default** `redocly-build-docs` - `./dist/openapi.html`
4849

49-
`OPENAPI_CONFIG_PATH` - Path to redocly.yaml (**default**: `./redocly.yaml`)
50+
`OPENAPI_FORMAT` - Output format
51+
52+
- **default** `redocly-bundle` - `yaml`
53+
- **default** `redocly-lint` - `codeframe`
54+
55+
`OPENAPI_CONFIG_PATH` - Path to redocly.yaml
56+
57+
- **default** `redocly-*` - `none` or `./redocly.yaml`

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
"@bymbly:registry": "https://npm.pkg.github.com"
1616
},
1717
"bin": {
18-
"openapi-bundle": "./dist/bin/bundle.js",
19-
"openapi-lint": "./dist/bin/lint.js"
18+
"redocly-bundle": "./dist/bin/redocly/bundle.js",
19+
"redocly-lint": "./dist/bin/redocly/lint.js",
20+
"redocly-build-docs": "./dist/bin/redocly/build-docs.js"
2021
},
2122
"scripts": {
2223
"build": "tsc",
2324
"watch": "tsc --watch",
2425
"prepublishOnly": "npm run build",
2526
"test": "vitest run",
2627
"test:watch": "vitest",
27-
"test:ui": "vitest --ui"
28+
"test:ui": "vitest --ui",
29+
"test:update": "vitest --update"
2830
},
2931
"dependencies": {
3032
"@redocly/cli": "^2.12.3",

src/bin/bundle.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/bin/lint.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/bin/redocly/build-docs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { buildDocs } from "../../lib/redocly/build-docs.js";
4+
5+
buildDocs();

src/bin/redocly/bundle.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { bundle } from "../../lib/redocly/bundle.js";
4+
5+
bundle();

src/bin/redocly/lint.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { lint } from "../../lib/redocly/lint.js";
4+
5+
lint();

src/lib/redocly/build-docs.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { execSync } from "child_process";
2+
import { createPath } from "../utils.js";
3+
4+
export interface BuildDocsOptions {
5+
input: string;
6+
output: string;
7+
configPath?: string;
8+
}
9+
10+
export function getOptions(): BuildDocsOptions {
11+
return {
12+
input: process.env.OPENAPI_INPUT || "openapi/openapi.yaml",
13+
output: process.env.OPENAPI_OUTPUT || "dist/openapi.html",
14+
configPath: process.env.OPENAPI_CONFIG,
15+
};
16+
}
17+
18+
export function buildDocs(): void {
19+
const options = getOptions();
20+
21+
console.log(`📚 Building documentation...`);
22+
console.log(` Input: ${options.input}`);
23+
console.log(` Output: ${options.output}`);
24+
console.log(` Config: ${options.configPath || "default"}`);
25+
26+
let command = `npx --no @redocly/cli build-docs ${options.input} --output ${options.output}`;
27+
if (options.configPath) {
28+
command += ` --config ${options.configPath}`;
29+
}
30+
31+
createPath(options.output);
32+
33+
try {
34+
execSync(command, { stdio: "inherit" });
35+
36+
console.log(`✅ Documentation built successfully: ${options.output}`);
37+
} catch (error) {
38+
console.error(`❌ Building documentation failed!`);
39+
console.error(`${error instanceof Error ? error.message : String(error)}`);
40+
process.exit(1);
41+
}
42+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from "child_process";
2-
import { createPath, createValidator } from "./utils.js";
2+
import { createPath, createValidator } from "../utils.js";
33

44
const VALID_FORMATS = ["json", "yaml"] as const;
55
export type Format = (typeof VALID_FORMATS)[number];

src/lib/lint.ts renamed to src/lib/redocly/lint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from "child_process";
2-
import { createValidator } from "./utils.js";
2+
import { createValidator } from "../utils.js";
33

44
const VALID_FORMATS = [
55
"codeframe",
@@ -23,7 +23,7 @@ const lintFormatValidator = createValidator(VALID_FORMATS);
2323
export const isValidLintFormat = lintFormatValidator.isValid;
2424

2525
export function getOptions(): LintOptions {
26-
const formatEnv = process.env.OPENAPI_LINT_FORMAT;
26+
const formatEnv = process.env.OPENAPI_FORMAT;
2727
const format =
2828
formatEnv && isValidLintFormat(formatEnv) ? formatEnv : "codeframe";
2929

0 commit comments

Comments
 (0)