From 098995de909460878e4c0349f887ac1f76bfec7d Mon Sep 17 00:00:00 2001 From: Eric Luce <37158449+eluce2@users.noreply.github.com> Date: Tue, 25 Apr 2023 12:46:45 -0500 Subject: [PATCH] support commonJS and module imports in codegen cli --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/cli.ts | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9df51a..8c7ce44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # @proofgeist/fmdapi +## 3.0.3 + +### Patch Changes + +- support commonJS and module imports in codegen cli + ## 3.0.2 ### Patch Changes diff --git a/package.json b/package.json index d3f34a6..5cb5cff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@proofgeist/fmdapi", - "version": "3.0.2", + "version": "3.0.4", "description": "FileMaker Data API client", "main": "dist/index.js", "repository": "git@github.com:proofgeist/fm-dapi.git", diff --git a/src/cli.ts b/src/cli.ts index 3def02f..0356428 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -52,9 +52,22 @@ async function runCodegen({ configLocation }: ConfigArgs) { return process.exit(1); }); - const { config }: { config: GenerateSchemaOptions } = await import( + const module: { config: GenerateSchemaOptions } = await import( configLocation ); + let config = module.config; + if (!config) { + config = require(configLocation); + } + if (!config) { + console.error( + chalk.red( + `Error reading the config object from ${path.basename( + configLocation + )}. Are you sure you have a "config" object exported?` + ) + ); + } await generateSchemas(config, configLocation).catch((err) => { console.error(err); return process.exit(1);