Skip to content

Commit

Permalink
use import to read typescript configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Dec 17, 2023
1 parent ae93c9f commit 0fa931d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-countries-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@authdog/hydra-cli": patch
---

read typescript configuration using import
13 changes: 11 additions & 2 deletions packages/cli/src/commands/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export const generateSchemaAction = async ({
const configPath = path.resolve(rootPath, config); // Construct absolute path for config
const outputPath = path.resolve(rootPath, ".hydra/schemaRaw.ts"); // Construct absolute path for output

const demoConfig = require(configPath).default;
let demoConfig: any;

try {
// Use `import` instead of `require` for TypeScript support
const importedConfig = await import(configPath);
demoConfig = importedConfig.default || importedConfig;
} catch (error) {
throw new Error("Error loading or parsing the config file: " + error);
}

console.log(demoConfig);
const validatedConfig = validateConfig(demoConfig);
Expand All @@ -27,7 +35,8 @@ export const generateSchemaAction = async ({
await buildSchemaIntrospection(validatedConfig.schemas, outputPath);
} catch (error) {
console.error(error);
throw new Error("Error generating schema");
}

console.info("Schema generated successfully");
};
};

0 comments on commit 0fa931d

Please sign in to comment.