@ir-kit/spec-docs 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ahmed Rowaihi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # `@ir-kit/spec-docs`
2
+
3
+ Render any supported API spec as a standalone HTML documentation page via [Scalar API Reference](https://github.com/scalar/scalar). Converts the input to OpenAPI 3 first (using `@ir-kit/spec-convert`), then delegates HTML emission to `@scalar/core`'s `getHtmlDocument` — the same renderer the official Express / Hono / Fastify integrations use.
4
+
5
+ Part of [ir-kit](https://github.com/ir-kit/ir-kit).
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @ir-kit/spec-docs
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { writeFile } from "node:fs/promises";
17
+ import { renderDocs } from "@ir-kit/spec-docs";
18
+
19
+ const { html } = await renderDocs({
20
+ input: "./api.yaml", // postman / proto / typespec / openapi3 / asyncapi3
21
+ theme: "moon", // optional Scalar theme
22
+ });
23
+
24
+ await writeFile("docs.html", html);
25
+ ```
26
+
27
+ The output is a self-contained HTML page that loads Scalar from CDN — no bundler required, ready to drop on any static host.
28
+
29
+ ## API
30
+
31
+ | Export | Description |
32
+ | ---------------------------------------------------- | --------------------------------------------------------------------- |
33
+ | `renderDocs(opts)` | Convert spec to OpenAPI 3 if needed, return `{ html, openapi, from }` |
34
+ | `RenderDocsOptions`, `RenderDocsResult`, `DocsTheme` | Public types |
35
+
36
+ Any input format supported by [`@ir-kit/spec-convert`](../spec-convert) works (currently: openapi3, postman, proto, typespec, asyncapi3, json-schema).
37
+
38
+ ## CLI
39
+
40
+ ```sh
41
+ ir docs ./api.yaml --out docs.html
42
+ ir docs ./collection.postman_collection.json --theme moon --out docs.html
43
+ ```
@@ -0,0 +1,23 @@
1
+ import type { ConvertSpecInput, SpecDocument, SpecFormat } from "@ir-kit/spec-convert";
2
+ export type DocsTheme = "default" | "alternate" | "moon" | "purple" | "solarized" | "bluePlanet" | "saturn" | "kepler" | "mars" | "deepSpace" | "none";
3
+ export interface RenderDocsOptions {
4
+ input: ConvertSpecInput;
5
+ from?: SpecFormat;
6
+ cwd?: string;
7
+ theme?: DocsTheme;
8
+ /** Extra Scalar configuration merged into the HTML render. */
9
+ scalar?: Record<string, unknown>;
10
+ }
11
+ export interface RenderDocsResult {
12
+ html: string;
13
+ openapi: SpecDocument;
14
+ from: SpecFormat;
15
+ }
16
+ /**
17
+ * Render any supported spec format as a standalone HTML page via
18
+ * Scalar API Reference. Converts to OpenAPI 3 first (if needed), then
19
+ * delegates HTML emission to `@scalar/core` — same renderer used by
20
+ * the official Express/Hono/Fastify integrations.
21
+ */
22
+ export declare function renderDocs(opts: RenderDocsOptions): Promise<RenderDocsResult>;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACX,MAAM,sBAAsB,CAAC;AAK9B,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,WAAW,GACX,MAAM,GACN,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,WAAW,GACX,MAAM,CAAC;AAEX,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAmB3B"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ import { convertSpec } from "@ir-kit/spec-convert";
2
+ import { getHtmlDocument } from "@scalar/core/libs/html-rendering";
3
+ /**
4
+ * Render any supported spec format as a standalone HTML page via
5
+ * Scalar API Reference. Converts to OpenAPI 3 first (if needed), then
6
+ * delegates HTML emission to `@scalar/core` — same renderer used by
7
+ * the official Express/Hono/Fastify integrations.
8
+ */
9
+ export async function renderDocs(opts) {
10
+ const result = await convertSpec({
11
+ input: opts.input,
12
+ from: opts.from,
13
+ to: "openapi3",
14
+ cwd: opts.cwd,
15
+ });
16
+ if (result.output.kind !== "document") {
17
+ throw new Error(`Unexpected converter output kind '${result.output.kind}' for openapi3 target`);
18
+ }
19
+ const openapi = result.output.document;
20
+ const html = getHtmlDocument({
21
+ content: openapi,
22
+ ...(opts.theme ? { theme: opts.theme } : {}),
23
+ ...opts.scalar,
24
+ });
25
+ return { html, openapi, from: result.from };
26
+ }
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AA8BnE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAAuB;IAEvB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC;QAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,EAAE,EAAE,UAAU;QACd,GAAG,EAAE,IAAI,CAAC,GAAG;KACd,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,uBAAuB,CAC/E,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;IACvC,MAAM,IAAI,GAAG,eAAe,CAAC;QAC3B,OAAO,EAAE,OAAO;QAChB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,GAAG,IAAI,CAAC,MAAM;KACf,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AAC9C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@ir-kit/spec-docs",
3
+ "version": "0.2.0",
4
+ "description": "Render any API spec as standalone HTML documentation via Scalar API Reference. Programmatic + CLI.",
5
+ "keywords": [
6
+ "openapi",
7
+ "asyncapi",
8
+ "typespec",
9
+ "protobuf",
10
+ "postman",
11
+ "docs",
12
+ "scalar",
13
+ "ir-kit"
14
+ ],
15
+ "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/shared/spec-docs",
16
+ "bugs": {
17
+ "url": "https://github.com/ir-kit/ir-kit/issues"
18
+ },
19
+ "license": "MIT",
20
+ "author": {
21
+ "name": "Ahmed Rowaihi",
22
+ "email": "ahmedrowaihi@gmail.com"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/ir-kit/ir-kit.git",
27
+ "directory": "packages/shared/spec-docs"
28
+ },
29
+ "type": "module",
30
+ "sideEffects": false,
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md",
43
+ "LICENSE.md"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "dependencies": {
50
+ "@scalar/core": "^0.5.9",
51
+ "@ir-kit/spec-convert": "0.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^22",
55
+ "vitest": "^4.0.0",
56
+ "@ir-kit/tsconfig": "0.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=20.19.0"
60
+ },
61
+ "scripts": {
62
+ "build": "tsc -p tsconfig.build.json",
63
+ "dev": "tsc -p tsconfig.build.json --watch",
64
+ "typecheck": "tsc --noEmit",
65
+ "test": "vitest run --passWithNoTests"
66
+ }
67
+ }