-
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
Showing
3 changed files
with
35 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getSchemaPath } from './getSchema' | ||
import { arg } from './utils' | ||
import crypto from 'crypto' | ||
|
||
/** | ||
* Get a unique identifier for the project by hashing | ||
* the directory with `schema.prisma` | ||
*/ | ||
export async function getProjectHash(): Promise<string> { | ||
const args = arg(process.argv.slice(3), { '--schema': String }) | ||
|
||
let projectPath = await getSchemaPath(args['--schema']) | ||
projectPath = projectPath || process.cwd() // Default to cwd if the schema couldn't be found | ||
|
||
return crypto | ||
.createHash('sha256') | ||
.update(projectPath) | ||
.digest('hex') | ||
.substring(0, 8) | ||
} | ||
|
||
/** | ||
* Get a unique identifier for the CLI installation path | ||
* which can be either global or local (in project's node_modules) | ||
*/ | ||
export function getCLIPathHash(): string { | ||
const cliPath = process.argv[1] | ||
return crypto | ||
.createHash('sha256') | ||
.update(cliPath) | ||
.digest('hex') | ||
.substring(0, 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