Skip to content

Commit

Permalink
Merge pull request #24 from narthur/codegen
Browse files Browse the repository at this point in the history
prevent missing config from breaking installs
  • Loading branch information
narthur committed Apr 11, 2024
2 parents a293b04 + 8341524 commit d2972f5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname);
export default async function main(): Promise<void> {
const config = getConfig();

if (
!config.databaseToken ||
!config.config ||
!config.outDir ||
!config.tables
) {
console.error("Missing required configuration options");
return;
}

console.dir(config);

const outDir = path.join(path.dirname(config.config), config.outDir);
Expand Down
3 changes: 3 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export abstract class Factory {

constructor() {
this.config = getConfig();
if (!this.config.databaseToken) {
throw new Error("Missing database token in configuration");
}
this.sdk = new BaserowSdk(this.config.databaseToken);
}

Expand Down
16 changes: 9 additions & 7 deletions src/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import rc from "rc";
import z from "zod";

const schema = z.object({
url: z.string(),
tables: z.record(z.string(), z.number()),
databaseToken: z.string(),
outDir: z.string(),
config: z.string(),
});
const schema = z
.object({
url: z.string(),
tables: z.record(z.string(), z.number()),
databaseToken: z.string(),
outDir: z.string(),
config: z.string(),
})
.partial();

export type BaserowConfig = z.infer<typeof schema>;

Expand Down

0 comments on commit d2972f5

Please sign in to comment.