UNPKG

6.05 kBTypeScriptView Raw
1import * as reflect from 'jsii-reflect';
2import { TargetLanguage } from 'jsii-rosetta';
3import { Json } from '../render/json';
4import { MarkdownDocument } from '../render/markdown-doc';
5import { MarkdownFormattingOptions } from '../render/markdown-render';
6import { Schema } from '../schema';
7import { CSharpTranspile } from '../transpile/csharp';
8import { GoTranspile } from '../transpile/go';
9import { JavaTranspile } from '../transpile/java';
10import { PythonTranspile } from '../transpile/python';
11import { Language } from '../transpile/transpile';
12import { TypeScriptTranspile } from '../transpile/typescript';
13/**
14 * Options for rendering a `Documentation` object.
15 */
16export interface RenderOptions extends TransliterationOptions {
17 /**
18 * Which language to generate docs for.
19 */
20 readonly language: Language;
21 /**
22 * Include a generated api reference in the documentation.
23 *
24 * @default true
25 */
26 readonly apiReference?: boolean;
27 /**
28 * Include the user defined README.md in the documentation.
29 *
30 * @default false
31 */
32 readonly readme?: boolean;
33 /**
34 * Generate documentation only for a specific submodule.
35 *
36 * @default - Documentation is generated for the root module only.
37 */
38 readonly submodule?: string;
39 /**
40 * Generate a single document with APIs from all assembly submodules
41 * (including the root).
42 *
43 * Note: only the root-level README is included.
44 *
45 * @default false
46 */
47 readonly allSubmodules?: boolean;
48}
49export interface TransliterationOptions {
50 /**
51 * Whether to ignore missing fixture files that will prevent transliterating
52 * some code snippet examples.
53 *
54 * @default true
55 */
56 readonly loose?: boolean;
57 /**
58 * Whether to validate jsii assemblies against the jsii schema before
59 * using them.
60 *
61 * @default false
62 */
63 readonly validate?: boolean;
64}
65export interface MarkdownRenderOptions extends RenderOptions, MarkdownFormattingOptions {
66}
67/**
68 * Options for creating a `Documentation` object using the `fromLocalPackage` function.
69 */
70export interface ForLocalPackageDocumentationOptions {
71 /**
72 * A local directory containing jsii assembly files that will
73 * comprise the type-system.
74 *
75 * @default - the root package directory will be used.
76 */
77 readonly assembliesDir?: string;
78}
79export interface ForPackageDocumentationOptions {
80 /**
81 * Whether verbose logging is to be performed.
82 *
83 * @default true
84 */
85 readonly verbose?: boolean;
86}
87/**
88 * Render documentation pages for a jsii library.
89 */
90export declare class Documentation {
91 private readonly assemblyName;
92 private readonly assembliesDir;
93 /**
94 * Create a `Documentation` object from a package installable by npm.
95 *
96 * Note that this method installs the target package to the local file-system. Make sure
97 * to call `Documentation.cleanup` once you are done rendering.
98 *
99 * @param target - The target to install. This can either be a local path or a registry identifier (e.g <name>@<version>)
100 * @param options - Additional options.
101 *
102 * @throws NoSpaceLeftOnDevice if the installation fails due to running out of disk space
103 * @throws NpmError if some `npm` command fails when preparing the working set
104 */
105 static forPackage(target: string, options?: ForPackageDocumentationOptions): Promise<Documentation>;
106 /**
107 * Create a `Documentation` object from a local directory containing a node project.
108 *
109 * @param root - The local directory path. Must contain a package.json file.
110 * @param options - Additional options.
111 */
112 static forProject(root: string, options?: ForLocalPackageDocumentationOptions): Promise<Documentation>;
113 /**
114 * Create a `Documentation` object for a specific assembly from a directory of assemblies.
115 *
116 * @param assemblyName - The assembly name.
117 * @param assembliesDir - The directory containing the assemblies that comprise the type-system.
118 */
119 static forAssembly(assemblyName: string, assembliesDir: string): Promise<Documentation>;
120 private readonly cleanupDirectories;
121 private readonly assembliesCache;
122 private assemblyFqn;
123 private constructor();
124 /**
125 * List all submodules in the assembly.
126 */
127 listSubmodules(): Promise<readonly reflect.Submodule[]>;
128 toIndexMarkdown(fileSuffix: string, options: RenderOptions): Promise<MarkdownDocument>;
129 /**
130 * Generate markdown.
131 */
132 toJson(options: RenderOptions): Promise<Json<Schema>>;
133 toMarkdown(options: MarkdownRenderOptions): Promise<MarkdownDocument>;
134 private addCleanupDirectory;
135 /**
136 * Removes any internal working directories.
137 */
138 cleanup(): Promise<void>;
139 private languageSpecific;
140 /**
141 * Lookup a submodule by a submodule name.
142 *
143 * The contract of this function is historically quite confused: the submodule
144 * name can be either an FQN (`asm.sub1.sub2`) or just a submodule name
145 * (`sub1` or `sub1.sub2`).
146 *
147 * This is sligthly complicated by ambiguity: `asm.asm.package` and
148 * `asm.package` can both exist, and which one do you mean when you say
149 * `asm.package`?
150 *
151 * We prefer an FQN match if possible (`asm.sub1.sub2`), but will accept a
152 * root-relative submodule name as well (`sub1.sub2`).
153 */
154 private findSubmodule;
155 private createAssembly;
156}
157export declare const LANGUAGE_SPECIFIC: {
158 [x: string]: {
159 transpile: PythonTranspile;
160 rosettaTarget: TargetLanguage;
161 } | {
162 transpile: TypeScriptTranspile;
163 rosettaTarget: undefined;
164 } | {
165 transpile: JavaTranspile;
166 rosettaTarget: TargetLanguage;
167 } | {
168 transpile: CSharpTranspile;
169 rosettaTarget: TargetLanguage;
170 } | {
171 transpile: GoTranspile;
172 rosettaTarget: TargetLanguage;
173 };
174};
175export declare function extractPackageName(spec: string): string;