-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec5c958
commit cd628c0
Showing
17 changed files
with
267 additions
and
277 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,90 @@ | ||
import { promisify } from 'util' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
const exists = promisify(fs.exists) | ||
const readFile = promisify(fs.readFile) | ||
|
||
/** | ||
* Async | ||
*/ | ||
|
||
export async function getSchemaPath(): Promise<string | null> { | ||
let schemaPath = path.join(process.cwd(), 'schema.prisma') | ||
|
||
if (await exists(schemaPath)) { | ||
return schemaPath | ||
} | ||
|
||
schemaPath = path.join(process.cwd(), `prisma/schema.prisma`) | ||
|
||
if (await exists(schemaPath)) { | ||
return schemaPath | ||
} | ||
|
||
return null | ||
} | ||
|
||
/** | ||
* Small helper that returns the directory which contains the `schema.prisma` file | ||
*/ | ||
export async function getSchemaDir(): Promise<string | null> { | ||
const schemaPath = await getSchemaPath() | ||
if (schemaPath) { | ||
return path.dirname(schemaPath) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export async function getSchema(): Promise<string> { | ||
const schemaPath = await getSchemaPath() | ||
|
||
if (!schemaPath) { | ||
throw new Error(`Could not find ${schemaPath}`) | ||
} | ||
|
||
return readFile(schemaPath, 'utf-8') | ||
} | ||
|
||
/** | ||
* Sync | ||
*/ | ||
|
||
export function getSchemaPathSync(): string | null { | ||
let schemaPath = path.join(process.cwd(), 'schema.prisma') | ||
|
||
if (fs.existsSync(schemaPath)) { | ||
return schemaPath | ||
} | ||
|
||
schemaPath = path.join(process.cwd(), `prisma/schema.prisma`) | ||
|
||
if (fs.existsSync(schemaPath)) { | ||
return schemaPath | ||
} | ||
|
||
return null | ||
} | ||
|
||
/** | ||
* Small helper that returns the directory which contains the `schema.prisma` file | ||
*/ | ||
export function getSchemaDirSync(): string | null { | ||
const schemaPath = getSchemaPathSync() | ||
if (schemaPath) { | ||
return path.dirname(schemaPath) | ||
} | ||
|
||
return null | ||
} | ||
|
||
export function getSchemaSync(): string { | ||
const schemaPath = getSchemaPathSync() | ||
|
||
if (!schemaPath) { | ||
throw new Error(`Could not find ${schemaPath}`) | ||
} | ||
|
||
return fs.readFileSync(schemaPath, 'utf-8') | ||
} |
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
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
Oops, something went wrong.