-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for reading configuration at generation time (#27)
Co-authored-by: Jason Kuhrt <jasonkuhrt@me.com>
- Loading branch information
1 parent
afa09c6
commit 275e03f
Showing
10 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { cosmiconfig } from 'cosmiconfig' | ||
import TypeScriptLoader from '@endemolshinegroup/cosmiconfig-typescript-loader' | ||
import { Configuration } from '../generator' | ||
|
||
const CONFIGURATION_NAME = 'nexus-prisma' | ||
|
||
export async function getConfiguration(): Promise<Configuration | null> { | ||
const explorer = cosmiconfig(CONFIGURATION_NAME, { | ||
searchPlaces: [ | ||
'nexus-prisma.ts', | ||
'nexusPrisma.ts', | ||
'nexus_prisma.ts', | ||
'prisma/nexus-prisma.ts', | ||
'prisma/nexusPrisma.ts', | ||
'prisma/nexus_prisma.ts', | ||
], | ||
loaders: { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
'.ts': TypeScriptLoader, | ||
}, | ||
packageProp: [], | ||
}) | ||
const result = await explorer.search() | ||
if (!result) { | ||
return null | ||
} | ||
console.log(`Loaded configuration from ${result.filepath}`) | ||
// TODO runtime validation with zod | ||
return result.config as Configuration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './configuration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { generateRuntimeAndEmit } from './generate' | ||
export { Configuration } from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters