Fix/apiDocsBuild (#989)
* copy api json to docs * copy api json to docs * improvements * fix web build * mjs > js
This commit is contained in:
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -62,6 +62,8 @@ jobs:
|
|||||||
VERSION: ${{ needs.publish.outputs.version }}
|
VERSION: ${{ needs.publish.outputs.version }}
|
||||||
run: |
|
run: |
|
||||||
docker buildx build db/ --no-cache -t flomp/wanderer-db:$VERSION -t flomp/wanderer-db:latest --platform=linux/amd64,linux/arm64 --push
|
docker buildx build db/ --no-cache -t flomp/wanderer-db:$VERSION -t flomp/wanderer-db:latest --platform=linux/amd64,linux/arm64 --push
|
||||||
|
npm --prefix web ci
|
||||||
|
npm --prefix web run openapi:generate
|
||||||
docker buildx build web/ --no-cache -t flomp/wanderer-web:$VERSION -t flomp/wanderer-web:latest --platform=linux/amd64,linux/arm64 --push
|
docker buildx build web/ --no-cache -t flomp/wanderer-web:$VERSION -t flomp/wanderer-web:latest --platform=linux/amd64,linux/arm64 --push
|
||||||
npm --prefix docs ci
|
npm --prefix docs ci
|
||||||
npm --prefix docs run build
|
npm --prefix docs run build
|
||||||
|
|||||||
3
docs/.gitignore
vendored
3
docs/.gitignore
vendored
@@ -3,6 +3,9 @@ dist/
|
|||||||
# generated types
|
# generated types
|
||||||
.astro/
|
.astro/
|
||||||
|
|
||||||
|
# generated OpenAPI schema
|
||||||
|
wanderer.openapi.json
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "astro dev",
|
"dev": "astro dev",
|
||||||
"start": "astro dev",
|
"start": "astro dev",
|
||||||
"build": "astro check && astro build",
|
"sync-openapi": "node scripts/sync-openapi.js",
|
||||||
|
"build": "npm run sync-openapi && astro check && astro build",
|
||||||
"preview": "astro preview",
|
"preview": "astro preview",
|
||||||
"astro": "astro"
|
"astro": "astro"
|
||||||
},
|
},
|
||||||
|
|||||||
18
docs/scripts/sync-openapi.js
Normal file
18
docs/scripts/sync-openapi.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { copyFileSync, existsSync } from 'node:fs';
|
||||||
|
import { dirname, resolve } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const docsDir = resolve(scriptDir, '..');
|
||||||
|
const repoDir = resolve(docsDir, '..');
|
||||||
|
|
||||||
|
const source = resolve(repoDir, 'web/static/docs/api/wanderer.openapi.json');
|
||||||
|
const destination = resolve(docsDir, 'wanderer.openapi.json');
|
||||||
|
|
||||||
|
if (!existsSync(source)) {
|
||||||
|
console.error(`OpenAPI schema not found at ${source}. Run the web build first so it can be generated.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
copyFileSync(source, destination);
|
||||||
|
console.log(`Synced OpenAPI schema to ${destination}`);
|
||||||
File diff suppressed because it is too large
Load Diff
1
web/.gitignore
vendored
1
web/.gitignore
vendored
@@ -3,6 +3,7 @@ node_modules
|
|||||||
/build
|
/build
|
||||||
/.svelte-kit
|
/.svelte-kit
|
||||||
/package
|
/package
|
||||||
|
static/docs/api/wanderer.openapi.json
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|||||||
12
web/openapi.config.js
Normal file
12
web/openapi.config.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export function openapiOptions(version) {
|
||||||
|
return {
|
||||||
|
info: {
|
||||||
|
title: 'Wanderer API',
|
||||||
|
version,
|
||||||
|
description: 'API documentation for wanderer backend',
|
||||||
|
},
|
||||||
|
outputPath: 'static/docs/api/wanderer.openapi.json',
|
||||||
|
include: ['src/routes/api/v1/**/*.{js,ts}'],
|
||||||
|
baseSchemasPath: 'src/lib/models/api/openapi_schemas.ts',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"openapi:generate": "node scripts/generate-openapi.js",
|
||||||
"start": "node watcher.js & node build",
|
"start": "node watcher.js & node build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"test": "npm run test:integration && npm run test:unit",
|
"test": "npm run test:integration && npm run test:unit",
|
||||||
|
|||||||
18
web/scripts/generate-openapi.js
Normal file
18
web/scripts/generate-openapi.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { dirname, resolve } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
import { generateSpec, writeSpec } from '../node_modules/sveltekit-openapi-generator/dist/generator.js';
|
||||||
|
import { openapiOptions } from '../openapi.config.js';
|
||||||
|
|
||||||
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const webDir = resolve(scriptDir, '..');
|
||||||
|
const packageJson = JSON.parse(readFileSync(resolve(webDir, 'package.json'), 'utf-8'));
|
||||||
|
const { outputPath, ...generatorOptions } = openapiOptions(packageJson.version);
|
||||||
|
|
||||||
|
const spec = generateSpec({
|
||||||
|
rootDir: webDir,
|
||||||
|
...generatorOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
writeSpec(spec, resolve(webDir, outputPath));
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -4,20 +4,12 @@ import tailwindcss from '@tailwindcss/vite';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import openapiPlugin from 'sveltekit-openapi-generator';
|
import openapiPlugin from 'sveltekit-openapi-generator';
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
import { openapiOptions } from './openapi.config.js';
|
||||||
|
|
||||||
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
|
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [enhancedImages(), openapiPlugin({
|
plugins: [enhancedImages(), openapiPlugin(openapiOptions(packageJson.version)), tailwindcss(), sveltekit()],
|
||||||
info: {
|
|
||||||
title: 'Wanderer API',
|
|
||||||
version: `${packageJson.version}`,
|
|
||||||
description: 'API documentation for wanderer backend',
|
|
||||||
},
|
|
||||||
outputPath: 'static/docs/api/wanderer.openapi.json',
|
|
||||||
include: ['src/routes/api/v1/**/*.{js,ts}'],
|
|
||||||
baseSchemasPath: 'src/lib/models/api/openapi_schemas.ts',
|
|
||||||
}), tailwindcss(), sveltekit()],
|
|
||||||
test: { include: ['src/**/*.{test,spec}.{js,ts}'] },
|
test: { include: ['src/**/*.{test,spec}.{js,ts}'] },
|
||||||
ssr: { noExternal: ['three'] },
|
ssr: { noExternal: ['three'] },
|
||||||
...(process.env.WANDERER_ENV == "dev" ? {
|
...(process.env.WANDERER_ENV == "dev" ? {
|
||||||
|
|||||||
Reference in New Issue
Block a user