Skip to content

Commit

Permalink
fix: make api urls optional in the generate scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviareichl committed Sep 30, 2024
1 parent 2b7e895 commit 50ac400
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions scripts/generate-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";

import { log } from "@acdh-oeaw/lib";
import { assert, log } from "@acdh-oeaw/lib";
import openapi, { astToString } from "openapi-typescript";
import * as v from "valibot";

const schema = v.object({
NUXT_PUBLIC_DATABASE: v.optional(v.picklist(["enabled", "disabled"]), "enabled"),
NUXT_PUBLIC_OPENAPI_BASE_URL: v.pipe(v.string(), v.url()),
NUXT_PUBLIC_OPENAPI_BASE_URL: v.optional(v.pipe(v.string(), v.url())),
});

async function generate() {
Expand All @@ -29,6 +29,8 @@ async function generate() {

const url = result.output.NUXT_PUBLIC_OPENAPI_BASE_URL;

assert(url, "NUXT_PUBLIC_OPENAPI_BASE_URL environment variable not provided.");

const ast = await openapi(url, {
arrayLength: true,
});
Expand Down
6 changes: 4 additions & 2 deletions scripts/generate-crm-locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import * as v from "valibot";

import { log } from "@acdh-oeaw/lib";
import { assert, log } from "@acdh-oeaw/lib";
import createApiClient from "@stefanprobst/openapi-client";

import { defaultLocale, locales } from "@/config/i18n.config";
import type { paths } from "@/lib/api-client/api";

const schema = v.object({
NUXT_PUBLIC_DATABASE: v.optional(v.picklist(["enabled", "disabled"]), "enabled"),
NUXT_PUBLIC_API_BASE_URL: v.pipe(v.string(), v.url()),
NUXT_PUBLIC_API_BASE_URL: v.optional(v.pipe(v.string(), v.url())),
});

interface Translations {
Expand Down Expand Up @@ -135,6 +135,8 @@ async function generate(locale = defaultLocale) {
return false;
}

assert(baseUrl, "NUXT_PUBLIC_API_BASE_URL environment variable not provided.");

log.info(`Generating crm messages for locale: "${locale}" from url: ${baseUrl} ...`);
const apiClient = createApiClient<paths>({ baseUrl });

Expand Down

0 comments on commit 50ac400

Please sign in to comment.