mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Docs now run in development with pnpm run dev
This commit is contained in:
parent
07920a4102
commit
3f40f60e43
20
.github/workflows/preview-docs.yaml
vendored
20
.github/workflows/preview-docs.yaml
vendored
@ -26,10 +26,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
- name: Setup Node.js v20
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
node-version: 20
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v3
|
||||
@ -42,29 +42,21 @@ jobs:
|
||||
- name: Build
|
||||
run: pnpm build
|
||||
|
||||
- name: Generate docs
|
||||
run: pnpm generate-docs
|
||||
|
||||
- name: Install Fern
|
||||
run: npm install -g fern-api
|
||||
|
||||
- name: Check API is valid
|
||||
run: fern check
|
||||
working-directory: ./docs
|
||||
run: pnpm run fern check
|
||||
|
||||
- name: Generate preview URL
|
||||
id: generate-docs
|
||||
env:
|
||||
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
|
||||
run: |
|
||||
OUTPUT=$(fern generate --docs --preview 2>&1) || true
|
||||
OUTPUT=$(pnpm run fern generate --docs --preview 2>&1) || true
|
||||
echo "$OUTPUT"
|
||||
URL=$(echo "$OUTPUT" | grep -oP 'Published docs to \K.*(?= \()')
|
||||
echo "Preview URL: $URL"
|
||||
echo "🌿 Preview your docs: $URL" > preview_url.txt
|
||||
working-directory: ./docs
|
||||
echo "🌿 Preview your docs: $URL" > docs_preview_url.untracked.txt
|
||||
|
||||
- name: Comment URL in PR
|
||||
uses: thollander/actions-comment-pull-request@v2.4.3
|
||||
with:
|
||||
filePath: docs/preview_url.txt
|
||||
filePath: docs_preview_url.untracked.txt
|
||||
|
||||
14
.github/workflows/publish-docs.yaml
vendored
14
.github/workflows/publish-docs.yaml
vendored
@ -29,10 +29,10 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
- name: Setup Node.js v20
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
node-version: 20
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v3
|
||||
@ -45,14 +45,10 @@ jobs:
|
||||
- name: Build
|
||||
run: pnpm build
|
||||
|
||||
- name: Generate docs
|
||||
run: pnpm generate-docs
|
||||
|
||||
- name: Install Fern
|
||||
run: npm install -g fern-api
|
||||
- name: Check API is valid
|
||||
run: pnpm run fern check
|
||||
|
||||
- name: Publish Docs
|
||||
env:
|
||||
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
|
||||
run: fern generate --docs --log-level debug
|
||||
working-directory: ./docs
|
||||
run: pnpm run fern generate --docs --log-level debug
|
||||
|
||||
7
docs/LICENSE
Normal file
7
docs/LICENSE
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2024 Stackframe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
15
docs/package.json
Normal file
15
docs/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@stackframe/docs",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "pnpm run fern docs dev --port 8104",
|
||||
"fern": "fern"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"dependencies": {
|
||||
"fern-api": "^0.30.7"
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,7 @@
|
||||
"codegen": "only-allow pnpm && turbo run codegen --no-cache",
|
||||
"psql:server": "only-allow pnpm && pnpm run --filter=@stackframe/stack-server psql",
|
||||
"prisma:server": "only-allow pnpm && pnpm run --filter=@stackframe/stack-server prisma",
|
||||
"fern": "only-allow pnpm && pnpm run --filter=@stackframe/docs fern",
|
||||
"dev": "only-allow pnpm && turbo run dev --parallel --continue",
|
||||
"dev:app": "only-allow pnpm && turbo run dev --continue --filter=@stackframe/dev-app...",
|
||||
"dev:server": "only-allow pnpm && turbo run dev --continue --filter=@stackframe/stack-server...",
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
"build": "npm run codegen && next build",
|
||||
"analyze-bundle": "ANALYZE_BUNDLE=1 npm run build",
|
||||
"start": "next start --port 8101",
|
||||
"codegen": "npm run prisma -- generate",
|
||||
"codegen": "npm run prisma -- generate && npm run generate-docs",
|
||||
"psql": "npm run with-env -- bash -c 'psql $DATABASE_CONNECTION_STRING'",
|
||||
"prisma": "npm run with-env -- prisma",
|
||||
"lint": "next lint",
|
||||
|
||||
@ -4,21 +4,30 @@ import { parseOpenAPI } from '@/lib/openapi';
|
||||
import yaml from 'yaml';
|
||||
import fs from 'fs';
|
||||
|
||||
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"];
|
||||
|
||||
for (const audience of ['client', 'server'] as const) {
|
||||
const openAPISchema = yaml.stringify(parseOpenAPI({
|
||||
endpointOptions: [
|
||||
{
|
||||
handler: usersCrudHandlers.listHandler,
|
||||
handlers: [usersCrudHandlers.listHandler],
|
||||
path: '/users',
|
||||
tags: ['Users'],
|
||||
},
|
||||
{
|
||||
handler: usersCrudHandlers,
|
||||
handlers: [
|
||||
usersCrudHandlers.readHandler,
|
||||
usersCrudHandlers.updateHandler,
|
||||
usersCrudHandlers.deleteHandler,
|
||||
],
|
||||
path: '/users/{userId}',
|
||||
tags: ['Users'],
|
||||
},
|
||||
{
|
||||
handler: currentUserCrudHandlers,
|
||||
handlers: [
|
||||
currentUserCrudHandlers.readHandler,
|
||||
currentUserCrudHandlers.updateHandler,
|
||||
],
|
||||
path: '/current-user',
|
||||
tags: ['Users'],
|
||||
}
|
||||
@ -27,4 +36,6 @@ for (const audience of ['client', 'server'] as const) {
|
||||
}));
|
||||
|
||||
fs.writeFileSync(`../../docs/fern/openapi/${audience}.yaml`, openAPISchema);
|
||||
}
|
||||
|
||||
console.log("Successfully updated OpenAPI schema");
|
||||
}
|
||||
|
||||
@ -3,8 +3,8 @@ import { RouteHandler } from '@/route-handlers/smart-route-handler';
|
||||
import { randomInt } from 'crypto';
|
||||
import * as yup from 'yup';
|
||||
|
||||
function isRouteHandler(handlers: any): handlers is CrudHandlers<any> {
|
||||
return handlers.schemas !== undefined;
|
||||
function isRouteHandler(handler: object): handler is RouteHandler {
|
||||
return "isSmartRouteHandler" in handler;
|
||||
}
|
||||
|
||||
function crudHandlerToArray(crudHandler: any) {
|
||||
@ -17,7 +17,7 @@ function crudHandlerToArray(crudHandler: any) {
|
||||
}
|
||||
|
||||
type EndpointOption = {
|
||||
handler: RouteHandler | CrudHandlers<any>,
|
||||
handlers: RouteHandler[],
|
||||
path: string,
|
||||
tags?: string[],
|
||||
};
|
||||
@ -40,8 +40,7 @@ export function parseOpenAPI(options: {
|
||||
};
|
||||
|
||||
for (const endpoint of options.endpointOptions) {
|
||||
|
||||
const handlers = isRouteHandler(endpoint.handler) ? [endpoint.handler] : crudHandlerToArray(endpoint.handler);
|
||||
const handlers = endpoint.handlers;
|
||||
for (const handler of handlers) {
|
||||
const parsed = parseRouteHandler({ handler, audience: options.audience, tags: endpoint.tags, path: endpoint.path });
|
||||
result.paths[endpoint.path] = { ...result.paths[endpoint.path], ...parsed };
|
||||
@ -243,4 +242,4 @@ export function parseSchema(options: {
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,6 +135,7 @@ export type RouteHandlerMetadata = {
|
||||
export type RouteHandlerSchemaMap = Map<string, { metadata?: RouteHandlerMetadata, request: yup.Schema, response: yup.Schema }>;
|
||||
|
||||
export type RouteHandler = ((req: NextRequest, options: any) => Promise<Response>) & {
|
||||
isSmartRouteHandler: boolean,
|
||||
schemas: RouteHandlerSchemaMap,
|
||||
}
|
||||
|
||||
@ -192,6 +193,7 @@ export function smartRouteHandler<
|
||||
|
||||
return await createResponse(req, requestId, smartRes, handler.response);
|
||||
}), {
|
||||
isSmartRouteHandler: true,
|
||||
schemas: overloadParams.reduce((acc: RouteHandlerSchemaMap, overloadParam) => {
|
||||
const handler = overloadGenerator(overloadParam);
|
||||
acc.set(overloadParam as string, {
|
||||
|
||||
@ -309,6 +309,12 @@ importers:
|
||||
specifier: ^5
|
||||
version: 5.3.3
|
||||
|
||||
docs:
|
||||
dependencies:
|
||||
fern-api:
|
||||
specifier: ^0.30.7
|
||||
version: 0.30.7
|
||||
|
||||
packages/init-stack:
|
||||
dependencies:
|
||||
inquirer:
|
||||
@ -4538,6 +4544,10 @@ packages:
|
||||
fastq@1.17.1:
|
||||
resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==}
|
||||
|
||||
fern-api@0.30.7:
|
||||
resolution: {integrity: sha512-gMmZkT9p2rIn+RavmpCOEWH3qGB+ppi0FcXIdlAVFO0pQ3Fj0aSJPniGvLx9XgqrAgadUStmMTjcrvGIc9ohpA==}
|
||||
hasBin: true
|
||||
|
||||
fflate@0.4.8:
|
||||
resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==}
|
||||
|
||||
@ -12605,6 +12615,8 @@ snapshots:
|
||||
dependencies:
|
||||
reusify: 1.0.4
|
||||
|
||||
fern-api@0.30.7: {}
|
||||
|
||||
fflate@0.4.8: {}
|
||||
|
||||
file-entry-cache@6.0.1:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user