@stainless-api/docs 0.1.0-beta.8 → 0.1.0-beta.80
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/CHANGELOG.md +636 -0
- package/eslint-suppressions.json +52 -0
- package/locals.d.ts +17 -0
- package/package.json +50 -39
- package/plugin/assets/languages/cli.svg +14 -0
- package/plugin/assets/languages/csharp.svg +1 -0
- package/plugin/buildAlgoliaIndex.ts +32 -7
- package/plugin/cms/server.ts +130 -59
- package/plugin/cms/sidebar-builder.ts +7 -26
- package/plugin/cms/worker.ts +83 -5
- package/plugin/components/MethodDescription.tsx +54 -0
- package/plugin/components/RequestBuilder/ParamEditor.tsx +55 -0
- package/plugin/components/RequestBuilder/SnippetStainlessIsland.tsx +107 -0
- package/plugin/components/RequestBuilder/index.tsx +31 -0
- package/plugin/components/RequestBuilder/props.ts +9 -0
- package/plugin/components/RequestBuilder/spec-helpers.ts +50 -0
- package/plugin/components/RequestBuilder/styles.css +67 -0
- package/plugin/components/SDKSelect.astro +7 -87
- package/plugin/components/SnippetCode.tsx +107 -67
- package/plugin/components/StainlessIslands.tsx +126 -0
- package/plugin/components/search/SearchAlgolia.astro +45 -28
- package/plugin/components/search/SearchIsland.tsx +45 -27
- package/plugin/generateAPIReferenceLink.ts +2 -2
- package/plugin/globalJs/ai-dropdown-options.ts +243 -0
- package/plugin/globalJs/code-snippets.ts +15 -8
- package/plugin/globalJs/copy.ts +91 -17
- package/plugin/globalJs/create-playground.shim.ts +3 -0
- package/plugin/globalJs/method-descriptions.ts +33 -0
- package/plugin/globalJs/navigation.ts +7 -26
- package/plugin/globalJs/playground-data.shim.ts +1 -0
- package/plugin/globalJs/playground-data.ts +14 -0
- package/plugin/helpers/generateDocsRoutes.ts +27 -0
- package/plugin/index.ts +198 -36
- package/plugin/languages.ts +7 -2
- package/plugin/loadPluginConfig.ts +122 -36
- package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
- package/plugin/react/Routing.tsx +199 -126
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +3 -3
- package/plugin/routes/Docs.astro +55 -102
- package/plugin/routes/DocsStatic.astro +1 -1
- package/plugin/routes/Overview.astro +10 -16
- package/plugin/routes/markdown.ts +9 -8
- package/plugin/vendor/preview.worker.docs.js +20928 -17830
- package/plugin/vendor/templates/go.md +1 -1
- package/plugin/vendor/templates/python.md +1 -1
- package/resolveSrcFile.ts +10 -0
- package/scripts/vendor_deps.ts +5 -5
- package/shared/getProsePages.ts +42 -0
- package/shared/getSharedLogger.ts +15 -0
- package/shared/terminalUtils.ts +3 -0
- package/src/content.config.ts +9 -0
- package/stl-docs/components/AIDropdown.tsx +63 -0
- package/stl-docs/components/AiChatIsland.tsx +14 -0
- package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +2 -2
- package/stl-docs/components/Head.astro +16 -0
- package/stl-docs/components/Header.astro +6 -8
- package/stl-docs/components/PageFrame.astro +18 -0
- package/stl-docs/components/PageTitle.astro +82 -0
- package/stl-docs/components/TableOfContents.astro +34 -0
- package/stl-docs/components/ThemeProvider.astro +36 -0
- package/stl-docs/components/ThemeSelect.astro +84 -139
- package/stl-docs/components/content-panel/ContentPanel.astro +15 -46
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
- package/stl-docs/components/headers/StackedHeader.astro +29 -24
- package/stl-docs/components/icons/chat-gpt.tsx +2 -2
- package/stl-docs/components/icons/cursor.tsx +10 -0
- package/stl-docs/components/icons/gemini.tsx +19 -0
- package/stl-docs/components/icons/markdown.tsx +1 -1
- package/stl-docs/components/index.ts +1 -0
- package/stl-docs/components/mintlify-compat/Accordion.astro +7 -5
- package/stl-docs/components/mintlify-compat/AccordionGroup.astro +7 -3
- package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
- package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
- package/stl-docs/components/mintlify-compat/callouts/Callout.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Check.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Danger.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Info.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Note.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Tip.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Warning.astro +1 -1
- package/stl-docs/components/mintlify-compat/card.css +33 -35
- package/stl-docs/components/mintlify-compat/index.ts +2 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -70
- package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
- package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
- package/stl-docs/components/nav-tabs/buildNavLinks.ts +3 -2
- package/stl-docs/components/pagination/HomeLink.astro +10 -0
- package/stl-docs/components/pagination/Pagination.astro +175 -0
- package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
- package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
- package/stl-docs/components/pagination/util.ts +71 -0
- package/stl-docs/components/scripts.ts +1 -0
- package/stl-docs/disableCalloutSyntax.ts +36 -0
- package/stl-docs/index.ts +147 -52
- package/stl-docs/loadStlDocsConfig.ts +45 -7
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +61 -0
- package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +39 -0
- package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
- package/stl-docs/proseSearchIndexing.ts +450 -0
- package/stl-docs/tabsMiddleware.ts +13 -4
- package/styles/code.css +128 -136
- package/styles/fonts.css +32 -17
- package/styles/links.css +11 -48
- package/styles/method-descriptions.css +36 -0
- package/styles/overrides.css +49 -57
- package/styles/page.css +90 -59
- package/styles/sdk_select.css +9 -7
- package/styles/search.css +57 -69
- package/styles/sidebar.css +211 -131
- package/styles/{variables.css → sl-variables.css} +3 -2
- package/styles/stldocs-variables.css +6 -0
- package/styles/toc.css +41 -34
- package/theme.css +10 -10
- package/tsconfig.json +2 -5
- package/virtual-module.d.ts +121 -5
- package/components/variables.css +0 -135
- package/plugin/globalJs/ai-dropdown.ts +0 -57
- package/stl-docs/components/APIReferenceAIDropdown.tsx +0 -58
- package/stl-docs/components/content-panel/ProseAIDropdown.tsx +0 -55
- package/stl-docs/components/mintlify-compat/Step.astro +0 -58
- package/stl-docs/components/mintlify-compat/Steps.astro +0 -17
- /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
package/plugin/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import react from '@astrojs/react';
|
|
2
2
|
import type { StarlightPlugin } from '@astrojs/starlight/types';
|
|
3
|
-
import type { AstroIntegration } from 'astro';
|
|
3
|
+
import type { AstroIntegration, AstroIntegrationLogger } from 'astro';
|
|
4
|
+
import type { BundledTheme } from 'shiki';
|
|
4
5
|
import { config } from 'dotenv';
|
|
5
6
|
import getPort from 'get-port';
|
|
6
|
-
import { startDevServer } from './cms/server';
|
|
7
|
+
import { startDevServer, type SpecResp } from './cms/server';
|
|
7
8
|
import { buildAlgoliaIndex } from './buildAlgoliaIndex';
|
|
8
9
|
import {
|
|
9
10
|
getAPIReferencePlaceholderItemFromSidebarConfig,
|
|
@@ -21,13 +22,21 @@ import {
|
|
|
21
22
|
type SpecRetrieverConfig,
|
|
22
23
|
} from './loadPluginConfig';
|
|
23
24
|
import { buildVirtualModuleString } from '../shared/virtualModule';
|
|
25
|
+
import type * as StlStarlightVirtualModule from 'virtual:stl-starlight-virtual-module';
|
|
24
26
|
import path from 'path';
|
|
25
27
|
import fs from 'fs';
|
|
28
|
+
import { getSharedLogger } from '../shared/getSharedLogger';
|
|
29
|
+
import { resolveSrcFile } from '../resolveSrcFile';
|
|
30
|
+
import { mkdir, writeFile } from 'fs/promises';
|
|
31
|
+
import { fileURLToPath } from 'url';
|
|
32
|
+
import prebundleWorkers from 'vite-plugin-prebundle-workers';
|
|
26
33
|
|
|
27
34
|
export { generateAPILink } from './generateAPIReferenceLink';
|
|
28
35
|
export type { ReferenceSidebarConfigItem };
|
|
29
36
|
|
|
30
|
-
config(
|
|
37
|
+
config({
|
|
38
|
+
quiet: true,
|
|
39
|
+
});
|
|
31
40
|
|
|
32
41
|
let sidebarIdCounter = 0;
|
|
33
42
|
|
|
@@ -108,20 +117,25 @@ function tmpGetCMSServerConfig(specRetrieverConfig: SpecRetrieverConfig) {
|
|
|
108
117
|
|
|
109
118
|
async function stlStarlightAstroIntegration(
|
|
110
119
|
pluginConfig: NormalizedStainlessStarlightConfig,
|
|
120
|
+
stlStarlightPluginLogger: AstroIntegrationLogger,
|
|
111
121
|
): Promise<AstroIntegration> {
|
|
112
122
|
const virtualId = `virtual:stl-starlight-virtual-module`;
|
|
113
123
|
// The '\0' prefix tells Vite “this is a virtual module” and prevents it from being resolved again.
|
|
114
124
|
const resolvedId = `\0${virtualId}`;
|
|
125
|
+
let playgroundsBase: string | undefined;
|
|
126
|
+
let buildPlaygrounds;
|
|
127
|
+
let astroBase = '/';
|
|
115
128
|
|
|
116
129
|
const CMS_PORT = await getPort();
|
|
117
130
|
|
|
118
131
|
const { apiKey, version, devPaths } = tmpGetCMSServerConfig(pluginConfig.specRetrieverConfig);
|
|
119
132
|
|
|
120
|
-
const cmsServer =
|
|
133
|
+
const cmsServer = startDevServer({
|
|
121
134
|
port: CMS_PORT,
|
|
122
|
-
apiKey,
|
|
135
|
+
apiKey: apiKey.value,
|
|
123
136
|
version,
|
|
124
137
|
devPaths,
|
|
138
|
+
logger: stlStarlightPluginLogger,
|
|
125
139
|
getGeneratedSidebarConfig: (id: number) => {
|
|
126
140
|
const config = sidebarConfigs.get(id);
|
|
127
141
|
if (!config) {
|
|
@@ -131,50 +145,99 @@ async function stlStarlightAstroIntegration(
|
|
|
131
145
|
},
|
|
132
146
|
});
|
|
133
147
|
|
|
148
|
+
let building: Promise<void> | undefined;
|
|
149
|
+
let reportError: ((message: string) => void) | null = null;
|
|
150
|
+
let collectedErrors: string[] | null = null;
|
|
151
|
+
|
|
152
|
+
function startPlaygroundsBuild(playgroundsCachePath: string) {
|
|
153
|
+
if (!pluginConfig.experimentalPlaygrounds) return;
|
|
154
|
+
if (building) return building;
|
|
155
|
+
return (building = (async () => {
|
|
156
|
+
const { data: spec, auth } = (await (
|
|
157
|
+
await fetch(`http://localhost:${CMS_PORT}/retrieve_spec`, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
body: JSON.stringify({}),
|
|
160
|
+
})
|
|
161
|
+
).json()) as SpecResp;
|
|
162
|
+
if (!spec || !auth) throw new Error('expected spec');
|
|
163
|
+
|
|
164
|
+
const langs = (spec.docs?.languages ?? ['http'])
|
|
165
|
+
.filter((lang) => lang !== 'terraform')
|
|
166
|
+
.filter((lang) => !pluginConfig.excludeLanguages?.includes(lang));
|
|
167
|
+
|
|
168
|
+
await buildPlaygrounds!({
|
|
169
|
+
spec,
|
|
170
|
+
langs,
|
|
171
|
+
auth,
|
|
172
|
+
playPath: playgroundsCachePath,
|
|
173
|
+
reportError(message: string) {
|
|
174
|
+
(reportError ?? console.error)(message);
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
})());
|
|
178
|
+
}
|
|
179
|
+
|
|
134
180
|
return {
|
|
135
181
|
name: 'stl-starlight-astro',
|
|
136
182
|
hooks: {
|
|
137
|
-
'astro:config:setup': async ({
|
|
183
|
+
'astro:config:setup': async ({
|
|
184
|
+
injectRoute,
|
|
185
|
+
updateConfig,
|
|
186
|
+
logger: localLogger,
|
|
187
|
+
command,
|
|
188
|
+
config: astroConfig,
|
|
189
|
+
}) => {
|
|
190
|
+
const logger = getSharedLogger({ fallback: localLogger });
|
|
138
191
|
const projectDir = astroConfig.root.pathname;
|
|
192
|
+
astroBase = astroConfig.base;
|
|
193
|
+
|
|
194
|
+
reportError = (message: string) => logger.error(message);
|
|
195
|
+
|
|
196
|
+
if (pluginConfig.experimentalPlaygrounds) {
|
|
197
|
+
playgroundsBase = pluginConfig.experimentalPlaygrounds.playgroundsBase;
|
|
198
|
+
}
|
|
139
199
|
|
|
140
200
|
const middlewareFile = path.join(projectDir, 'middleware.stainless.ts');
|
|
141
201
|
|
|
142
202
|
let vmMiddlewareExport = 'export const MIDDLEWARE = {};';
|
|
143
203
|
if (fs.existsSync(middlewareFile)) {
|
|
144
|
-
logger.
|
|
204
|
+
logger.debug(`Loading middleware from ${middlewareFile}`);
|
|
145
205
|
vmMiddlewareExport = `export { default as MIDDLEWARE } from '${middlewareFile}';`;
|
|
146
206
|
}
|
|
147
207
|
|
|
148
208
|
injectRoute({
|
|
149
|
-
pattern: `${pluginConfig.basePath}/[...slug].md`,
|
|
150
|
-
entrypoint: '
|
|
209
|
+
pattern: `${pluginConfig.basePath}/[...slug]/index.md`,
|
|
210
|
+
entrypoint: resolveSrcFile('/plugin/routes/markdown.ts'),
|
|
151
211
|
prerender: command === 'build',
|
|
152
212
|
});
|
|
153
213
|
|
|
154
|
-
const astroFile = command === 'build' ? '
|
|
214
|
+
const astroFile = command === 'build' ? 'DocsStatic' : 'Docs';
|
|
155
215
|
injectRoute({
|
|
156
216
|
pattern: `${pluginConfig.basePath}/[...slug]`,
|
|
157
|
-
|
|
158
|
-
entrypoint: `@stainless-api/docs/${astroFile}`,
|
|
217
|
+
entrypoint: resolveSrcFile(`/plugin/routes/${astroFile}.astro`),
|
|
159
218
|
prerender: command === 'build',
|
|
160
219
|
});
|
|
161
220
|
|
|
162
221
|
injectRoute({
|
|
163
222
|
pattern: pluginConfig.basePath,
|
|
164
|
-
entrypoint: '
|
|
223
|
+
entrypoint: resolveSrcFile('/plugin/routes/Overview.astro'),
|
|
165
224
|
prerender: command === 'build',
|
|
166
225
|
});
|
|
167
226
|
|
|
168
227
|
updateConfig({
|
|
169
228
|
vite: {
|
|
170
|
-
ssr: {
|
|
171
|
-
noExternal: ['@stainless-api/ui-primitives'],
|
|
172
|
-
},
|
|
173
|
-
optimizeDeps: { include: ['@stainless-api/ui-primitives'] },
|
|
174
229
|
plugins: [
|
|
175
230
|
{
|
|
176
231
|
name: 'stl-starlight-vite',
|
|
177
|
-
|
|
232
|
+
buildStart() {
|
|
233
|
+
building = undefined;
|
|
234
|
+
},
|
|
235
|
+
async configureServer(server) {
|
|
236
|
+
if (playgroundsBase) {
|
|
237
|
+
buildPlaygrounds = (await server.ssrLoadModule(playgroundsBase + '/src/build.ts'))
|
|
238
|
+
.buildPlaygrounds;
|
|
239
|
+
}
|
|
240
|
+
|
|
178
241
|
for (const filePath of Object.values(devPaths)) {
|
|
179
242
|
if (!filePath) {
|
|
180
243
|
continue;
|
|
@@ -197,28 +260,82 @@ async function stlStarlightAstroIntegration(
|
|
|
197
260
|
if (id === virtualId) {
|
|
198
261
|
return resolvedId;
|
|
199
262
|
}
|
|
263
|
+
if (id === 'virtual:stl-playground/unstable-update-language') {
|
|
264
|
+
return resolveSrcFile('plugin/languages.ts');
|
|
265
|
+
}
|
|
266
|
+
if (id === 'virtual:stl-playground/create') {
|
|
267
|
+
return fileURLToPath(
|
|
268
|
+
new URL(
|
|
269
|
+
pluginConfig.experimentalPlaygrounds
|
|
270
|
+
? path.join(playgroundsBase!, '/src/create.tsx')
|
|
271
|
+
: './globalJs/create-playground.shim.ts',
|
|
272
|
+
import.meta.url,
|
|
273
|
+
),
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
if (id === 'virtual:stl-playground/data') {
|
|
277
|
+
return fileURLToPath(
|
|
278
|
+
new URL(
|
|
279
|
+
pluginConfig.experimentalPlaygrounds
|
|
280
|
+
? './globalJs/playground-data.ts'
|
|
281
|
+
: './globalJs/playground-data.shim.ts',
|
|
282
|
+
import.meta.url,
|
|
283
|
+
),
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (id.startsWith('virtual:stl-playground/')) {
|
|
287
|
+
const result = path.join(
|
|
288
|
+
this.environment.getTopLevelConfig().cacheDir,
|
|
289
|
+
'stl-playground',
|
|
290
|
+
id.slice('virtual:stl-playground/'.length),
|
|
291
|
+
);
|
|
292
|
+
const config = this.environment.getTopLevelConfig();
|
|
293
|
+
return startPlaygroundsBuild(path.join(config.cacheDir, 'stl-playground'))?.then(
|
|
294
|
+
() => result,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
200
297
|
},
|
|
201
298
|
load(id) {
|
|
202
299
|
if (id === resolvedId) {
|
|
203
300
|
return [
|
|
204
301
|
buildVirtualModuleString({
|
|
205
|
-
BASE_PATH: pluginConfig.basePath,
|
|
302
|
+
BASE_PATH: path.posix.join(astroConfig.base, pluginConfig.basePath),
|
|
206
303
|
CMS_PORT,
|
|
207
|
-
EXCLUDE_LANGUAGES: pluginConfig.excludeLanguages,
|
|
304
|
+
EXCLUDE_LANGUAGES: ['php', ...pluginConfig.excludeLanguages],
|
|
208
305
|
DEFAULT_LANGUAGE: pluginConfig.defaultLanguage,
|
|
209
306
|
BREADCRUMB_CONFIG: pluginConfig.breadcrumbs,
|
|
210
307
|
EXPAND_RESOURCES: pluginConfig.expandResources,
|
|
211
308
|
HIGHLIGHT_THEMES: pluginConfig.highlighting.themes,
|
|
212
309
|
CONTENT_PANEL_LAYOUT: pluginConfig.contentPanel.layout,
|
|
213
310
|
EXPERIMENTAL_COLLAPSIBLE_SNIPPETS: pluginConfig.experimentalCollapsibleSnippets,
|
|
311
|
+
EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS:
|
|
312
|
+
pluginConfig.experimentalCollapsibleMethodDescriptions,
|
|
214
313
|
PROPERTY_SETTINGS: pluginConfig.propertySettings,
|
|
215
|
-
|
|
216
|
-
|
|
314
|
+
ENABLE_CONTEXT_MENU: pluginConfig.contextMenu,
|
|
315
|
+
EXPERIMENTAL_PLAYGROUNDS: !!pluginConfig.experimentalPlaygrounds,
|
|
316
|
+
EXPERIMENTAL_REQUEST_BUILDER: pluginConfig.experimentalRequestBuilder,
|
|
317
|
+
STAINLESS_PROJECT: version.stainlessProject,
|
|
318
|
+
} satisfies Omit<typeof StlStarlightVirtualModule, 'MIDDLEWARE'>),
|
|
217
319
|
vmMiddlewareExport,
|
|
218
320
|
].join('\n');
|
|
219
321
|
}
|
|
220
322
|
},
|
|
221
323
|
},
|
|
324
|
+
prebundleWorkers({
|
|
325
|
+
include: [
|
|
326
|
+
'**/typescript/runner*',
|
|
327
|
+
'**/typescript/worker*',
|
|
328
|
+
'**/pyright.worker*',
|
|
329
|
+
'**/python/pyodide*',
|
|
330
|
+
],
|
|
331
|
+
configureEsBuild(_, opts) {
|
|
332
|
+
opts.external ??= [];
|
|
333
|
+
opts.external.push('url');
|
|
334
|
+
opts.loader ??= {};
|
|
335
|
+
opts.loader['.wasm'] = 'dataurl';
|
|
336
|
+
return opts;
|
|
337
|
+
},
|
|
338
|
+
}),
|
|
222
339
|
],
|
|
223
340
|
},
|
|
224
341
|
});
|
|
@@ -226,6 +343,29 @@ async function stlStarlightAstroIntegration(
|
|
|
226
343
|
'astro:server:done': async () => {
|
|
227
344
|
await cmsServer.destroy();
|
|
228
345
|
},
|
|
346
|
+
'astro:build:start'({ logger }) {
|
|
347
|
+
collectedErrors = [];
|
|
348
|
+
reportError = (message: string) => {
|
|
349
|
+
logger.error(message);
|
|
350
|
+
collectedErrors!.push(message);
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
'astro:build:done': async ({ dir, logger }) => {
|
|
354
|
+
const dist = fileURLToPath(dir);
|
|
355
|
+
const stainlessDir = path.join(dist, '_stainless');
|
|
356
|
+
await mkdir(stainlessDir, { recursive: true });
|
|
357
|
+
if (collectedErrors) {
|
|
358
|
+
for (const error of collectedErrors) {
|
|
359
|
+
logger.error(error);
|
|
360
|
+
}
|
|
361
|
+
collectedErrors = null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const manifest = {
|
|
365
|
+
astroBase,
|
|
366
|
+
};
|
|
367
|
+
await writeFile(path.join(stainlessDir, 'stl-manifest.json'), JSON.stringify(manifest, null, 2));
|
|
368
|
+
},
|
|
229
369
|
},
|
|
230
370
|
};
|
|
231
371
|
}
|
|
@@ -241,15 +381,20 @@ export function stainlessStarlight(someUserConfig: SomeStainlessStarlightUserCon
|
|
|
241
381
|
command,
|
|
242
382
|
config: starlightConfig,
|
|
243
383
|
astroConfig,
|
|
244
|
-
logger,
|
|
384
|
+
logger: localLogger,
|
|
245
385
|
}) => {
|
|
246
386
|
if (command !== 'build' && command !== 'dev') {
|
|
247
387
|
return;
|
|
248
388
|
}
|
|
249
389
|
|
|
390
|
+
const logger = getSharedLogger({ fallback: localLogger });
|
|
391
|
+
|
|
250
392
|
const configParseResult = parseStarlightPluginConfig(someUserConfig, command);
|
|
251
393
|
if (configParseResult.result === 'error') {
|
|
252
|
-
|
|
394
|
+
const errorLines = configParseResult.message.split('\n');
|
|
395
|
+
for (const line of errorLines) {
|
|
396
|
+
logger.error(line);
|
|
397
|
+
}
|
|
253
398
|
process.exit(1);
|
|
254
399
|
}
|
|
255
400
|
const config = configParseResult.config;
|
|
@@ -260,17 +405,30 @@ export function stainlessStarlight(someUserConfig: SomeStainlessStarlightUserCon
|
|
|
260
405
|
addIntegration(react());
|
|
261
406
|
}
|
|
262
407
|
|
|
408
|
+
if ('apiKey' in config.specRetrieverConfig) {
|
|
409
|
+
if (!config.specRetrieverConfig.apiKey) {
|
|
410
|
+
logger.info(`Stainless credentials not loaded`);
|
|
411
|
+
} else if (config.specRetrieverConfig.apiKey.source === 'explicit-config') {
|
|
412
|
+
logger.info(`Stainless credentials loaded from user config`);
|
|
413
|
+
} else if (config.specRetrieverConfig.apiKey.source === 'environment-variable') {
|
|
414
|
+
logger.info('Stainless credentials loaded from `STAINLESS_API_KEY` environment variable');
|
|
415
|
+
} else if (config.specRetrieverConfig.apiKey.source === 'cli') {
|
|
416
|
+
logger.info('Stainless credentials loaded from `stl` CLI');
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
263
420
|
if (
|
|
264
421
|
command === 'build' &&
|
|
265
422
|
config.specRetrieverConfig.kind === 'local_spec_server_with_remote_files'
|
|
266
423
|
) {
|
|
267
424
|
await buildAlgoliaIndex({
|
|
268
425
|
version: config.specRetrieverConfig.version,
|
|
269
|
-
apiKey: config.specRetrieverConfig.apiKey,
|
|
426
|
+
apiKey: config.specRetrieverConfig.apiKey.value,
|
|
427
|
+
logger,
|
|
270
428
|
});
|
|
271
429
|
}
|
|
272
430
|
|
|
273
|
-
addIntegration(await stlStarlightAstroIntegration(config));
|
|
431
|
+
addIntegration(await stlStarlightAstroIntegration(config, logger));
|
|
274
432
|
|
|
275
433
|
if (starlightConfig.sidebar) {
|
|
276
434
|
// for pagination (https://starlight.astro.build/reference/configuration/#pagination) to work correctly
|
|
@@ -281,21 +439,25 @@ export function stainlessStarlight(someUserConfig: SomeStainlessStarlightUserCon
|
|
|
281
439
|
}
|
|
282
440
|
}
|
|
283
441
|
|
|
284
|
-
const
|
|
442
|
+
const expressiveCodeConfig =
|
|
285
443
|
typeof starlightConfig.expressiveCode === 'object' ? starlightConfig.expressiveCode : {};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
},
|
|
291
|
-
});
|
|
444
|
+
|
|
445
|
+
const themes = expressiveCodeConfig.themes
|
|
446
|
+
? (expressiveCodeConfig.themes as BundledTheme[])
|
|
447
|
+
: (['github-light', 'github-dark'] as BundledTheme[]);
|
|
292
448
|
|
|
293
449
|
updateConfig({
|
|
294
450
|
sidebar: starlightConfig.sidebar,
|
|
451
|
+
...(expressiveCodeConfig && {
|
|
452
|
+
expressiveCode: {
|
|
453
|
+
...expressiveCodeConfig,
|
|
454
|
+
themes,
|
|
455
|
+
},
|
|
456
|
+
}),
|
|
295
457
|
});
|
|
296
458
|
|
|
297
459
|
addRouteMiddleware({
|
|
298
|
-
entrypoint: '
|
|
460
|
+
entrypoint: resolveSrcFile('/plugin/replaceSidebarPlaceholderMiddleware.ts'),
|
|
299
461
|
order: 'post',
|
|
300
462
|
});
|
|
301
463
|
},
|
|
@@ -304,5 +466,5 @@ export function stainlessStarlight(someUserConfig: SomeStainlessStarlightUserCon
|
|
|
304
466
|
}
|
|
305
467
|
|
|
306
468
|
// Additional exports we want for Stainless <-> docs integration.
|
|
307
|
-
export { parseStainlessPath } from '@stainless-api/docs-ui/
|
|
308
|
-
export { renderMarkdown } from '@stainless-api/docs-ui/
|
|
469
|
+
export { parseStainlessPath } from '@stainless-api/docs-ui/routing';
|
|
470
|
+
export { renderMarkdown } from '@stainless-api/docs-ui/markdown';
|
package/plugin/languages.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocsLanguage } from '@stainless-api/docs-ui/
|
|
1
|
+
import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
2
2
|
import KotlinIcon from './assets/languages/kotlin.svg';
|
|
3
3
|
import RubyIcon from './assets/languages/ruby.svg';
|
|
4
4
|
import TerraformIcon from './assets/languages/terraform.svg';
|
|
@@ -7,6 +7,8 @@ import PythonIcon from './assets/languages/python.svg';
|
|
|
7
7
|
import JavaIcon from './assets/languages/java.svg';
|
|
8
8
|
import GoIcon from './assets/languages/go.svg';
|
|
9
9
|
import CurlIcon from './assets/languages/curl.svg';
|
|
10
|
+
import CSharpIcon from './assets/languages/csharp.svg';
|
|
11
|
+
import CLIIcon from './assets/languages/cli.svg';
|
|
10
12
|
|
|
11
13
|
export const Languages: Record<
|
|
12
14
|
DocsLanguage,
|
|
@@ -29,6 +31,9 @@ export const Languages: Record<
|
|
|
29
31
|
http: { name: 'HTTP', icon: CurlIcon, alt: 'HTTP logo' },
|
|
30
32
|
terraform: { name: 'Terraform', icon: TerraformIcon, alt: 'Terraform logo' },
|
|
31
33
|
ruby: { name: 'Ruby', icon: RubyIcon, alt: 'Ruby logo' },
|
|
34
|
+
csharp: { name: 'C#', icon: CSharpIcon, alt: 'C# logo' },
|
|
35
|
+
cli: { name: 'CLI Tool', icon: CLIIcon, alt: 'CLI logo' },
|
|
36
|
+
php: { name: 'PHP', icon: CSharpIcon, alt: 'PHP logo' }, // TODO update PHP icon
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
export function generatePrefix(basePath: string, language: string) {
|
|
@@ -44,7 +49,7 @@ export function applyLanguageToLinks(basePath?: string, defaultLanguage?: string
|
|
|
44
49
|
`[data-stldocs-overview],[data-stldocs-method],a.nav-link[href^='${basePath}']`,
|
|
45
50
|
);
|
|
46
51
|
|
|
47
|
-
for (
|
|
52
|
+
for (const link of links) {
|
|
48
53
|
const href = link.getAttribute('href');
|
|
49
54
|
const prefix = generatePrefix(basePath, language);
|
|
50
55
|
if (href?.startsWith(basePath) && !href?.startsWith(prefix)) {
|